Commit 70f793ae authored by rokka's avatar rokka

ueb5

parent 5b51776a
;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname A51) (read-case-sensitive #t) (teachpacks ((lib "image.rkt" "teachpack" "2htdp") (lib "universe.rkt" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.rkt" "teachpack" "2htdp") (lib "universe.rkt" "teachpack" "2htdp")) #f)))
; (PROG) ->
(reveal THEDOCTOR)
; (FUN) ->
(cond
[(string=? (hero-race hero) "Martian") (string-append
(hero-supername hero) " is " (hero-realname hero)
" from Mars.")]
[(string=? (hero-race hero) "Kryptonian") (string-append
(hero-supername hero) " is " (hero-realname hero)
" from Krypton.")]
[(string=? (hero-race hero) "Timelord") (string-append
(hero-supername hero) " is " (hero-realname hero)
" from Gallifrey.")]
[(string=? (hero-race hero) "New God") (string-append
(hero-supername hero) " is " (hero-realname hero)
" from New Genesis.")]
[(string=? (hero-race hero) "Sayajin") (string-append
(hero-supername hero) " is " (hero-realname hero)
" from Vegeta.")]
[(string=? (hero-race hero) "Old One") (string-append
(hero-supername hero) " is " (hero-realname hero)
" from R’lyeh.")]
[true (string-append (hero-supername hero) " is "
(hero-realname hero) " from Earth.")]))
; (STRUCT-select) ->
(cond
[(string=? "Timelord" "Martian") ...]
...)
; (PRIM) ->
(cond
[#false ...]
...)
; (COND-false) ->
(cond
[(string=? (hero-race hero) "Kryptonian") ...]
...)
; (STRUCT-select) ->
(cond
[(string=? "Timelord" "Kryptonian") ...]
...)
; (PRIM) ->
(cond
[#false ...]
...)
; (COND-false) ->
(cond
[(string=? (hero-race hero) "Timelord") ...]
...)
; (STRUCT-select) ->
(cond
[(string=? "Timelord" "Timelord") ...]
...)
; (PRIM) ->
(cond
[#true (string-append (hero-supername hero) " is " (hero-realname hero) " from Gallifrey.")]
...)
; (COND-true) ->
(string-append (hero-supername hero) " is " (hero-realname hero) " from Gallifrey.")
; (STRUCT-select) ->
(string-append "The Doctor" " is " (hero-realname hero) " from Gallifrey.")
; (STRUCT-select) ->
(string-append "The Doctor" " is " "Unknown" " from Gallifrey.")
; (PRIM) ->
"The Doctor is Unknown from Gallifrey."
;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname A51) (read-case-sensitive #t) (teachpacks ((lib "image.rkt" "teachpack" "2htdp") (lib "universe.rkt" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.rkt" "teachpack" "2htdp") (lib "universe.rkt" "teachpack" "2htdp")) #f)))
(define THEDOCTOR (make-hero "The Doctor" "Unkown" "Timelord"))
; (PROG) ->
(reveal THEDOCTOR)
; (FUN) ->
(cond
[(string=? (hero-race hero) "Martian") (string-append
(hero-supername hero) " is " (hero-realname hero)
" from Mars.")]
[(string=? (hero-race hero) "Kryptonian") (string-append
(hero-supername hero) " is " (hero-realname hero)
" from Krypton.")]
[(string=? (hero-race hero) "Timelord") (string-append
(hero-supername hero) " is " (hero-realname hero)
" from Gallifrey.")]
[(string=? (hero-race hero) "New God") (string-append
(hero-supername hero) " is " (hero-realname hero)
" from New Genesis.")]
[(string=? (hero-race hero) "Sayajin") (string-append
(hero-supername hero) " is " (hero-realname hero)
" from Vegeta.")]
[(string=? (hero-race hero) "Old One") (string-append
(hero-supername hero) " is " (hero-realname hero)
" from R’lyeh.")]
[true (string-append (hero-supername hero) " is "
(hero-realname hero) " from Earth.")]))
; (STRUCT-select) ->
(cond
[(string=? "Timelord" "Martian") ...]
...)
; (PRIM) ->
(cond
[#false ...]
...)
; (COND-false) ->
(cond
[(string=? (hero-race hero) "Kryptonian") ...]
...)
; (STRUCT-select) ->
(cond
[(string=? "Timelord" "Kryptonian") ...]
...)
; (PRIM) ->
(cond
[#false ...]
...)
;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname A52) (read-case-sensitive #t) (teachpacks ((lib "image.rkt" "teachpack" "2htdp") (lib "universe.rkt" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.rkt" "teachpack" "2htdp") (lib "universe.rkt" "teachpack" "2htdp")) #f)))
; a)
(* (+ 4 3) (- 2 1)) 7
; (ERED) ->
(* 7 (- 2 1)) 7
; (ERED) ->
(* 7 1) 7
; (ERED) ->
7 7
; b)
(cond [(> n 0) (* 0.5 n)] [true (* 2 n)])
(cond [(> n 0) (/ n 2)] [true (+ n n)])
; (EKONG) ->
(cond [(> n 0) (/ n 2)] [true (* 2 n)])
(cond [(> n 0) (/ n 2)] [true (+ n n)])
; (EKONG) ->
(cond [(> n 0) (/ n 2)] [true (+ n n)])
(cond [(> n 0) (/ n 2)] [true (+ n n)])
; c)
42 (* 2 21)
; (EKONG) ->
(* 2 21) (* 2 21)
; (ERED) ->
(* 2 21) 42
; (ERED) ->
42 42
; d)
(g 10 x x) (* 10 (* x x))
; (EFUN) ->
(* (* 10 x x) (* 10 (* x x))
; (EKOMM) ->
(* 10 ( * x x)) (* 10 (* x x))
;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname A52) (read-case-sensitive #t) (teachpacks ((lib "image.rkt" "teachpack" "2htdp") (lib "universe.rkt" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.rkt" "teachpack" "2htdp") (lib "universe.rkt" "teachpack" "2htdp")) #f)))
; a)
(* (+ 4 3) (- 2 1)) ≡ 7
; (ERED) ->
(* 7 (- 2 1)) ≡ 7
; (ERED) ->
(* 7 1) ≡ 7
; (ERED) ->
7 ≡ 7
\ No newline at end of file
;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname A53) (read-case-sensitive #t) (teachpacks ((lib "image.rkt" "teachpack" "2htdp") (lib "universe.rkt" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.rkt" "teachpack" "2htdp") (lib "universe.rkt" "teachpack" "2htdp")) #f)))
(define WIDTH 400)
(define HEIGHT 400)
(define MIDDLE (/ HEIGHT 2))
; Angle is a Number
; interp. as rotation angle from 0 to 360 degrees
; Progress is a Number
; interp. as the progress of an animation in [0,1]
; Ease is a (Progress -> Progress)
; interp. as manipulation of a linear animation
(define (ease/linear progress) progress)
(define (ease/sineEaseIn progress)
(+ (sin (* (- progress 1) pi)) 1))
(define (ease/easeOutExpo progress)
(- 1 (expt 2 (* -8 progress))))
; Shape is a (Color -> Image)
; interp. generates a shape with the given color
; (define (circ col) (circle 10 "solid" col ))
(define (shape-one col)
(above
(pulled-regular-polygon 100 3 1.8 30 "solid" col)
(text "zu wenig zeit diese woche sry ( ⓥωⓥ)" 14 col)
(add-solid-curve (rectangle 30 30 "solid" "black")
-5 -5 0 1
60 60 0 1
col)))
(define (shape-two col)
(overlay (ellipse 10 10 "solid" col)
(ellipse 20 20 "solid" "black")
(ellipse 30 30 "solid" col)
(ellipse 40 40 "solid" "black")
(ellipse 50 50 "solid" col)
(ellipse 60 60 "solid" "black")))
; A color-anim is (make-color-anim Color Color Ease
; (make-color-anim Color(0 0 0 255) Color(255 255 255 255) ease/linear)
(define-struct color-anim (from to ease))
; A rotation-anim is (make-movement-anim Angle Angle Ease)
; (make-rotation-anim 0 180 ease/linear)
(define-struct rotation-anim (from to ease))
; A movement-anim is (make-movement-anim Posn Posn Ease)
; (make-movement-anim (make-posn 0 0) (make-posn 100 100) ease/linear)
(define-struct movement-anim (from to ease))
; An animation is (make-animation Shape Number Number Boolean Movement-Anim Rotation-Anim Color-Anim
; Keep determines whether the shape is rendered at its final position/color/rotation after end is reached
; (make-animation circ 0 100 true ....)
(define-struct animation (shape start end keep movement rotation color))
; A world is (make-world Number (list-of Animation)
; interp. as a complex animation over time
(define-struct world (t animations))
; Progress Position-Animation -> Posn
; Returns the shape's position according to the given progress
(define (apply/pos progress anim)
(local [(define startx (posn-x (movement-anim-from anim)))
(define starty (posn-y (movement-anim-from anim)))
(define endx (posn-x (movement-anim-to anim)))
(define endy (posn-y (movement-anim-to anim)))
(define dx (- endx startx))
(define dy (- endy starty))
(define tprog ((movement-anim-ease anim) progress))]
(make-posn (+ startx (* tprog dx)) (+ starty (* tprog dy)))))
; Image Progress Rotation-Animation -> Image
; Applys the rotation to the given image, according to the animation-rules
(define (apply/rot img progress anim)
(local [(define da (- (rotation-anim-to anim) (rotation-anim-from anim)))
(define tprog ((rotation-anim-ease anim) progress))]
(rotate (+ (rotation-anim-from anim) (* tprog da)) img)))
; Shape Progress Color-Animation -> Image
; Creates a shape with the color specified by the given animation
(define (apply/color shape progress anim)
(local [(define cstart (color-anim-from anim))
(define cend (color-anim-to anim))
(define dr (- (color-red cend) (color-red cstart)))
(define dg (- (color-green cend) (color-green cstart)))
(define db (- (color-blue cend) (color-blue cstart)))
(define da (- (color-alpha cend) (color-alpha cstart)))
(define tprog ((color-anim-ease anim) progress))]
(shape (make-color (floor (+ (color-red cstart) (* dr tprog)))
(floor (+ (color-green cstart) (* dg tprog)))
(floor (+ (color-blue cstart) (* db tprog)))
(floor (+ (color-alpha cstart) (* da tprog)))))))
; Animation Image Number -> Image
; Renders the given animation into the scene according to the time elapsed
(define (render/animation anim scene t)
(if (and (<= (animation-start anim) t) (or (<= t (animation-end anim)) (animation-keep anim)))
(local [(define ts (animation-start anim))
(define te (animation-end anim))
(define progress (min (/ (- t ts) (- te ts)) 1.0))
(define plain-img (apply/color (animation-shape anim) progress (animation-color anim)))
(define rot-img (apply/rot plain-img progress (animation-rotation anim)))
(define pos (apply/pos progress (animation-movement anim)))]
(place-image rot-img (posn-x pos) (posn-y pos) scene))
scene))
; (list-of Animation) Number -> Image
; Renders all animation according to the current world-state
(define (render/all anims t)
(if (empty? anims)
(empty-scene WIDTH HEIGHT)
(render/animation (first anims) (render/all (rest anims) t) t)))
; World -> Image
; Renders all animation according to the current world-state
(define (render w)
(render/all (world-animations w) (world-t w)))
; World -> World
; Progresses the animation
(define (tick w)
(cond
[(> 360 (world-t w)) (make-world (+ 1 (world-t w)) (world-animations w))]
[else (make-world 0 (world-animations w))]))
; World -> Boolean
; Determines if the animation is finished
(define (eow w)
#false)
;(> (world-t w)
; (foldr max 0 (map (lambda (anim) (animation-end anim)) (world-animations w)))))
(define DEMO (make-animation (lambda (color) (shape-one color))
0 360 false
(make-movement-anim (make-posn (/ WIDTH 2) HEIGHT) (make-posn MIDDLE MIDDLE) ease/sineEaseIn)
(make-rotation-anim 0 360 ease/sineEaseIn)
(make-color-anim (make-color 255 0 0 255) (make-color 0 255 0 255) ease/linear)))
(define DEMO2 (make-animation (lambda (color) (shape-two color))
0 360 false
(make-movement-anim (make-posn 0 WIDTH) (make-posn MIDDLE MIDDLE) ease/easeOutExpo)
(make-rotation-anim 0 360 ease/sineEaseIn)
(make-color-anim (make-color 255 0 0 255) (make-color 0 255 0 255) ease/linear)))
; Holds the list of animations
(define ANIMS (list DEMO DEMO2))
; BIG BANG
(big-bang (make-world 0 ANIMS)
(on-tick tick 0.02)
(to-draw render)
(stop-when eow))
\ No newline at end of file
;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname animate) (read-case-sensitive #t) (teachpacks ((lib "image.rkt" "teachpack" "2htdp") (lib "universe.rkt" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.rkt" "teachpack" "2htdp") (lib "universe.rkt" "teachpack" "2htdp")) #f)))
(define WIDTH 400)
(define HEIGHT 400)
(define MIDDLE (/ HEIGHT 2))
; Angle is a Number
; interp. as rotation angle from 0 to 360 degrees
; Progress is a Number
; interp. as the progress of an animation in [0,1]
; Ease is a (Progress -> Progress)
; interp. as manipulation of a linear animation
(define (ease/linear progress) progress)
(define (ease/sineEaseIn progress)
(+ (sin (* (- progress 1) pi)) 1))
(define (ease/easeOutExpo progress)
(- 1 (expt 2 (* -8 progress))))
; Shape is a (Color -> Image)
; interp. generates a shape with the given color
; (define (circ col) (circle 10 "solid" col ))
(define (shape-one col)
(above
(pulled-regular-polygon 100 3 1.8 30 "solid" col)
(text "zu wenig zeit diese woche sry ( ⓥωⓥ)" 14 col)
(add-solid-curve (rectangle 30 30 "solid" "black")
-5 -5 0 1
60 60 0 1
col)))
(define (shape-two col)
(overlay (ellipse 10 10 "solid" col)
(ellipse 20 20 "solid" "black")
(ellipse 30 30 "solid" col)
(ellipse 40 40 "solid" "black")
(ellipse 50 50 "solid" col)
(ellipse 60 60 "solid" "black")))
; A color-anim is (make-color-anim Color Color Ease
; (make-color-anim Color(0 0 0 255) Color(255 255 255 255) ease/linear)
(define-struct color-anim (from to ease))
; A rotation-anim is (make-movement-anim Angle Angle Ease)
; (make-rotation-anim 0 180 ease/linear)
(define-struct rotation-anim (from to ease))
; A movement-anim is (make-movement-anim Posn Posn Ease)
; (make-movement-anim (make-posn 0 0) (make-posn 100 100) ease/linear)
(define-struct movement-anim (from to ease))
; An animation is (make-animation Shape Number Number Boolean Movement-Anim Rotation-Anim Color-Anim
; Keep determines whether the shape is rendered at its final position/color/rotation after end is reached
; (make-animation circ 0 100 true ....)
(define-struct animation (shape start end keep movement rotation color))
; A world is (make-world Number (list-of Animation)
; interp. as a complex animation over time
(define-struct world (t animations))
; Progress Position-Animation -> Posn
; Returns the shape's position according to the given progress
(define (apply/pos progress anim)
(local [(define startx (posn-x (movement-anim-from anim)))
(define starty (posn-y (movement-anim-from anim)))
(define endx (posn-x (movement-anim-to anim)))
(define endy (posn-y (movement-anim-to anim)))
(define dx (- endx startx))
(define dy (- endy starty))
(define tprog ((movement-anim-ease anim) progress))]
(make-posn (+ startx (* tprog dx)) (+ starty (* tprog dy)))))
; Image Progress Rotation-Animation -> Image
; Applys the rotation to the given image, according to the animation-rules
(define (apply/rot img progress anim)
(local [(define da (- (rotation-anim-to anim) (rotation-anim-from anim)))
(define tprog ((rotation-anim-ease anim) progress))]
(rotate (+ (rotation-anim-from anim) (* tprog da)) img)))
; Shape Progress Color-Animation -> Image
; Creates a shape with the color specified by the given animation
(define (apply/color shape progress anim)
(local [(define cstart (color-anim-from anim))
(define cend (color-anim-to anim))
(define dr (- (color-red cend) (color-red cstart)))
(define dg (- (color-green cend) (color-green cstart)))
(define db (- (color-blue cend) (color-blue cstart)))
(define da (- (color-alpha cend) (color-alpha cstart)))
(define tprog ((color-anim-ease anim) progress))]
(shape (make-color (floor (+ (color-red cstart) (* dr tprog)))
(floor (+ (color-green cstart) (* dg tprog)))
(floor (+ (color-blue cstart) (* db tprog)))
(floor (+ (color-alpha cstart) (* da tprog)))))))
; Animation Image Number -> Image
; Renders the given animation into the scene according to the time elapsed
(define (render/animation anim scene t)
(if (and (<= (animation-start anim) t) (or (<= t (animation-end anim)) (animation-keep anim)))
(local [(define ts (animation-start anim))
(define te (animation-end anim))
(define progress (min (/ (- t ts) (- te ts)) 1.0))
(define plain-img (apply/color (animation-shape anim) progress (animation-color anim)))
(define rot-img (apply/rot plain-img progress (animation-rotation anim)))
(define pos (apply/pos progress (animation-movement anim)))]
(place-image rot-img (posn-x pos) (posn-y pos) scene))
scene))
; (list-of Animation) Number -> Image
; Renders all animation according to the current world-state
(define (render/all anims t)
(if (empty? anims)
(empty-scene WIDTH HEIGHT)
(render/animation (first anims) (render/all (rest anims) t) t)))
; World -> Image
; Renders all animation according to the current world-state
(define (render w)
(render/all (world-animations w) (world-t w)))
; World -> World
; Progresses the animation
(define (tick w)
(cond
[(> 360 (world-t w)) (make-world (+ 1 (world-t w)) (world-animations w))]
[else (make-world 0 (world-animations w))]))
; World -> Boolean
; Determines if the animation is finished
(define (eow w)
#false)
;(> (world-t w)
; (foldr max 0 (map (lambda (anim) (animation-end anim)) (world-animations w)))))
(define DEMO (make-animation (lambda (color) (shape-one color))
0 360 false
(make-movement-anim (make-posn (/ WIDTH 2) HEIGHT) (make-posn MIDDLE MIDDLE) ease/sineEaseIn)
(make-rotation-anim 0 360 ease/sineEaseIn)
(make-color-anim (make-color 255 0 0 255) (make-color 0 255 0 255) ease/linear)))
(define DEMO2 (make-animation (lambda (color) (shape-two color))
0 360 false
(make-movement-anim (make-posn 0 WIDTH) (make-posn MIDDLE MIDDLE) ease/easeOutExpo)
(make-rotation-anim 0 360 ease/sineEaseIn)
(make-color-anim (make-color 255 0 0 255) (make-color 0 255 0 255) ease/linear)))
; Holds the list of animations
(define ANIMS (list DEMO DEMO2))
; BIG BANG
(big-bang (make-world 0 ANIMS)
(on-tick tick 0.02)
(to-draw render)
(stop-when eow))
\ No newline at end of file
;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname animate) (read-case-sensitive #t) (teachpacks ((lib "image.rkt" "teachpack" "2htdp") (lib "universe.rkt" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.rkt" "teachpack" "2htdp") (lib "universe.rkt" "teachpack" "2htdp")) #f)))
(define WIDTH 400)
(define HEIGHT 400)
; Angle is a Number
; interp. as rotation angle from 0 to 360 degrees
; Progress is a Number
; interp. as the progress of an animation in [0,1]
; Ease is a (Progress -> Progress)
; interp. as manipulation of a linear animation
(define (ease/linear progress) progress)
; Shape is a (Color -> Image)
; interp. generates a shape with the given color
; (define (circ col) (circle 10 "solid" col ))
; A color-anim is (make-color-anim Color Color Ease
; (make-color-anim Color(0 0 0 255) Color(255 255 255 255) ease/linear)
(define-struct color-anim (from to ease))
; A rotation-anim is (make-movement-anim Angle Angle Ease)
; (make-rotation-anim 0 180 ease/linear)
(define-struct rotation-anim (from to ease))
; A movement-anim is (make-movement-anim Posn Posn Ease)
; (make-movement-anim (make-posn 0 0) (make-posn 100 100) ease/linear)
(define-struct movement-anim (from to ease))
; An animation is (make-animation Shape Number Number Boolean Movement-Anim Rotation-Anim Color-Anim
; Keep determines whether the shape is rendered at its final position/color/rotation after end is reached
; (make-animation circ 0 100 true ....)
(define-struct animation (shape start end keep movement rotation color))
; A world is (make-world Number (list-of Animation)
; interp. as a complex animation over time
(define-struct world (t animations))
; Progress Position-Animation -> Posn
; Returns the shape's position according to the given progress
(define (apply/pos progress anim)
(local [(define startx (posn-x (movement-anim-from anim)))
(define starty (posn-y (movement-anim-from anim)))
(define endx (posn-x (movement-anim-to anim)))
(define endy (posn-y (movement-anim-to anim)))
(define dx (- endx startx))
(define dy (- endy starty))
(define tprog ((movement-anim-ease anim) progress))]
(make-posn (+ startx (* tprog dx)) (+ starty (* tprog dy)))))
; Image Progress Rotation-Animation -> Image
; Applys the rotation to the given image, according to the animation-rules
(define (apply/rot img progress anim)
(local [(define da (- (rotation-anim-to anim) (rotation-anim-from anim)))
(define tprog ((rotation-anim-ease anim) progress))]
(rotate (+ (rotation-anim-from anim) (* tprog da)) img)))
; Shape Progress Color-Animation -> Image
; Creates a shape with the color specified by the given animation
(define (apply/color shape progress anim)
(local [(define cstart (color-anim-from anim))
(define cend (color-anim-to anim))
(define dr (- (color-red cend) (color-red cstart)))
(define dg (- (color-green cend) (color-green cstart)))
(define db (- (color-blue cend) (color-blue cstart)))
(define da (- (color-alpha cend) (color-alpha cstart)))
(define tprog ((color-anim-ease anim) progress))]
(shape (make-color (floor (+ (color-red cstart) (* dr tprog)))
(floor (+ (color-green cstart) (* dg tprog)))
(floor (+ (color-blue cstart) (* db tprog)))
(floor (+ (color-alpha cstart) (* da tprog)))))))
; Animation Image Number -> Image
; Renders the given animation into the scene according to the time elapsed
(define (render/animation anim scene t)
(if (and (<= (animation-start anim) t) (or (<= t (animation-end anim)) (animation-keep anim)))
(local [(define ts (animation-start anim))
(define te (animation-end anim))
(define progress (min (/ (- t ts) (- te ts)) 1.0))
(define plain-img (apply/color (animation-shape anim) progress (animation-color anim)))
(define rot-img (apply/rot plain-img progress (animation-rotation anim)))
(define pos (apply/pos progress (animation-movement anim)))]
(place-image rot-img (posn-x pos) (posn-y pos) scene))
scene))
; (list-of Animation) Number -> Image
; Renders all animation according to the current world-state
(define (render/all anims t)
(if (empty? anims)
(empty-scene WIDTH HEIGHT)
(render/animation (first anims) (render/all (rest anims) t) t)))
; World -> Image
; Renders all animation according to the current world-state
(define (render w)
(render/all (world-animations w) (world-t w)))
; World -> World
; Progresses the animation
(define (tick w)
(make-world (+ 1 (world-t w)) (world-animations w)))
; World -> Boolean
; Determines if the animation is finished
(define (eow w)
(> (world-t w)
(foldr max 0 (map (lambda (anim) (animation-end anim)) (world-animations w)))))
(define DEMO (make-animation (lambda (color) (square 20 "solid" color))
0 200 true
(make-movement-anim (make-posn 0 0) (make-posn WIDTH HEIGHT) ease/linear)
(make-rotation-anim 0 360 ease/linear)
(make-color-anim (make-color 255 0 0 255) (make-color 0 255 0 255) ease/linear)))
; Holds the list of animations
(define ANIMS (list DEMO))
; BIG BANG
(big-bang (make-world 0 ANIMS)
(on-tick tick 0.02)
(to-draw render)
(stop-when eow))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment