After looking for a solution to glowing lines I thought about it for a while and came up with this, I think its suitable but could be improved on the glow width and such else, tell me what you think!
Just draw on the screen with different colours and watch the rest happen, I’m glad Codea has blend modes now. Not that it didn’t before
--# Main
function setup()
screen = image(WIDTH,HEIGHT)
parameter.color("colour",color(200,255,0,255))
parameter.integer("width",5,100)
parameter.action("clear",function() screen = image(WIDTH,HEIGHT) end)
cap = image(100,100)
setContext(cap)
pushStyle()
local mp = 255/100
for i=1,300 do
fill(255,255,255,1)
ellipse(50,50,i/3)
end
popStyle()
setContext()
end
function draw()
background(255)
sprite(screen,WIDTH/2,HEIGHT/2)
end
function touched(t)
if t.state == MOVING then
setContext(screen)
Glow(vec2(t.prevX,t.prevY),vec2(t.x,t.y),width,colour):draw()
setContext()
end
if t.state == ENDED then
setContext(screen)
Glow(vec2(t.prevX,t.prevY),vec2(t.x,t.y),width,colour):draw()
setContext()
end
end
--# Glow
Glow = class()
function Glow:init(pos1,pos2,width,colour)
self.pos1 = pos1
self.pos2 = pos2
self.dist = pos2:dist(pos1)
self.width = width*2
self.col = colour
self.m = mesh()
self.m.texture = cap
self.r = self.m:addRect(pos1.x,pos1.y,self.width,self.width)
self.m:setColors(colour.r,colour.g,colour.b,200/(self.width/13))
end
function Glow:draw()
local col = self.col
local p1,p2 = self.pos1,self.pos2
local width = self.width
local mp = 255/width
pushStyle()
for i=1,self.dist do
local dp = (p2-p1)/self.dist
self.m:setRect(self.r,p1.x+dp.x*i,p1.y+dp.y*i,self.width,self.width)
blendMode(ADDITIVE)
self.m:draw()
end
--[[fill(col.r,col.g,col.b,255)
ellipse(p1.x,p1.y,self.width/5+1.5)
ellipse(p2.x,p2.y,self.width/5+1.5)
strokeWidth(self.width/5)
stroke(col.r,col.g,col.b,255)
line(p1.x,p1.y,p2.x,p2.y)]]
blendMode(NORMAL)
popStyle()
end
function Glow:touched(touch)
-- Codea does not automatically call this method
end