;; 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 lab5-given) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f))) (require 2htdp/image) (require 2htdp/universe) #|--- DATA DEFINITIONS ---|# ;;A Command is one of: ;; - 'move ;; - 'turn-left ;; - 'turn-right ;;A List-of-Commands (LOC) is one of: ;; - '() ;; - (cons Command LOC) ;;A Direction is one of: ;; - 'left ;; - 'right ;; - 'up ;; - 'down ;;A Turtle is a (make-turtle Direction Posn LOC) (define-struct turtle (dir p loc)) ; - where dir is the direction the turtle is facing ; - p is the current location of the turtle ; - and loc is the list of commands the turtle needs to follow #|--- CONSTANTS ---|# (define WIDTH 500) (define HEIGHT 500) (define BACKGROUND (empty-scene WIDTH HEIGHT)) (define TURTLE-UP (triangle 20 "solid" "forestgreen")) (define TURTLE-LEFT (rotate 90 TURTLE-UP)) (define TURTLE-DOWN (rotate 90 TURTLE-LEFT)) (define TURTLE-RIGHT (rotate 90 TURTLE-DOWN)) (define CENTER (make-posn (/ WIDTH 2) (/ HEIGHT 2))) #|--- FUNCTIONS ---|# ;;main : LOC -> Turtle ;;Simulate a turtle following these commands (define (main all-commands) (big-bang (make-turtle 'up CENTER all-commands) [on-tick do-command] [to-draw draw-turtle] [stop-when out-of-commands?])) ;;do-command : Turtle -> Turtle ;;Do the first command in the list of commands (define (do-command t) t) ;; FIX ME I'M A DUMMY HEADER ;;draw-turtle : Turtle -> Image ;;Renders the turtle on the background (define (draw-turtle t) BACKGROUND) ;; FIX ME I'M A DUMMY HEADER ;;out-of-commands? : Turtle -> Boolean ;;Is the turtle out of commands? (define (out-of-commands? t) #f) ;; FIX ME I'M A DUMMY HEADER