;===== ; CS 111 - Week 3 Lecture 1 - 2024-09-10 ;===== (require 2htdp/image) ;===== ; a bit of named constant review (define PAINT-COLOR "fuchsia") (string=? PAINT-COLOR "PAINT-COLOR") (string=? PAINT-COLOR "fuchsia") ;===== ; fun fact: a parameter ONLY has meaning inside ; the BODY of the function it is declared in ; ; CS term: scope ; * the SCOPE of an identifier is the portion ; of a program it has meaning in ; ; so: the scope of a parameter is just the body of the ; function it is declared in ; and, the scope of a named constant is from where it ; is declared until the end of the file it is ; declared in ;===== ; I decide I want a function to get ; a Humboldt logo of a size I specify... ;----- ; signature: humboldt-logo: number -> image ; purpose: expects a desired Humboldt logo ; size in pixels, and returns an image ; of a forest green uppercase H beside a ; gold period with letters of that size (check-expect (humboldt-logo 1) (beside (text "H" 1 "forestgreen") (text "." 1 "gold"))) (check-expect (humboldt-logo 30) (beside (text "H" 30 "forestgreen") (text "." 30 "gold"))) (define (humboldt-logo letter-size) (beside (text "H" letter-size "forestgreen") (text "." letter-size "gold")) ) (humboldt-logo 100) ;===== ; I have an odd client who wants a function ; they can give an exclamation and a phrase ; to be doubted, and it gives back a ; phrase using that exclamation and echoing ; it ;----- ; signature: doubt-it: string string -> string ; purpose: expects an exclamation and a statement ; to doubt, and returns a new string that ; has the exclamation in all-uppercase ; followed by an exclamation point and a ; blank, that statement to doubt followed ; by two question marks and a blank, ; and that statement to doubt again ; just followed by two question marks (check-expect (doubt-it "really" "I like banana pudding") "REALLY! I like banana pudding?? I like banana pudding??") (check-expect (doubt-it "wait" "It's windy outside") "WAIT! It's windy outside?? It's windy outside??") (define (doubt-it exclamation doubt-stmt) (string-append (string-upcase exclamation) "! " doubt-stmt "?? " doubt-stmt "??") ) (doubt-it "wait" "It's windy outside") (doubt-it "really" "I like banana pudding") ;===== ; 2htdp/image defines a new type, ; a special sub-type of image, ; called scene ;===== ; when one creates a new type, one also needs to ; provide basic operations on that new type; ; 2htdp/image provides two basic functions for ; scenes: ; * empty-scene ; * place-image ;----- ; signature: empty-scene: number number -> scene ; purpose: expects a desired scene's width and height ; in pixels, and returns a blank scene of that ; width and height (empty-scene 300 200) ;----- ; signature: place-image: image number number scene -> scene ; purpose: expects a desired image, a desired x and y location, ; and a desired scene, and returns a new scene with ; that image at that location in that scene (place-image (circle 20 "solid" "blue") 150 45 (empty-scene 300 200))