forked from stevelavietes/pico8carts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
boids.p8
183 lines (181 loc) · 17 KB
/
boids.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
pico-8 cartridge // http://www.pico-8.com
version 16
__lua__
--al meetup 2019 intro tweetcart
--by stephan_gfx
d=8192z=11v=128
cls()
tgt={
{rnd()*v,rnd()*v},
{rnd()*v,rnd()*v}
}
pset(tgt[1][1],tgt[1][2],9)
pset(tgt[2][1],tgt[2][2],9)
boids={}
for i=0,v do
add(boids,{rnd()*v, rnd()*v,1,.5})
end
function dst(p1, p2)
g = {
p2[1] - p1[1],
p2[2] - p1[2]
}
return g, g[1]*g[1]+g[2]*g[2]
end
function lerp(a,b,m)
return (a-b)*(1-m) + b
end
::_::
flip()cls()
for b in all(boids) do
pset(flr(b[1]),flr(b[2]),z)
g1, d1 = dst(b, tgt[1])
g2, d2 = dst(b, tgt[2])
g = (d1 < d2 and g1 or g2)
a = atan2(g[1], g[2])
b[3] = lerp(b[3],a,0.25*(a-b[3]))
b[1] += sin(b[3])*b[4]
b[2] += cos(b[3])*b[4]
end
for t in all(tgt) do
pset(flr(t[1]),flr(t[2]),9)
end
--[[
n=0
for i=x-1,x+1 do
for j=y-1,y+1 do
l=pget(i,j)n+=l/3+z*flr(l/z)end
end
sset(x,y,(n>9or n==2or n==3)and 3or 0)end
]]--
--m(d*3,0,d)
goto _
__label__
00000000000003000000030000030003bbb333b3bb33b3b30000030003000003bbb3b3330003bbb3bbb3bbb3bbb3b3b3bbb30300030333000000030000000000
00000000000330000000030000030003b3333b333b33b3b30000030003000003b3b3b3330003bbb3b333b3333b33b3b3b3b30300033000000000030000000000
00000003333333000000030000030003bbb33b303b33bbb30000030003000003bbb3b3000003b3b3bb33bb303b33b3b3bbb30000330000000000030000000000
0000003333333333000003000003000333b33b333b3333b30000030003000003b3b3b3330003b3b3b333b3333b33b3b3b3330003300000003000030000000000
00000333330000003000030000030003bbb3b333bbb303b30000030003000003b3b3bbb30003b3b3bbb3bbb33b333bb3b3000003330000300300300000000000
33333330000000003300003333030003333333033333033300000300030000033333333300033333333333333330333333300033000003000300300000000000
33333000330000000300000000300000000000000000000000000300030000000000000030000000000000000000000000000033300000300300300000000000
33330003003000000030000000000003333303333333333300000300030000033333330333033333333333333333333333330033000000003000030000000000
00000330000300000030000000000003bbb333b3bb33b3b30000030003000003bbb3b3033303bbb3bbb3bbb3bbb3b3b3bbb30303000330000000030000000000
00003000000300000033333333000003b3333b333b33b3b30000030003000003b3b3b3000003bbb3b333b3333b33b3b3b3b33033000330000000030000000000
00030000000330000033300000300003bbb33b303b33bbb30000030003000003bbb3b3000003b3b3bb33bb303b33b3b3bbb30303000330000000030000000000
0003000000033000000333000300000333b33b333b3333b30000030003000003b3b3b3330003b3b3b333b3333b33b3b3b3330033000000003000030000000000
00333033033300000003330030000003bbb3b333bbb303b30000030003000003b3b3bbb30003b3b3bbb3bbb33b333bb3b3000033300000300300300000000000
33003033033000000000333300000003333333033333033300000300030000033333333300033333333333333330333333300303000000300300300000000000
33000333300000000330030000030000000000000000000000000300030000000000000030000000000000000000000000000033300000300300300000000000
33000033000000000333003000330003333303333333333300000300030000033333330333033333333333333333333333330033000000003000030000000000
00030003000000000303000000333303bbb333b3bb33b3b30000030003000003bbb3b3033303bbb3bbb3bbb3bbb3b3b3bbb30303000330000000030000000000
33000000000000000300333000033303b3333b333b33b3b30000030003000003b3b3b3000003bbb3b333b3333b33b3b3b3b33033000330000000030000000000
33303330000000003000000000000033bbb33b303b33bbb30000030003000003bbb3b3000003b3b3bb33bb303b33b3b3bbb30303000330000000030000000000
3333300300000000300000000000330333b33b333b3333b30000030003000003b3b3b3330003b3b3b333b3333b33b3b3b3330033000000003000030000000000
00033000330000003000003333300303bbb3b333bbb303b30000030330000003b3b3bbb30003b3b3bbb3bbb33b333bb3b3000033300000300300300000000000
00000000333000000333330000030033333333033333033300000033300000033333333300033333333333333330333333300303000000300300300000000000
33330000333300003000333000033330000000000000000000300033330000000000000030000000000000000000000000000033300000300300300000000000
30300000300300333000333000333033333303333333333303033300003330033333330333033333333333333333333333330033000000003000030000000000
33000000000300333000333003330033bbb333b3bb33b3b30030330000003303bbb3b3033303bbb3bbb3bbb3bbb3b3b3bbb30303000330000000030000000000
00300000000300000000003003330033b3333b333b33b3b30333300333003303b3b3b3000003bbb3b333b3333b33b3b3b3b33033000330000000030000000000
33330000000330000003003333333303bbb33b303b33bbb30330033000330003bbb3b3000003b3b3bb33bb303b33b3b3bbb30303000330000000030000000000
0003300003330003333330333300330333b33b333b3333b33003000000330003b3b3b3330003b3b3b333b3333b33b3b3b3330033000000003000030000000000
00003000000000033333033030033003bbb3b333bbb303b30303000000300003b3b3bbb30003b3b3bbb3bbb33b333bb3b3000033300000300300300000000000
30000000333033333003033300333303333333033333033300330000030300033333333300033333333333333330333333300303000000300300300000000000
00300000003333333300300033003300000000000000000000303000033000000000000030000000000000000000000000000033300000300300300000000000
00300000003330333300000033003303333303333333333300300000303000033333330333033333333333333333333333330033000000003000030000000000
00300000000000333330000033000003bbb333b3bb33b3b30030030333000003bbb3b3033303bbb3bbb3bbb3bbb3b3b3bbb30303000330000000030000000000
03300000000033000003303300300003b3333b333b33b3b30330333333330003b3b3b3000003bbb3b333b3333b33b3b3b3b33033000330000000030000000000
03300000000033333330033303000003bbb33b303b33bbb30330330333333303bbb3b3000003b3b3bb33bb303b33b3b3bbb30303000330000000030000000000
0030000000030333000033330000000333b33b333b3333b30330300330033003b3b3b3330003b3b3b333b3333b33b3b3b3330033000000003000030000000000
00300000000303330000030303000303bbb3b333bbb303b30003300300000003b3b3bbb30003b3b3bbb3bbb33b333bb3b3000033300000300300300000000000
00300000003300003000003333000003333333033333033300000033033000033333333300033333333333333330333333300303000000300300300000000000
00330030303300003000003000000000000000000000000000003303330000000000000030000000000000000000000000000033300000300300300000000000
00030003000300030030333000000003333303333333333300003333300000033333330333033333333333333333333333330033000000003000030000000000
00030003000300030330000000300003bbb333b3bb33b3b30033003303000003bbb3b3033303bbb3bbb3bbb3bbb3b3b3bbb30303000330000000030000000000
33333000333000033333330000030003b3333b333b33b3b30000330003000003b3b3b3000003bbb3b333b3333b33b3b3b3b33033000330000000030000000000
00033003000000000333333000003303bbb33b303b33bbb30000030003000003bbb3b3000003b3b3bb33bb303b33b3b3bbb30303000330000000030000000000
0003300030000000003330030000330333b33b333b3333b30000030003000003b3b3b3330003b3b3b333b3333b33b3b3b3330033000000003000030000000000
33330000333333333000030030003303bbb3b333bbb303b30000030003000003b3b3bbb30003b3b3bbb3bbb33b333bb3b3000033300000300300300000000000
00030000030000003300003003003003333333033333033300000300030000033333333300033333333333333330333333300303000000300300300000000000
00033000030000003333330003003000000000000000000000000300030000000000000030000000000000000000000000000033300000300300300000000000
00000300333333300300000333003303333303333333333300000300030000033333330333033333333333333333333333330033000000003000030000000000
33333000300000000000000330000003bbb333b3bb33b3b30000030003000003bbb3b3033303bbb3bbb3bbb3bbb3b3b3bbb30303000330000000030000000000
00030033000000000030000333000033b3333b333b33b3b30000030003000003b3b3b3000003bbb3b333b3333b33b3b3b3b33033000330000000030000000000
00030030003303000030000003000033bbb33b303b33bbb30000030003000003bbb3b3000003b3b3bb33bb303b33b3b3bbb30303000330000000030000000000
3000003000000030000300000030003333b33b333b3333b30000030003000003b3b3b3330003b3b3b333b3333b33b3b3b3330033000000003000030000000000
00300003333000030003000000300033bbb3b333bbb303b30000030003000003b3b3bbb30003b3b3bbb3bbb33b333bb3b3000033300000300300300000000000
33000003300000003003333000030033333333033333033300000300030000033333333300033333333333333330333333300303000000300300300000000000
33000003330330003333000300003030000000000000000000000300030000000000000030000000000000000000000000000033300000300300300000000000
30000000033330033303000300000333333303333333333300000300030000033333330333033333333333333333333333330033000000003000030000000000
03000003033333303000000030000003bbb333b3bb33b3b30000030003000003bbb3b3033303bbb3bbb3bbb3bbb3b3b3bbb30303000330000000030000000000
30000000003333330330000003000003b3333b333b33b3b30000030003000003b3b3b3000003bbb3b333b3333b33b3b3b3b33033000330000000030000000000
00003000030030330030000000300003bbb33b303b33bbb30000030003000003bbb3b3000003b3b3bb33bb303b33b3b3bbb30303000330000000030000000000
0003300003033030000030000003000333b33b333b3333b30000030003000003b3b3b3330003b3b3b333b3333b33b3b3b3330033000000003000030000000000
00033000000333000000330003333003bbb3b333bbb303b30000030003000003b3b3bbb30003b3b3bbb3bbb33b333bb3b3000033300000300300300000000000
30330333330333000003333333300303333333033333033300000300030000033333333300033333333333333330333333300303000000300300300000000000
03303300330333000030330003300300000000000000000000000300030000000000000030000000000000000000000000000033300000300300300000000000
00300033000300300033330000300303333303333333333300000300030000033333330333033333333333333333333333330033000000003000030000000000
00300000333333300003303333330303bbb333b3bb33b3b30000030003000003bbb3b3033303bbb3bbb3bbb3bbb3b3b3bbb30303000330000000030000000000
00033000303033300003300033333003b3333b333b33b3b30000030003000003b3b3b3000003bbb3b333b3333b33b3b3b3b33033000330000000030000000000
00000033303000330003300330030003bbb33b303b33bbb30000030003000003bbb3b3000003b3b3bb33bb303b33b3b3bbb30303000330000000030000000000
0000003303333300330030300030000333b33b333b3333b30000030003000003b3b3b3330003b3b3b333b3333b33b3b3b3330033000000003000030000000000
00000030030033003000333000330003bbb3b333bbb303b30000030003000003b3b3bbb30003b3b3bbb3bbb33b333bb3b3000033300000300300300000000000
00000033033330000003030000333003333333033333033300000300030000033333333300033333333333333330333333300303000000300300300000000000
00000003000003030000030003000300000000000000000000000300030000000000000030000000000000000000000000000033300000300300300000000000
00033003300030030030030000300303333303333333333300000300030000033333330333033333333333333333333333330033000000003000030000000000
00303303300030030300030000030303bbb333b3bb33b3b30000030003000003bbb3b3033303bbb3bbb3bbb3bbb3b3b3bbb30303000330000000030000000000
03300033000030033300003330030303b3333b333b33b3b30000030003000003b3b3b3000003bbb3b333b3333b33b3b3b3b33033000330000000030000000000
03303333000003333300000003330303bbb33b303b33bbb30000030003000003bbb3b3000003b3b3bb33bb303b33b3b3bbb30303000330000000030000000000
0033330333000030033333333330030333b33b333b3333b30000030003000003b3b3b3330003b3b3b333b3333b33b3b3b3330033000000003000030000000000
00033333303000300033330000300303bbb3b333bbb303b30000030003000003b3b3bbb30003b3b3bbb3bbb33b333bb3b3000033300000300300300000000000
33033000303003000033330000300303333333033333033300000300030000033333333300033333333333333330333333300303000000300300300000000000
33003300033330000000330000303000000000000000000000000300030000000000000030000000000000000000000000000033300000300300300000000000
33300330003000000000300000000003333303333333333300000300030000033333330333033333333333333333333333330033000000003000030000000000
03330003000000000003000000000003bbb333b3bb33b3b30000030003000003bbb3b3033303bbb3bbb3bbb3bbb3b3b3bbb30303000330000000030000000000
00333003303333333333300000030303b3333b333b33b3b30000030003000003b3b3b3000003bbb3b333b3333b33b3b3b3b33033000330000000030000000000
00033300333333333330033000303303bbb33b303b33bbb30000030003000003bbb3b3000003b3b3bb33bb303b33b3b3bbb30303000330000000030000000000
0000333003333333330003333330330333b33b333b3333b30000030003000003b3b3b3330003b3b3b333b3333b33b3b3b3330033000000003000030000000000
00000333000000000000033330003303bbb3b333bbb303b30000030003000003b3b3bbb30003b3b3bbb3bbb33b333bb3b3000033300000300300300000000000
33333003000000000000033330000303333333033333033300000300030000033333333300033333333333333330333333300303000000300300300000000000
33333333000000000000033000000000000000000000000000000300030000000000000030000000000000000000000000000033300000300300300000000000
33333330000000000000003000000003333303333333333300000300030000033333330333033333333333333333333333330033000000003000030000000000
00000000000000000000000000300003bbb333b3bb33b3b30000030003000003bbb3b3033303bbb3bbb3bbb3bbb3b3b3bbb30303000330000000030000000000
00000000000000000333003330030003b3333b333b33b3b30000030003000003b3b3b3000003bbb3b333b3333b33b3b3b3b33033000330000000030000000000
00000000000000000333333000030003bbb33b303b33bbb30000030003000003bbb3b3000003b3b3bb33bb303b33b3b3bbb30303000330000000030000000000
0000000000000000300003000003000333b33b333b3333b30000030003000003b3b3b3330003b3b3b333b3333b33b3b3b3330033000000003000030000000000
00000000000000033000030000030003bbb3b333bbb303b30000030003000003b3b3bbb30003b3b3bbb3bbb33b333bb3b3000033300000300300300000000000
33333333333333300000030000030003333333033333033300000300030000033333333300033333333333333330333333300303000000300300300000000000
33333333333333000000030000030000000000000000000000000300030000000000000030000000000000000000000000000033300000300300300000000000
33333333333330000000030000030003333303333333333300000300030000033333330333033333333333333333333333330033000000003000030000000000
00000000000003000000030000030003bbb333b3bb33b3b30000030003000003bbb3b3033303bbb3bbb3bbb3bbb3b3b3bbb30303000330000000030000000000
00000000000003000000030000030003b3333b333b33b3b30000030003000003b3b3b3000003bbb3b333b3333b33b3b3b3b33033000330000000030000000000
00000000000003000000030000030003bbb33b303b33bbb30000030003000003bbb3b3000003b3b3bb33bb303b33b3b3bbb30303000330000000030000000000
0000000000000300000003000003000333b33b333b3333b30000030003000003b3b3b3330003b3b3b333b3333b33b3b3b3330033000000003000030000000000
00000000000003000000030000030003bbb3b333bbb303b30000030003000003b3b3bbb30003b3b3bbb3bbb33b333bb3b3000033300000300300300000000000
00000000000003000000030000030003333333033333033300000300030000033333333300033333333333333330333333300303000000300300300000000000
00000000000003000000030000030000000000000000000000000300030000000000000030000000000000000000000000000033300000300300300000000000
00000000000003000000030000030003333303333333333300000300030000033333330333033333333333333333333333330033000000003000030000000000
00000000000003000000030000030003bbb333b3bb33b3b30000030003000003bbb3b3033303bbb3bbb3bbb3bbb3b3b3bbb30303000330000000030000000000
00000000000003000000030000030003b3333b333b33b3b30000030003000003b3b3b3000003bbb3b333b3333b33b3b3b3b33033000330000000030000000000
00000000000003000000030000030003bbb33b303b33bbb30000030003000003bbb3b3000003b3b3bb33bb303b33b3b3bbb30303000330000000030000000000
0000000000000300000003000003000333b33b333b3333b30000030003000003b3b3b3330003b3b3b333b3333b33b3b3b3330033000000003000030000000000
00000000000003000000030000030003bbb3b333bbb303b30000030003000003b3b3bbb30003b3b3bbb3bbb33b333bb3b3000033300000300300300000000000
00000000000003000000030000030003333333033333033300000300030000033333333300033333333333333330333333300303000000300300300000000000
00000000000003000000030000030000000000000000000000000300030000000000000030000000000000000000000000000033300000300300300000000000
00000000000003000000030000030003333303333333333300000300030000033333330333033333333333333333333333330033000000003000030000000000
00000000000003000000030000030003bbb333b3bb33b3b30000030003000003bbb3b3033303bbb3bbb3bbb3bbb3b3b3bbb30303000330000000030000000000
00000000000003000000030000030003b3333b333b33b3b30000030003000003b3b3b3000003bbb3b333b3333b33b3b3b3b33033000330000000030000000000
00000000000003000000030000030003bbb33b303b33bbb30000030003000003bbb3b3000003b3b3bb33bb303b33b3b3bbb30303000330000000030000000000
0000000000000300000003000003000333b33b333b3333b30000030003000003b3b3b3330003b3b3b333b3333b33b3b3b3330033000000003000030000000000
00000000000003000000030000030003bbb3b333bbb303b30000030003000003b3b3bbb30003b3b3bbb3bbb33b333bb3b3000033300000300300300000000000
00000000000003000000030000030003333333033333033300000300030000033333333300033333333333333330333333300033000003000300300000000000
00000000000003000000030000030000000000000000000000000300030000000000000030000000000000000000000000000003330033300300300000000000
00000000000003000000030000030003333303333333333300000300030000033333330333033333333333333333333333330003330000003000030000000000
00000000000003000000030000030003bbb333b3bb33b3b30000003330000003bbb3b3033303bbb3bbb3bbb3bbb3b3b3bbb30000000300000000030000000000
00000000000003000000030000300003b3333b333b33b3b30000000000000003b3b3b3000003bbb3b333b3333b33b3b3b3b30300000330000000030000000000
00000000000003000000030003330303bbb33b303b33bbb30033300000333003bbb3b3000003b3b3bb33bb303b33b3b3bbb30000000333000000030000000000
0000000000000300000003003303300333b33b333b3333b30033330003333003b3b3b3330003b3b3b333b3333b33b3b3b3330000000000000000030000000000
00000000000003000000030033300033bbb3b333bbb303b30030300000303003b3b3bbb30003b3b3bbb3bbb33b333bb3b3000000000300000000300000000000
00000000000003000000000333000033333333033333033300030003000300033333333300033333333333333330333333000000000000000003000000000000
00000000000000300000003333000030000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000
00000000000000030000003333000003333333333333333333000000000003333333333333333333333333333333333333000000303000000300000000000000