File: arrow.html

package info (click to toggle)
drscheme 1%3A352-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 71,608 kB
  • ctags: 55,284
  • sloc: ansic: 278,966; cpp: 63,318; sh: 32,265; lisp: 14,530; asm: 7,327; makefile: 4,846; pascal: 4,363; perl: 2,920; java: 1,632; yacc: 755; lex: 258; sed: 93; xml: 12
file content (84 lines) | stat: -rw-r--r-- 2,453 bytes parent folder | download | duplicates (2)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<html>
<head>
<title>Teachpack : Arrows</title>
</head>
<body bgcolor="#ffffff" text="#000000"
      link="#009900" vlink="#007700" alink="#cc0000">

<a href="index.html">Teachpacks for How to Design Programs</a>

<h1>Arrows</h1>

<hr> <h3><a name="arrow.ss">arrow.ss</a></h3> <!-- DOCNOTE="teach=arrow.ss" -->

<p>A shape is a class of data for which <code>move</code> and
<code>draw</code> operations can be drawn. </p>

<p>The teachpack <code>arrow.ss</code> implements controller for moving
shapes across a canvass. It provides three operations:
<menu>
  <li> <code><a name="control-left-right">control-left-right</a> : shape number move draw -> true </code>:

  <br> It consumes a shape, a number, a <code>move</code> function and a
  <code>draw</code> function.  The
  move function consumes a number and a  shape and re-draws the shape on
  some canvas and produces a shape that is translated by N pixels left or
  right.
  <br><br>

  <li> <code><a name="control-up-down">control-up-down</a> : shape number move -> true</code>:

  <br> It is like <code>control-left-right</code> but controls movements by
  N pixels up or down.
  <br><br>

  <li> <code><a name="control">control</a> : shape number move-lr move-ud -> true</code>:

  <br> It consumes a shape, a number, two <code>move</code> functions, and a
  draw function.  The <code>move</code> functions consume a number and a
  shape and re-draw the shape on some canvas and produces a shape that is
  translated by N pixels left or right and up or down, respectively.

</menu>

<p>Example:
<pre>
;; A shape is a structure:
;;   (make-posn num num)

;; RAD : the radius of the simple disk moving across a canvas
(define RAD 10)

;; move : number shape -> shape or false
;; to move a shape by delta according to translate
;; effect: to redraw it
(define (move delta sh)
  (cond
    [(and (clear-solid-disk sh RAD)
          (draw-solid-disk (translate sh delta) RAD))
     (translate sh delta)]
    [else false]))

;; translate : shape number -> shape
;; to translate a shape by delta in the x direction
(define (translate sh delta)
  (make-posn (+ (posn-x sh) delta) (posn-y sh)))

;; draw-it : shape -> true
;; to draw a shape on the canvas: a disk with radius
(define (draw-it sh)
  (draw-solid-disk sh RAD))

;; TESTS:

;; this creates the canvas
(start 100 50)

;; this creates the controller GUI
(control-left-right (make-posn 10 20) 10 move draw-it)
</pre>

<br>
<br>
</body>
</html>