Hello guys I want to make an animation using Drracket with 4 different objects going different ways like "left right up and down" but on-tick part I'm having a problem. So the problem is I'm giving the function a list and I want to take another made up new list and call the function with this "new" list again so it will automatically be recursion and shapes will move without stopping
My program is like this
(define R 300)
(define L (* 2 R))
(define U (* 2.5 R))
(define MYSCN (empty-scene L U))
;Structure:
(define-struct SHAPE (type posn direction color size))
;type is a shape of the object and it can only be circle or square (Image)
;posn is the initial point of the shape is drawn (Number)
;direction can be "left right up down" and represents the direction of the shape moves (String)
;color and size are the color and size of the object (String)
;Contructors
(define pos1 (make-posn 450 50))
(define pos3 (make-posn 200 540))
(define shape1 (make-SHAPE "circle" pos1 "down" "red" 50))
(define shape2 (make-SHAPE "square" (make-posn 100 230) "right" "purple" 170))
(define shape3 (make-SHAPE "circle" pos3 "up" "green" 100))
(define shape4 (make-SHAPE "square" (make-posn 500 450) "left" "orange" 155))
(define shapelist1 (list shape1 shape2 shape3 shape4))
;Selectors
(posn-x pos1) ;400 (Number)
(posn-y (SHAPE-posn shape2)) ;200 (Number)
(SHAPE-type shape3) ;"circle" (Image)
(SHAPE-direction shape4) ;"left" (String)
(SHAPE-color shape1) ;"red" (String)
;Predicators
(SHAPE? shape1) ;true
(posn? shape2) ;false
(posn? pos1) ;true
;Purpose: Transferring all the shapes to the scene
;alltheshapes shapelist1-->image
(define (alltheshapes f)
(place-image (circle (SHAPE-size (first shapelist1)) "solid" (SHAPE-color (first shapelist1)))
(posn-x (SHAPE-posn (first shapelist1))) (posn-y (SHAPE-posn (first shapelist1)))
(place-image
(square (SHAPE-size (first(rest shapelist1))) "solid" (SHAPE-color (first (rest shapelist1))))
(posn-x (SHAPE-posn (first(rest shapelist1)))) (posn-y (SHAPE-posn (first(rest shapelist1))))
(place-image
(circle (SHAPE-size (first (rest (rest shapelist1)))) "solid" (SHAPE-color (first (rest (rest shapelist1)))))
(posn-x (SHAPE-posn (first (rest (rest shapelist1))))) (posn-y (SHAPE-posn (first (rest (rest shapelist1)))))
(place-image
(square (SHAPE-size(first(rest(rest(rest shapelist1))))) "solid" (SHAPE-color(first(rest(rest(rest shapelist1))))))
(posn-x (SHAPE-posn (first(rest(rest(rest shapelist1)))))) (posn-y (SHAPE-posn (first(rest(rest(rest shapelist1))))))
MYSCN)))))
I couldn't figure out the recursive part here
;Purpose: Change the position of the shape according to the current word
;Contract: moveshapes shapelist1-->creates a new shape
(define (moveshapes shapelist1)
(cond
((string=? (SHAPE-direction (first shapelist1)) "down") (append (list (make-SHAPE "circle" (make-posn 450 (+ 1 (posn-y pos1))) "down" "red" 50)) (moveshape (rest shapelist1))))
((string=? (SHAPE-direction (first shapelist1)) "right") (append (list (make-SHAPE "square" (make-posn (+ 1 (posn-x (SHAPE-posn shape2))) 230) "right" "purple" 170)) (moveshape (rest shapelist1))))
((string=? (SHAPE-direction (first shapelist1)) "up") (append (list(make-SHAPE "circle" (make-posn 200 (- (posn-y (SHAPE-posn shape3)) 1)) "up" "green" 100)) (moveshape (rest shapelist1))))
((string=? (SHAPE-direction (first shapelist1)) "left") (append (list(make-SHAPE "square" (make-posn (- (posn-x (SHAPE-posn shape4)) 1) 450) "left" "orange" 155))))
(define (Project super)
(big-bang super
(to-draw alltheshapes) ;Takes the current word and produce an image
(on-tick moveshapes))) ;It will take the shapes and create a new shape while moving them
(Project shapelist1)
