-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtree2.rkt
More file actions
41 lines (33 loc) · 913 Bytes
/
Copy pathtree2.rkt
File metadata and controls
41 lines (33 loc) · 913 Bytes
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
#lang racket
#|
Draw a fractal tree
DONE:
- Make the branches join up!
TODO:
- Have more than 2 branches
- Vary stem thickness
- Introduce some randomness
|#
(require 2htdp/image)
(require racket/trace)
(define BRANCH-COLOUR "white")
(define MIN-SIZE 3)
(define DS 0.6)
(define DA 30)
(define (tree scene x y size angle)
;; Return a new scene with a tree on it
(if (< size MIN-SIZE)
scene
(let* ([a (degrees->radians angle)]
[x2 (+ x (* (cos a) size))]
[y2 (+ y (* (sin a) size))]
[next-size (* size DS)]
[next-angle-1 (+ angle DA)]
[next-angle-2 (- angle DA)])
(tree
(tree
(add-line scene x y x2 y2 BRANCH-COLOUR)
x2 y2 next-size next-angle-1)
x2 y2 next-size next-angle-2))))
;; (tree (empty-scene 0 0 "black") 0 0 50 90)
;; (tree (empty-scene 200 200 "blue") 100 190 50 270)