Mailing List Archive: 49091 messages

[REBOL] Beziere curve example

From: rebol-list2::seznam::cz at: 15-Jan-2003 13:34

```
Hello rebol-list,

I've just made one simple script without any serious reason...
... so injoy it if you want...

=( Oliva David )=======================( [oliva--david--seznam--cz] )==
=( Earth/Europe/Czech_Republic/Brno )=============================
=( coords: [lat: 49.22 long: 16.67] )=============================

-- Attached file included as plaintext by Listar --
-- File: bezier-curve.r

REBOL [
title: "Bezier Curve"
author: "Oldes"
note: {Inspired by Cyphre's Spline demo and by one Flash file}
]

drawcurve: has [result pp x0 x1 x2 x3 y0 y1 y2 y3 cx bx ax cy by ay t tx ty s] [
result: make block! 20
pp: p0/size/x / 2
x0: p0/offset/x + pp
y0: p0/offset/y + pp
x1: p1/offset/x + pp
y1: p1/offset/y + pp
x2: p2/offset/x + pp
y2: p2/offset/y + pp
x3: p3/offset/x + pp
y3: p3/offset/y + pp

insert result compose [
pen 155.0.0
line (p0/offset + pp) (p1/offset + pp)
line (p2/offset + pp) (p3/offset + pp)
pen 255.255.255 line (p0/offset + pp)
]
cx: 3 * (x1 - x0)
bx: 3 * (x2 - x1) - cx
ax: x3 - x0 - cx - bx
cy: 3 * (y1 - y0)
by: 3 * (y2 - y1) - cy
ay: y3 - y0 - cy - by

t: s: 0.01 ;this value sets quality of the curve

while [t <= 1][
tx: to integer! (
(ax * (t * t * t)) + (bx * (t * t)) + (cx * t) + .5
) + x0
ty: to integer! (
(ay * (t * t * t)) + (by * (t * t)) + (cy * t) + .5
) + y0

t: t + s
insert tail result to pair! reduce [tx ty]
]
return result
]

click?: false
mouse-pos: 0x0

fl: [
effect: [draw [pen 255.0.0 fill-pen 200.0.0 circle 4x4 4]]
feel: make feel [
engage: func [f a e][
if find [down] a [
click?: true
mouse-pos: e/offset
]
if find [up] a [
click?: false
]
if find [over away] a [
if click? [
f/offset: f/offset + e/offset - mouse-pos
f/changes: [offset]
bkg/effect: compose/deep [draw [(drawcurve)]]
show [bkg f]
]
]
]
]
]

view layout [
origin 0
bkg: box black 400x400
at 300x200
p0: box 10x10 with fl
at 200x100
p1: box 10x10 with fl
at 200x300
p2: box 10x10 with fl
at 100x200
p3: box 10x10 with fl
do [bkg/effect: compose/deep [draw [(drawcurve)]]]
]
```