;; The first three lines of this file were inserted by DrScheme. 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 entry1_not_contest) (read-case-sensitive #t) (teachpacks ((lib "master.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "master.ss" "teachpack" "htdp") (lib "guess.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp"))))) ;;Lab 4 ;;Purpose: The purpose of this lab is to create moving shapes using, draw-shapes, clear-shapes, sleep-for-a-while and structures such as (make-posn.. . and our own defined structures such as "circle". We may have overdid the comments, please leave a comment if this is true. Also during this lab we are using solid-disks and calling them circles because its shorter. (start 450 450);; Opens Canvas for Drawing (define-struct circle (center radius color)) ;; Defines a structure that allows us to use (make-circle. . . function to define circles. (define (draw-circ a-circle x y);;Function that Draws a Solid Disk. (draw-solid-disk ;Pre-loaded function (make-posn ;Pre-loaded structure (+ x (posn-x (circle-center a-circle))) ;Alters x-value. (+ y (posn-y (circle-center a-circle))));Alters y-value. (circle-radius a-circle) ;Keeps Radius the same. (circle-color a-circle) ;Keeps Color the same. ));;The purpose of this function is to take a pre-defined circle defined using a (make-circle. . . function and then draws the same shape in a different location given by x and y. X and Y represent the difference in those values from the original shape. (define (clear-circ a-circle x y);;Function that Clears a Solid Disk. (clear-solid-disk ;Pre-loaded function (make-posn (+ x (posn-x (circle-center a-circle))) ;Alters x-value. (+ y (posn-y (circle-center a-circle)))) ;Alters y-value. (circle-radius a-circle) ;Keeps Radius the same. (circle-color a-circle) ;Keeps Color the same. ));;This function does exactly the same thing as the draw-circ function except that it clears the shape instead of drawing it. (define (draw-and-clear-circle circle x y delay) (and (draw-circ circle x y) ;Pre-defined function (sleep-for-a-while delay);;Pre-loaded delay function. (clear-circ circle x y) ;Pre-defined function ));; This function pieces the two previous functions together and adds a delay inbetween drawing and clearing the shapes. Useful since we want the shapes to have the appearance of moving. (define (translate circle x y delay times time);Times is the number of translations and time is a value that needs to start out at 1, it allows the function to keep track of how many translations it has done to keep the shape moving. (cond ;Condition that causes it to loop untill it completes the correct number of moves. [(= times 1) (draw-and-clear-circle circle (* time x) (* time y) delay)] [(>= times 2) (and (draw-and-clear-circle circle (* time x) (* time y) delay) (translate circle x y delay (- times 1) (+ time 1)) ) ] [else 'InvalidTranslation] ));;This function is a little bit unneccesary but I wanted to piece it together. It takes a pre-defined circle, x and y values, a delay, how many times it translates and a number time that has to be 1 at the start for the function to work correctly. This function takes the pre-defined circle and translates it a certain x and y value based on imput, a certain number of times based on imput. If used correctly it can, with limited other code, create circles flying across the screen. In order to keep this Lab simple shorter I will not define this many functions for the other shapes. (draw-solid-rect (make-posn 29 250) 9 85 'darkblue);Draws Bumper 1, Blue Rectangle. (draw-solid-rect (make-posn 421 40) 9 85 'darkblue);Draws Bumber 2, Blue Rectangle. (draw-solid-rect (make-posn 300 0) 85 8 'darkblue) ;Draws Bumper 3, Blue Rectangle. (draw-solid-line (make-posn 65 380) (make-posn 90 415) 'darkgreen) ;Makes left Line of Cup. (draw-solid-line (make-posn 90 415) (make-posn 115 395) 'darkgreen);Makes bottom Line of Cup. (draw-solid-line (make-posn 115 395) (make-posn 93 360) 'darkgreen);Makes right Line of Cup. (define circle1 (make-circle (make-posn 225 225) 9 'red));Defines Circle 1, Red, starts in the middle. (translate circle1 5 -4 .023 37 1) ;Slides Circle 1 to new position against Bumper 2. (define circle2 (make-circle (make-posn 410 77) 9 'red)) ;Defines Circle 2, Red, starts where Circle 1 left off. (translate circle2 -4 -4 .02 15 1) ;Starts where Circle 1 ended, against Bumper 2 and slides to Bumper 3. (define circle3 (make-circle (make-posn 342 17) 9 'red)) ;Defines Circle 3, Red, starts where Circle 2 left off. (translate circle3 -5 5 .015 59 1) ;Starts where Circle 2 ended, against Bumper 3 and slides to Bumper 1. (define circle4 (make-circle (make-posn 47 312) 9 'red)) ;Defines Circle 4, Red, starts where Circle 3 left off. (translate circle4 3 5 .01 16 1) ;Starts where Circle 3 ended, against Bumper 1 and slides into Cup. (draw-solid-disk (make-posn 95 392) 9 'red) ;Creates visible circle that is not cleared in the cup at the end of the motion. (translate circle4 3 3 .01 -1 1) ;Test for 'InvalidTranslation.