Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| course_planning:code-testing [2024/01/19 13:29] – caballero | course_planning:code-testing [2024/01/19 13:44] (current) – caballero | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | <Code: python | + | # Embedded |
| + | |||
| + | ## Basic | ||
| + | |||
| + | ### Syntax | ||
| + | |||
| + | ``` | ||
| + | <code python> | ||
| + | {YOUR CODE} | ||
| + | </ | ||
| + | ``` | ||
| + | |||
| + | ### Example | ||
| + | |||
| + | < | ||
| Web VPython 3.2 | Web VPython 3.2 | ||
| Line 35: | Line 49: | ||
| if not (side > ball.pos.z > -side): | if not (side > ball.pos.z > -side): | ||
| ball.p.z = -ball.p.z | ball.p.z = -ball.p.z | ||
| - | </Code> | + | </code> |
| + | |||
| + | |||
| + | ## With Line Numbers and Highlighting | ||
| + | |||
| + | ### Syntax | ||
| + | |||
| + | ``` | ||
| + | <code python [enable_line_numbers=" | ||
| + | {YOUR CODE} | ||
| + | </ | ||
| + | ``` | ||
| + | |||
| + | ### Example | ||
| + | |||
| + | <code python [enable_line_numbers=" | ||
| + | Web VPython 3.2 | ||
| + | |||
| + | scene.caption = """ | ||
| + | To zoom, drag with middle button or Alt/Option depressed, or use scroll wheel. | ||
| + | On a two-button mouse, middle is left + right. | ||
| + | To pan left/right and up/down, Shift-drag. | ||
| + | Touch screen: pinch/ | ||
| + | |||
| + | side = 4.0 | ||
| + | thk = 0.3 | ||
| + | s2 = 2*side - thk | ||
| + | s3 = 2*side + thk | ||
| + | |||
| + | wallR = box (pos=vector( side, 0, 0), size=vector(thk, | ||
| + | wallL = box (pos=vector(-side, | ||
| + | wallB = box (pos=vector(0, | ||
| + | wallT = box (pos=vector(0, | ||
| + | wallBK = box(pos=vector(0, | ||
| + | |||
| + | ball = sphere (color = color.green, | ||
| + | ball.mass = 1.0 | ||
| + | ball.p = vector (-0.15, -0.23, +0.27) | ||
| + | |||
| + | side = side - thk*0.5 - ball.radius | ||
| + | |||
| + | dt = 0.3 | ||
| + | while True: | ||
| + | rate(200) | ||
| + | ball.pos = ball.pos + (ball.p/ | ||
| + | if not (side > ball.pos.x > -side): | ||
| + | ball.p.x = -ball.p.x | ||
| + | if not (side > ball.pos.y > -side): | ||
| + | ball.p.y = -ball.p.y | ||
| + | if not (side > ball.pos.z > -side): | ||
| + | ball.p.z = -ball.p.z | ||
| + | </ | ||
| + | |||
| + | |||
| + | ## With Line Numbers, Highlighting, | ||
| + | |||
| + | ### Syntax | ||
| + | |||
| + | ``` | ||
| + | <code python [enable_line_numbers=" | ||
| + | {YOUR CODE} | ||
| + | </ | ||
| + | ``` | ||
| + | |||
| + | **Note: Highlighting lines uses an absolute number (i.e., the given number of lines sets the length and order starting from 1).** | ||
| + | |||
| + | ### Example | ||
| + | |||
| + | <code python [enable_line_numbers=" | ||
| + | while True: | ||
| + | rate(200) | ||
| + | ball.pos = ball.pos + (ball.p/ | ||
| + | if not (side > ball.pos.x > -side): | ||
| + | ball.p.x = -ball.p.x | ||
| + | if not (side > ball.pos.y > -side): | ||
| + | ball.p.y = -ball.p.y | ||
| + | if not (side > ball.pos.z > -side): | ||
| + | ball.p.z = -ball.p.z | ||
| + | </code> | ||