Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------xerpi - (c) 2011 -----------------
- math.randomseed(os.time()/math.pi*os.clock()/os.time())
- function draw.circle(x,y,r,color)
- local x0, y0 = r, 0
- for i=0,90,9 do
- local x1,y1 = r*math.cos( math.rad( i )), r*math.sin(math.rad( i ));
- draw.line(x+x1,y+y1,x+x0,y+y0,color);
- draw.line(x+x0,y-y0,x+x1,y-y1,color);
- draw.line(x-x0,y+y0,x-x1,y+y1,color);
- draw.line(x-x0,y-y0,x-x1,y-y1,color);
- x0, y0 = x1, y1;
- end
- end
- particles = {}
- os.cpu(333)
- function random_color()
- return color.new(math.random(50,255),math.random(50,255),math.random(50,255))
- end
- function particles.create(n,max_rad)
- local tab ={initx=ix,inity=iy,status="stop",particles={},rad=max_rad}
- for i = 1, n do
- table.insert(tab.particles,{status="alive",x=0,y=0,vel = math.random(15000,50000)/10000,ang = math.rad(math.random(0,360))})
- tab.particles[i].img = image.create(math.random(500,1000)/100,math.random(200,500)/100,random_color())
- --tab.particles[i].img:clear(color.new(255,0,0))
- tab.particles[i].img:center()
- tab.particles[i].img:rotate(math.deg(tab.particles[i].ang))
- end
- return tab
- end
- function particles.blit(cx,cy,part,rad)
- if part.status != "stop" then
- for i =1, #part.particles do
- if part.particles[i].status != "alive" then continue end
- if part.status == "run" then
- part.particles[i].x = part.particles[i].x + math.cos(part.particles[i].ang)*part.particles[i].vel
- part.particles[i].y = part.particles[i].y + math.sin(part.particles[i].ang)*part.particles[i].vel
- local x = (part.particles[i].x+cx)
- local y = (part.particles[i].y+cy)
- if x >= 480 or x <= 0 or y >= 272 or y <= 0 or math.sqrt(part.particles[i].x*part.particles[i].x+part.particles[i].y*part.particles[i].y) >= rad then
- part.particles[i].status = "dead"
- end
- end
- part.particles[i].img:blit(cx+part.particles[i].x,cy+part.particles[i].y)
- end
- end
- end
- function particles.init(part)
- part.status = "run"
- end
- function particles.pause(part)
- part.status = "pause"
- end
- function particles.stop(part)
- part.status = "stop"
- end
- function particles.reset(part)
- for i =1, #part.particles do
- part.particles[i].status = "alive"
- part.particles[i].x = 0
- part.particles[i].y = 0
- end
- end
- my_part = particles.create(90,100)
- lol= {x=240,y=136,rad=50}
- while true do
- controls.read()
- if math.abs(controls.analogx())>=50 then lol.x=lol.x+controls.analogx()/50 end
- if math.abs(controls.analogy())>=50 then lol.y=lol.y+controls.analogy()/50 end
- if lol.x>=480 then lol.x = 479 end
- if lol.y>=272 then lol.y = 271 end
- if lol.x<=0 then lol.x = 0 end
- if lol.y<=0 then lol.y = 0 end
- draw.circle(lol.x,lol.y,lol.rad,color.new(0,255,0))
- draw.line(lol.x-5,lol.y,lol.x+5,lol.y,color.new(0,255,0))
- draw.line(lol.x,lol.y-5,lol.x,lol.y+5,color.new(0,255,0))
- if controls.press("cross") then
- particles.reset(my_part)
- particles.init(my_part)
- end
- if controls.press("square") then
- particles.pause(my_part)
- end
- if controls.r() then lol.rad=lol.rad+1 end
- if controls.l() then lol.rad=lol.rad-1 end
- particles.blit(lol.x,lol.y,my_part,lol.rad)
- screen.print(430,3,"@"..screen.fps())
- if controls.select() then a() end
- screen.flip()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement