Ive just created a class and its saying its a global nil value, im trying to drawing quadratic splines for an app, heres the code:
Brushb = class()
function Brushb:init(x,y,width,col)
self.col = col
self.alpha = col.a
self.width = width
self.points = {vec2(x,y)}
self.curves = {}
self.id = 1
end
function Brushb:addPoints(p)
self.id = self.id + 1
table.insert(self.points,p)
local sp = self.points
local si = self.id
if (self.id%3) == 1 then
local tempc = {}
local t = 0
for i=1,5 do
t = t + 0.2
table.insert(self.curves,((1 – t)^2)*sp[si-2] + 2*(1 – t)*t*sp[si-1] + (t^2)*sp[si])
end
end
end
function Brushb:drawPoints()
local sc = self.curves
local sp = self.points
for i=2,#sc do
local sci = sc[i]
local sci2 = sc[i-1]
Line(sci,sci2,self.width,color(self.col.r,self.col.g,self.col.b,self.alpha):draw()
end
if #sp > #sc then
for i=1,#sp-#sc do
local spi = sp[#sc+i]
local spi2 = sp[#sc+i-1]
Line(spi,spi2,self.width,color(self.col.r,self.col.g,self.col.b,self.alpha):draw()
end
end
end
function Brushb:draw()
end
function Brushb:touched(touch)
-- Codea does not automatically call this method
end
Im not getting it if I just type in,
brush = Brushb(t.x,t.y,color(50,50,50,255),5)
then I get given the error that global ‘Brushb’ is a nil value.