PocketCHIPのPICO-8でボロノイ図を描画するプログラムを作ってみました。
![イメージ 1](https://stat.ameba.jp/user_images/20190615/05/time-tripper-ame/f2/52/j/o0560055914465091014.jpg?caw=800)
プログラムはたったのこれだけです。
ショートプログラムは俳句や短歌のようで楽しいです。
ショートプログラムは俳句や短歌のようで楽しいです。
-- voronoi diagram
-- (c) time tripper 2016
-- (c) time tripper 2016
bit={}
bn=20
bs=32
bc=9
bf=9
bn=20
bs=32
bc=9
bf=9
function _init()
for i=1,bn do
end
make_bit()
endfunction make_bit()
local b={}
b.x=rnd(128)
b.y=rnd(128)
b.c=1+flr(rnd(15))
b.dx=2-rnd(4)
b.dy=2-rnd(4)
add(bit,b)
end b.x=rnd(128)
b.y=rnd(128)
b.c=1+flr(rnd(15))
b.dx=2-rnd(4)
b.dy=2-rnd(4)
add(bit,b)
function move_bit(sp)
sp.x += sp.dx
sp.y += sp.dy
if sp.x < 0 then sp.dx *= -1 end
if sp.y < 0 then sp.dy *= -1 end
if sp.x > 127 then sp.dx *= -1 end
if sp.y > 127 then sp.dy *= -1 end
endsp.y += sp.dy
if sp.x < 0 then sp.dx *= -1 end
if sp.y < 0 then sp.dy *= -1 end
if sp.x > 127 then sp.dx *= -1 end
if sp.y > 127 then sp.dy *= -1 end
function _update()
if btn(0) and bc>1 then bc-=1 end
if btn(1) and bc<32 then bc+=1 end
if btn(2) and bf>0 then bf-=1 end
if btn(3) and bf<15 then bf+=1 end
if btn(4) then make_bit() end
if btn(5) then del(bit,bit[1]) end
foreach(bit,move_bit)
endif btn(1) and bc<32 then bc+=1 end
if btn(2) and bf>0 then bf-=1 end
if btn(3) and bf<15 then bf+=1 end
if btn(4) then make_bit() end
if btn(5) then del(bit,bit[1]) end
foreach(bit,move_bit)
function _draw()
cls()
for i=bs,1,-1 do
print("count="..count(bit),0,0,8)
print("pattern="..bc,0,6,8)
print("color="..bf,0,12,8)
endfor i=bs,1,-1 do
for b in all(bit) do
end
circfill(b.x,b.y,i,(b.c+bf+flr(i/bc))%16)
endprint("count="..count(bit),0,0,8)
print("pattern="..bc,0,6,8)
print("color="..bf,0,12,8)