Arcs... AND MORE!

Hi guys! I just learnt about basic trigonometry, and couldn’t resist playing around with it, and viola! Here is an experiment with arcs, trigonometry, and creating a “clean” function. (I have a circle feature in here, but it is incomplete, so I removed it)

-- Upgrade Codea



local mt = {}

function mt:__call(...)
    self:call(...)
end

function mt:__newindex()
    return
end

arc = {}

arc.mesh = mesh()

arc.points = {}

function arc:call(x, y, r, s, e)
    self.mesh:clear()
    self.points = {}
    self.points[1] = vec2(0, 0)
    for i = s, e, 3  do
        i = i / 180 * math.pi
        table.insert(self.points, 1, vec2(math.cos(i), math.sin(i)))
    end
    self.mesh.vertices = triangulate(self.points)
    pushMatrix()
        translate(x, y)
        scale(r)
        self.mesh:draw()
    popMatrix()
end
    

setmetatable(arc, mt)

-- Use this function to perform your initial setup
function setup()
    watch("dt")
end

-- This function gets called once every frame
function draw()
    dt = 1/DeltaTime
    background(255, 255, 255, 255)
    fill(255, 0, 0, 255)
    arc(WIDTH / 2, HEIGHT / 2, 200, 0, 60)
    fill(6, 255, 0, 255)
    arc(WIDTH / 2, HEIGHT / 2, 200, 60, 180)
    fill(0, 0, 255, 255)
    arc(WIDTH / 2, HEIGHT / 2, 200, 180, 360)
end



P.S.
The frame rate drops to 15 or so when using arc with about 270 to 360 degrees, as it creates the mesh every frame (my circle function is MUCH faster, as it just reuses the same mesh, but scales it, I guess I could cache the meshes, but that sounds like a big deal, so maybe later)

And the rest of the code …

Today trigonometry, tomorrow … calculus!

Oh wait. Forgot to post both tabs :slight_smile: Edited now