-
Notifications
You must be signed in to change notification settings - Fork 0
/
105.rkt
63 lines (52 loc) · 2.01 KB
/
105.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
;; 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 105ex) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f)))
;; Exercise 104.
;; -------------
;; Some program contains the following data definition:
;;
;; ; A Coordinate is one of:
;; ; – a NegativeNumber
;; ; interpretation on the y axis, distance from top
;; ; – a PositiveNumber
;; ; interpretation on the x axis, distance from left
;; ; – a Posn
;; ; interpretation an ordinary Cartesian point
;;
;; Make up at least two data examples per clause in the data definition. For
;; each of the examples, explain its meaning with a sketch of a canvas.
;; -----------------------------------------------------------------------------
(require 2htdp/image)
(define BACKG (empty-scene 200 200))
(define point (circle 5 "solid" "red"))
; A Coordinate is one of:
; – a NegativeNumber
; interpretation on the y axis, distance from top
; – a PositiveNumber
; interpretation on the x axis, distance from left
; – a Posn
; interpretation an ordinary Cartesian point
; Examples of the first clause:
(define cneg-1 -50)
(define cneg-2 -10)
; Examples of the second clause:
(define cpos-1 50)
(define cpos-2 10)
; Examples of the third clause:
(define cposn-1 (make-posn 50 10))
(define cposn-2 (make-posn 10 50))
(define canv-cneg-1 (place-image point (* -1 cneg-1) 0 BACKG))
(define canv-cneg-2 (place-image point(* -1 cneg-2) 0 BACKG))
(define canv-cpos-1 (place-image point 0 cpos-1 BACKG))
(define canv-cpos-2 (place-image point 0 cpos-2 BACKG))
(define canv-cposn-1 (place-image point (posn-x cposn-1) (posn-y cposn-1) BACKG))
(define canv-cposn-2 (place-image point (posn-x cposn-2) (posn-y cposn-2) BACKG))
; on the y axis
canv-cneg-1
canv-cneg-2
; on the x axis
canv-cpos-1
canv-cpos-2
; any posn
canv-cposn-1
canv-cposn-2