Skip to content

Commit

Permalink
Add acceleration param (out of 100)
Browse files Browse the repository at this point in the history
  • Loading branch information
schrockwell committed Aug 26, 2023
1 parent 07e67ea commit 8b16f73
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pdParticles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function Particle:init(x, y)
self.size = {1,1}
self.spread = {0,359}
self.speed = {1,1}
self.acceleration = {0, 0}
self.thickness = {0,0}
self.lifespan = {1,1}
self.decay = 1
Expand Down Expand Up @@ -93,6 +94,15 @@ function Particle:getSpeed()
return self.speed[1], self.speed[2]
end

-- acceleration
function Particle:setAcceleration(min,max)
self.acceleration = {min, max or min}
end

function Particle:getAcceleration()
return self.acceleration[1], self.acceleration[2]
end

-- thickness
function Particle:setThickness(min, max)
self.thickness = {min, max or min}
Expand Down Expand Up @@ -237,6 +247,7 @@ function ParticleCircle:create(amount)
dir = math.random(self.spread[1],self.spread[2]),
size = math.random(self.size[1],self.size[2]) * precision,
speed = math.random(self.speed[1],self.speed[2]) * precision,
acceleration = math.random(self.acceleration[1],self.acceleration[2]) * precision,
lifespan = math.random(self.lifespan[1],self.lifespan[2]) * precision,
thickness = math.random(self.thickness[1],self.thickness[2]),
decay = self.decay
Expand Down Expand Up @@ -265,6 +276,8 @@ function ParticleCircle:update()

circ.x += math.sin(math.rad(circ.dir)) * circ.speed
circ.y -= math.cos(math.rad(circ.dir)) * circ.speed

circ.speed += circ.acceleration / 100

self.particles[part] = circ
end
Expand Down Expand Up @@ -320,6 +333,7 @@ function ParticlePoly:create(amount)
dir = math.random(self.spread[1],self.spread[2]),
size = math.random(self.size[1],self.size[2]) * precision,
speed = math.random(self.speed[1],self.speed[2]) * precision,
acceleration = math.random(self.acceleration[1],self.acceleration[2]) * precision,
lifespan = math.random(self.lifespan[1],self.lifespan[2]) * precision,
thickness = math.random(self.thickness[1],self.thickness[2]) * precision,
angular = math.random(self.angular[1],self.angular[2]) * precision,
Expand Down Expand Up @@ -359,6 +373,8 @@ function ParticlePoly:update()
poly.y = poly.y - math.cos(math.rad(poly.dir)) * poly.speed

poly.rotation += poly.angular

poly.speed += poly.acceleration / 100

self.particles[part] = poly
end
Expand Down Expand Up @@ -425,6 +441,7 @@ function ParticleImage:create(amount)
dir = math.random(self.spread[1],self.spread[2]),
size = math.random(self.size[1],self.size[2]) * precision,
speed = math.random(self.speed[1],self.speed[2]) * precision,
acceleration = math.random(self.acceleration[1],self.acceleration[2]) * precision,
lifespan = math.random(self.lifespan[1],self.lifespan[2]) * precision,
thickness = math.random(self.thickness[1],self.thickness[2]),
angular = math.random(self.angular[1],self.angular[2]) * precision,
Expand All @@ -443,6 +460,7 @@ function ParticleImage:create(amount)
dir = math.random(self.spread[1],self.spread[2]),
size = math.random(self.size[1],self.size[2]) * precision,
speed = math.random(self.speed[1],self.speed[2]) * precision,
acceleration = math.random(self.acceleration[1],self.acceleration[2]) * precision,
lifespan = math.random(self.lifespan[1],self.lifespan[2]) * precision,
thickness = math.random(self.thickness[1],self.thickness[2]),
angular = math.random(self.angular[1],self.angular[2]) * precision,
Expand Down Expand Up @@ -470,6 +488,8 @@ function ParticleImage:update()

img.x += math.sin(math.rad(img.dir)) * img.speed
img.y = img.y - math.cos(math.rad(img.dir)) * img.speed

img.speed += img.acceleration / 100

self.particles[part] = img
end
Expand Down Expand Up @@ -502,6 +522,8 @@ function ParticleImageBasic:update()
img.x += math.sin(math.rad(img.dir)) * img.speed
img.y = img.y - math.cos(math.rad(img.dir)) * img.speed

img.speed += img.acceleration / 100

self.particles[part] = img
end

Expand Down Expand Up @@ -529,6 +551,7 @@ function ParticlePixel:create(amount)
y = self.y,
dir = math.random(self.spread[1],self.spread[2]),
speed = math.random(self.speed[1],self.speed[2]) * precision,
acceleration = math.random(self.acceleration[1],self.acceleration[2]) * precision,
lifespan = math.random(self.lifespan[1],self.lifespan[2]) * precision,
}

Expand All @@ -550,6 +573,8 @@ function ParticlePixel:update()

pix.x += math.sin(math.rad(pix.dir)) * pix.speed
pix.y -= math.cos(math.rad(pix.dir)) * pix.speed

pix.speed += pix.acceleration / 100

self.particles[part] = pix
end
Expand Down

0 comments on commit 8b16f73

Please sign in to comment.