-
Notifications
You must be signed in to change notification settings - Fork 2
/
2points-curve.p8
78 lines (70 loc) · 1.77 KB
/
2points-curve.p8
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
pico-8 cartridge // http://www.pico-8.com
version 36
__lua__
--bezier curve
function fr(n)--rundom integer
return flr(rnd(n))
end
function reset()--make points
s={--start point
x=fr(20)+10,
y=110
}
g={--goal point
x=s.x+fr(50)+50,
y=fr(50)+60
}
p={--control point
x=abs(s.x-g.x)*0.5,
y=g.y-fr(50)-50
}
t=0--timer
r={}--result point
step={}
for n=0,1,0.1 do
add(step,curve(s,g,p,n))
end
end
function _init()
reset()
end
--return point of curve
function curve(s,g,p,st)
-- s:start
-- g:goal
-- p:control point
-- st:step
local x,y=
(s.x-p.x*2+g.x)*st*st+
(-2*s.x+2*p.x)*st+s.x,
(s.y-p.y*2+g.y)*st*st+
(s.y*-2+p.y*2)*st+s.y
return {x=x,y=y}
end
function _update()
r=curve(s,g,p,t)
t+=0.02
if r.y>128 then
reset()
end
end
function _draw()
cls()
circfill(s.x,s.y,4,8)
print("s",s.x-1,s.y-2,7)
circfill(p.x,p.y,1,9)
circfill(g.x,g.y,4,12)
print("g",g.x-1,g.y-2,7)
circfill(r.x,r.y,2,7)
for n=1,#step-1 do
line(step[n].x,step[n].y,
step[n+1].x,step[n+1].y,n)
end
end
__gfx__
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000