図形描画(ドラゴン曲線)

ドラゴン曲線

x = "ドラゴン曲線" 
f_SetTitle("Luaスクリプト:ドラゴン曲線")
gra = f_Graphics()
require('color')
maxLevel = 10
p = p or Pens.Cyan
function DragonCurve(ax, ay ,bx, by ,n)
  local xx,yy = bx-ax, ay-by
  local cx, cy = ax+(xx+yy)/2, by+(xx+yy)/2
  if n == maxLevel then
     gra:DrawLines(p, {gdi:Point(ax, ay), gdi:Point(cx, cy), gdi:Point(bx, by)})
  else
     DragonCurve(ax, ay ,cx, cy ,n + 1)
     DragonCurve(bx, by, cx, cy ,n + 1)
  end
end
gra:Clear(gdi:Color(35, 15, 15))
w = f_GetClientWidth()
h = f_GetClientHeight()
DragonCurve(w/2, h/4, 2*w/3, 3*h/4, 0)
 
comments powered by Disqus