Animate a pendulum: Difference between revisions
Content deleted Content added
m →{{header|Racket}}: Fix corrupt unicode |
|||
Line 2,876: | Line 2,876: | ||
(define (pendulum) |
(define (pendulum) |
||
(define (accel |
(define (accel θ) (- (sin θ))) |
||
(define |
(define θ (/ pi 2.5)) |
||
(define |
(define θ′ 0) |
||
(define |
(define θ′′ (accel (/ pi 2.5))) |
||
(define (x |
(define (x θ) (+ 200 (* 150 (sin θ)))) |
||
(define (y |
(define (y θ) (* 150 (cos θ))) |
||
( |
(λ (n) |
||
(define p-image (underlay/xy (add-line (empty-scene 400 200) 200 0 (x |
(define p-image (underlay/xy (add-line (empty-scene 400 200) 200 0 (x θ) (y θ) "black") |
||
(- (x |
(- (x θ) 5) (- (y θ) 5) (circle 5 "solid" "blue"))) |
||
(set! |
(set! θ (+ θ (* θ′ 0.04))) |
||
(set! |
(set! θ′ (+ θ′ (* (accel θ) 0.04))) |
||
p-image)) |
p-image)) |
||