x = "シェルピンスキーのギャスケット"
f_SetTitle("Luaスクリプト:シェルピンスキーのギャスケット")
g = f_Graphics()
require('color')
maxLevel = 5
p = p or Pens.Green
end
function SierpinskiGasket(x1, y1, x2, y2, x3, y3, level)
if level == maxLevel then
g:DrawPolygon(p, {gdi:Point(x1,y1), gdi:Point(x2,y2), gdi:Point(x3,y3)})
else
local ax,ay = (x1 + x2) / 2.0, (y1 + y2) / 2.0
local bx,by = (x2 + x3) / 2.0, (y2 + y3) / 2.0
local cx,cy = (x3 + x1) / 2.0, (y3 + y1) / 2.0
SierpinskiGasket(x1, y1, ax, ay, cx, cy, level + 1)
SierpinskiGasket(x2, y2, ax, ay, bx, by, level + 1)
SierpinskiGasket(x3, y3, cx, cy, bx, by, level + 1)
end
end
w = f_GetClientWidth()
h = f_GetClientHeight()
f_SetBackColor(gdi:Color(15, 15, 35))
SierpinskiGasket(w / 2, 20, 10, h - 10, w - 10, h - 10, 0)
comments powered by