Just touch the screen.
--# Main
-- Particles
particle = {}
nParticles = 2000
gemScale = .2
function setup()
gemMesh = mesh()
gemMesh.texture = "Planet Cute:Gem Blue"
w,h = spriteSize(gemMesh.texture)
w = w * gemScale
h = h * gemScale
for i=1, nParticles do
particle[i] = Particle()
end
end
function draw()
background(40, 40, 50)
strokeWidth(2)
for i=1, nParticles do
particle[i]:draw(i)
end
gemMesh:draw()
end
function touched(touch)
if touch.state == BEGAN or touch.state == MOVING then
touching = true
fingerPos = vec2(touch.x,touch.y)
else
touching = false
end
end
--# Particle
Particle = class()
function Particle:init()
self.pos = vec2(math.random(WIDTH), math.random(HEIGHT))
self.vel = vec2(0,0)
gemMesh:addRect(0,0,0,0)
end
function Particle:draw(i)
if touching then
d = self.pos:dist(fingerPos)
if d < 200 then
self.vel = self.vel + (self.pos-fingerPos):normalize():rotate(math.pi+1) * (200-d) * .003
end
end
self.vel = self.vel * .98
self.pos = self.pos + self.vel
if self.pos.x >= WIDTH or self.pos.x <= 0 then self.vel.x = -self.vel.x end
if self.pos.y >= HEIGHT or self.pos.y <= 0 then self.vel.y = -self.vel.y end
gemMesh:setRect(i,self.pos.x,self.pos.y,w,h)
end