Last active
June 23, 2018 19:09
-
-
Save toomasv/6176114cf830390bc46bca29ba2b029f to your computer and use it in GitHub Desktop.
Study of quadratic bezier curve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [ | |
Author: "Toomas Vooglaid" | |
Date: 2018-03-14 | |
Needs: 'View | |
] | |
system/view/auto-sync?: off | |
btw-points: func [pt1 pt2 rel][ | |
pt2 - pt1 * rel + pt1 | |
] | |
points: [50x200 100x100 200x200] | |
blk: copy [] i: -1 | |
foreach point points [append blk reduce ['circle point 2 'text point + 5x-10 rejoin ["P" i: i + 1]]] | |
append blk compose [pen gray line (points) pen black text 110x190 "t = " line 10x210 250x210] | |
blk2: copy blk | |
append blk compose [ | |
pen red line-width 2 curve (points) | |
pen green line-width 1 line (p1: btw-points points/1 points/2 25%) (p2: btw-points points/2 points/3 25%) | |
circle (p1) 1 circle (p2) 1 | |
pen black text (p1 - 20x10) "Q0" text (p2 + 5x-10) "Q1" | |
circle (p3: btw-points p1 p2 25%) 2 text (p3) "B" | |
text 130x190 ".25" | |
] | |
append blk2 compose [ | |
pen green l: line (points/1) (points/2) | |
c1: circle (points/1) 1 c2: circle (points/2) 1 | |
pen black c3: circle (points/1) 2 | |
t: text 130x190 "" | |
pen red line-width 2 | |
crv: curve (points/1) (points/1) (points/1) | |
] | |
tick: 0.0 | |
view/tight compose/deep/only [ | |
b1: box 300x250 | |
draw (blk) | |
b2: box 300x250 | |
rate 25 | |
on-time [ | |
tick: tick + 1 | |
r: tick % 100 / 100 | |
l/2: btw-points points/1 points/2 r | |
l/3: btw-points points/2 points/3 r | |
c1/2: l/2 | |
c2/2: l/3 | |
c3/2: btw-points c1/2 c2/2 r | |
crv/3: c1/2 crv/4: c3/2 | |
t/3: form r | |
show b2 | |
] | |
draw (blk2) | |
at 350x10 text "Rate:" at 390x10 rate: field 40x24 "25" | |
at 440x10 button 50x24 "Stop" [ | |
either b2/rate [ | |
b2/rate: none face/text: "Go" show [face b2] | |
][ | |
b2/rate: rate/data face/text: "Stop" show [face b2] | |
] | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great work as usual! 👍
Some possible minor simplifications:
compose/deep/only
to remove one level of block wrapping:view lay
instead ofview/no-wait lay
. The latter will not start an event loop, which works fine from the GUI console, because the console provides already a View event loop. Though, in other contexts (like compilation), this won't work. The standard way is to useview
to create an event loop, thenview/no-wait
for additional windows to use the existing event loop and not create new ones.