; For more practice with definitions and expressions let's make a tower of pandas. ; We will place a restriction on ourselves that will implicitly give us some ; experience with exponential growth and binary representation (two concepts ; important in CS which we will discuss later in the course). (require picturing-programs) ; We named this image 'pandy'. ; When the tower we were making was too large for the projector to show, we came ; back to this definition and put in the scaling. Because we were using the name ; everywhere, all the expressions produced new values. (define pandy (scale 1/4 )) ; The next expression is quite complex. ; Exercise: name parts of it to build up the final result, similar to what we did ; with Kody in the previous document. (define one (crop-left (crop-bottom (crop-top (crop-right pandy (round (* 1/4 (image-width pandy)))) (round (* 1/5 (image-height pandy)))) (round (* 1/8 (image-height pandy)))) (round (* 1/10 (image-width pandy))))) ; The function 'round' takes a number and rounds it to the nearest whole number. ; For example: (round 10.4) ; Produces 10. (round 12345/104) ; Produces 119 (not obvious, I looked at the Interactions area). ; To build the tower of pandas let's restrict ourselves to making each row without ; using the same name twice to build the row (for fun now, and reasons we will ; discuss later in the course). (define two (beside one one)) (define four (beside two two)) (define eight (beside four four)) ; The next expression produces the tower, using the previous definitions. ; I have lined up the uses of 'four', 'two', and 'one' vertically in this document ; but normally that would be bad style for writing an expression. (above one two ; (beside one one one) violates our self-imposed rule (beside two one) ; (beside one one one one) another violation ; (beside one one two) another violation ; (beside two two) another violation four (beside four one) (beside four two) (beside four two one) eight) ; Exercise: put more expressions into that expression to produce a tower with ; fifteen rows. ; The bottom row will be produced by: (beside eight four two one) ; Expressing sixteen with one, two, four, and eight requires repeating at least one ; of those numbers. So sixteen would be the next number of pandas we name: (define sixteen (beside eight eight))
© Copyright 2026 Paperzz