Particles
Author |
Message |
Diablo117
|
Posted: Mon Jun 22, 2009 4:42 pm Post subject: Particles |
|
|
Hi, I decided to make a particle program today as I was bored, copy and paste the code .
Turing: |
%Particle Engine%
View.Set ("offscreenonly;graphics:max;max;nobuttonbar")
var particlesx : flexible array 0 .. 1 of int
var particlesy : flexible array 0 .. 1 of int
var velx : flexible array 0 .. 1 of int
var vely : flexible array 0 .. 1 of int
var totalParticles : int := 0
var keys : array char of boolean
var reBound : boolean := false
var x, y, button : int
var counter : int
x := 1
y := 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%MODIFY VARIABLES IF YOU WISH TO HERE%
var delayTime : int := 10
var Gravity : int := 1
%var particlePicture : int := Pic.FileNew ("snow.bmp")
var radius : int := 1
var circleColor : int := Rand.Int (1, 255)
var outsideColor : int := Rand.Int (1, 255)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
colorback (255)
proc reDraw
for i : 1 .. totalParticles
particlesx (i ) + = velx (i )
particlesy (i ) + = vely (i )
%Pic.Draw (particlePicture, particlesx(i), particlesy(i), picCopy)
drawfilloval (particlesx (i ), particlesy (i ), radius+ 1, radius+ 1, outsideColor )
drawfilloval (particlesx (i ), particlesy (i ), radius, radius, circleColor )
end for
end reDraw
proc Calc
for i : 1 .. totalParticles
if velx (i ) < - 25 then
velx (i ) := - 25
end if
if vely (i ) < - 25 then
vely (i ) := - 25
end if
vely (i ) - = Gravity
end for
end Calc
proc Return
for i : 1 .. totalParticles
if particlesx (i ) < x then
velx (i ) + = Rand.Int (1, 5)
end if
if particlesx (i ) > x then
velx (i ) - = Rand.Int (1, 5)
end if
if particlesy (i ) < y then
vely (i ) + = Rand.Int (1, 5)
end if
if particlesy (i ) > y then
vely (i ) - = Rand.Int (1, 5)
end if
/*if particlesy (i) = y then
vely (i) += Rand.Int (-5, 5)
elsif particlesx (i) = x then
velx (i) += Rand.Int (-5, 5)
end if*/
end for
end Return
proc Rebound
for i : 1 .. totalParticles
if particlesx (i ) <= 0 or particlesx (i ) >= maxx then
velx (i ) := round (-velx (i ) div 1. 2)
vely (i ) := round (-vely (i ) div 1. 2)
end if
if particlesy (i ) <= 0 or particlesy (i ) >= maxy then
velx (i ) := round (-velx (i ) div 1. 2)
vely (i ) := round (-vely (i ) div 1. 2)
end if
end for
end Rebound
loop
reDraw
Calc
colorback (255)
Mouse.Where (x, y, button )
Input.KeyDown (keys )
if keys (' ') then
Return
end if
if keys (KEY_UP_ARROW) then
reBound := false
end if
if keys (KEY_DOWN_ARROW) then
reBound := true
end if
if reBound = true then
Rebound
end if
if button = 1 then
totalParticles + = 1
new particlesx, totalParticles
new particlesy, totalParticles
new velx, totalParticles
new vely, totalParticles
particlesy (totalParticles ) := y
particlesx (totalParticles ) := x
velx (totalParticles ) := Rand.Int (- 5, 15)
vely (totalParticles ) := Rand.Int (- 5, 15)
end if
View.Update
delay (delayTime )
cls
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|