-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample_-_additive flame animation.lua
More file actions
80 lines (67 loc) · 1.78 KB
/
Example_-_additive flame animation.lua
File metadata and controls
80 lines (67 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
-- Blendmode additive flame effect
par = class()
maxpars = 100
pars = {}
function par:init(position,active)
self.active = active
self.time = 100
self.position = position
self.move = vec2(0,math.random())
self.scale = math.random()
end
function par:update()
if self.active==false then return end
self.position = self.position + self.move
self.time = self.time - 1
self.scale = self.scale - .02
if self.time<0 or self.scale < .1 then self.active=false end
end
function par:draw()
if self.active==false then return end
local s = 1/100*self.time
pushMatrix()
translate(self.position.x,self.position.y)
scale(self.scale,self.scale)
sprite(im,0,0)
popMatrix()
end
-- Use this function to perform your initial setup
function setup()
print("Hello World!")
im = image(64,64)
setContext(im)
fill(255, 26, 0)
ellipse(32,32,32,32)
for i=0,maxpars do
pars[i] = par(vec2(200,200),false)
end
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
-- This sets the line thickness
strokeWidth(5)
blendMode(ADDITIVE)
if math.random()<1 then
local con=false
for i,v in pairs(pars) do
if v.active==false then
v.active=true
v.time = 100
v.scale = math.random()/2+.5
v.move = vec2(0,math.random()+1)
v.position.y=200
con=true
end
if con==true then
break
end
end
end
for i,v in pairs(pars) do
v:update()
v:draw()
end
-- Do your drawing here
end