jgtrosh

circles.lua

Feb 2nd, 2014
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.20 KB | None | 0 0
  1. require "gd"
  2.  
  3. size = 400
  4. cenx = 125
  5. ceny = 275
  6.  
  7. im = gd.createPalette(size, size)
  8. assert(im)
  9.  
  10. black = im:colorAllocate(0, 0, 0)
  11. im:gifAnimBegin("out.gif", true, 0)
  12.  
  13. r = 100
  14. astep = math.pi
  15. for i = 1, 15 do
  16.     local tim = gd.createTrueColor(size, size)
  17.     --tim:setAntiAliased(tim:colorAllocate(0, 0, 0))
  18.     for c = 14, 0, -1 do
  19.         local ccenx = cenx+16*c+i
  20.         local cceny = ceny-16*c-i
  21.         local angles = {}
  22.         for angle = 0, 2*math.pi, astep*math.pow(0.98, 15*c) do
  23.             table.insert(angles, angle)
  24.         end
  25.         local points = {}
  26.         for a = 1, #angles do
  27.             table.insert(points, {
  28.                 ccenx+r*math.cos(angles[a]),
  29.                 cceny+r*math.sin(angles[a])})
  30.         end
  31.         local w = (380-ccenx)%256
  32.         tim:filledPolygon(points, tim:colorAllocate(w, w, w))
  33.         tim:polygon(points, tim:colorAllocate(0, 0, 0))
  34.         --[[
  35.         for p = 1, #points-1 do
  36.             tim:line(points[p][1], points[p][2], points[p+1][1], points[p+1][2], gd.ANTI_ALIASED)
  37.         end
  38.         tim:line(points[#points][1], points[#points][2], points[1][1], points[1][2], gd.ANTI_ALIASED)
  39.         --]]
  40.     end
  41.     astep = astep*0.98
  42.     local ti = tim:createPaletteFromTrueColor(true, 8)
  43.     ti:gifAnimAdd("out.gif", true, 0, 0, 5, gd.DISPOSAL_NONE)
  44.     io.write(i.." ")
  45. end
  46.  
  47. gd.gifAnimEnd("out.gif")
Advertisement
Add Comment
Please, Sign In to add comment