jgtrosh

triangles.lua

Jan 28th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.37 KB | None | 0 0
  1. require "gd"
  2.  
  3. size = 400
  4.  
  5. im = gd.createPalette(size, size)
  6. assert(im)
  7.  
  8. black = im:colorAllocate(0, 0, 0)
  9. im:gifAnimBegin("out.gif", true, 0)
  10.  
  11. r = 40
  12. steps = 60
  13. angle = 2*math.pi/steps
  14. for i = 1, steps*2 do
  15.     --tim = gd.create(size, size)
  16.     --tim:paletteCopy(im)
  17.     tim = gd.createTrueColor(size, size)
  18.     --tim:arc(40, 40, 40, 40, 36*(i-1), 36*i, white)
  19.     angles = {{
  20.         angle*i,
  21.         angle*i+2*math.pi/3,
  22.         angle*i+4*math.pi/3,
  23.         -angle*i+2*math.pi,
  24.         -angle*i+4*math.pi/3,
  25.         -angle*i+2*math.pi/3},{
  26.         angle*i+math.pi,
  27.         angle*i+2*math.pi/3+math.pi,
  28.         angle*i+4*math.pi/3+math.pi,
  29.         -angle*i+2*math.pi+math.pi,
  30.         -angle*i+4*math.pi/3+math.pi,
  31.         -angle*i+2*math.pi/3+math.pi}}
  32.     table.sort(angles[1])
  33.     table.sort(angles[2])
  34.     for cx = -8, 12 do
  35.         c = cx%2+1
  36.         oy = cx%2
  37.         for cy = -5, 9, 2 do
  38.             points = {}
  39.             for a = 1, #angles[c] do
  40.                 table.insert(points, {
  41.                     r*(cx+math.cos(angles[c][a]))+oy*i*2,
  42.                     r*(cy+math.sin(angles[c][a]))+oy*i*2})
  43.             end
  44.             w = 255-math.sqrt(math.pow(r*cx+oy*i*2-size/2, 2)+math.pow(r*cy+oy*i*2-size/2, 2))/2
  45.             if w > 0 then
  46.                 tim:filledPolygon(points, tim:colorAllocate(w, w, w))
  47.             end
  48.             --tim:polygon(points, white)
  49.         end
  50.     end
  51.     ti = tim:createPaletteFromTrueColor(true, 5)
  52.     ti:gifAnimAdd("out.gif", true, 0, 0, 5, gd.DISPOSAL_NONE)
  53. end
  54.  
  55. gd.gifAnimEnd("out.gif")
  56.  
  57. print("Gif animation written to 'out.gif' file")
Advertisement
Add Comment
Please, Sign In to add comment