Skip to content

Instantly share code, notes, and snippets.

@toomasv
Last active February 4, 2021 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toomasv/373703d4e4a828f857838fae86d07ee5 to your computer and use it in GitHub Desktop.
Save toomasv/373703d4e4a828f857838fae86d07ee5 to your computer and use it in GitHub Desktop.
Red [
Author: {Toomas Vooglaid}
Date: 2017-11-13
]
dragon: func [n /local m k][
m: -1 until [odd? k: n / (2 ** (m: m + 1))]
pick [90 -90] 0 = (k - 3 % 4)
]
n: m: 0
drawing: forward: auto: true
tmp: copy []
view [
_stop: button "Stop" [face/text: pick ["Stop" "Start"] drawing: auto: not drawing]
text "Scale" 30x20
slider 100% react [img/draw/2/1: to-float face/data img/draw/2/4: to-float face/data]
text "Rate" 25x20
slider 50% react [img/rate: either 0 < drawrate: to-integer 100 * to-float face/data [drawrate][1]]
bcwd: button "<" 20x20 font [size: 10] [
frwd/font/size: 10 face/font/size: 14 forward: false
unless drawing and (n >= 1) [
remove/part find/last img/draw 'rotate tail img/draw;skip tail img/draw -7 tail img/draw
n: n - 1 _count/data: n
]
]
_count: field 50x20 data n [
either face/data <= n [
remove/part skip tail img/draw 7 * (face/data - n) tail img/draw
n: face/data
][
remove/part tmp tail tmp
repeat i face/data - n [
append tmp compose [rotate (dragon n + i) line 0x0 10x0 translate 10x0]
]
append img/draw tmp
n: _count/data: face/data
]
if auto [drawing: true _stop/text: "Stop"]
]
on-down [
drawing: false _stop/text: "Start"
]
frwd: button ">" 20x20 font [size: 14] [
bcwd/font/size: 10 face/font/size: 14 forward: true
unless drawing [
append img/draw compose [rotate (dragon n: n + 1) line 0x0 10x0 translate 10x0]
_count/data: n
]
]
return
img: image 600x600
draw [matrix [1 0 0 1 350 450] pen red]
rate 30
on-time [
if drawing [
either forward [
append face/draw compose [rotate (dragon n: n + 1) line 0x0 10x0 translate 10x0]
][
either n >= 1 [
remove/part find/last img/draw 'rotate tail img/draw
n: n - 1
][
drawing: no forward: yes
bcwd/font/size: 10 frwd/font/size: 14
_stop/text: "Start"
]
]
_count/data: n
]
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment