Spent the last two and half hours. Trying to make a heart. But it feels broken.
ORIGINALLY: There’s something wrong with the way I convert points into vertices at the end of the fheart function. I haven’t figured how to fix this.
NOW: I fixed it. But it still looks really ugly.
NEW CODE: still looks bad. Please observe the changes I made, all in this section of the code.
x = 0 -- was x = w/2
for i = 1,16 do
local angle = math.pi / 15 * i
local ptx, pty = x + r * math.cos( angle ), y + r * math.sin( angle )
table.insert ( verts, vec2(ptx, pty) )
end
-- convert points into triangles for mesh
local tri = {}
local center = vec2( w* .5, 0) -- was vec2(w* .75, 0)
for i,v in ipairs(verts) do
table.insert(tri, v)
if i % 2 then
table.insert(tri, center)
table.insert(tri, verts[i+1]) -- was totally broken before
end
end
BELOW: OLD CODE. It was probably worse
-- Heartis
function heart (w,h)
local r = w/2
local verts = {}
local a = 0
local x, y = w, h / 2
for i = 1,16 do
local angle = math.pi / 15 * i
local ptx, pty = x + r * math.cos( angle ), y + r * math.sin( angle )
table.insert ( verts, vec2(ptx, pty) )
end
x = w / 2
for i = 1,16 do
local angle = math.pi / 15 * i
local ptx, pty = x + r * math.cos( angle ), y + r * math.sin( angle )
table.insert ( verts, vec2(ptx, pty) )
end
-- convert points into triangles for mesh
local tri = {}
local center = vec2( w* .75, 0)
for i,v in ipairs(verts) do
table.insert(tri, v)
if i %2 == 0 then
table.insert(tri, center)
table.insert(tri, v)
end
end
return tri
end
function setup()
a=mesh()
a.vertices=heart(100,100)
a:setColors(255,0,0)
end
function draw()
background(40, 40, 50)
strokeWidth(5)
translate(490,480)
a:draw()
end