Hexagonal mesh

self.m = mesh()

local t = {}

for a = 0, 360, 60  do
    table.insert(t, vec2(self.size * math.cos(math.rad(a)), self.size * math.sin(math.rad(a))))
self.m.vertices = t

First of all Thanks for reading…So I’ve got some hexagons…currently I’m drawing several lines connecting to eachother…buuuut that’s lame.

So I’m trying to make a mesh to give me control over filling the interior of the hexagon. My battle plan was above. Go counter clockwise 60,120,180,249,300,360 degrees and use that as my mesh vertices. And it worked…sort of…But there’s a problem: there a perfectly rhombuscular patch of while left out of the mesh for some unknown reason…

What are I doing wrong?

You need to create triangles, ie your vertices need to be ordered so that each set of three vertices make a triangle. Typically, you will make a triangle between each side of the haxeagon, and the centre.

But Codea has a handy triangulate function that I haven’t used but may do this for you. Try using that on your table t and see if it helps.

If not, you need to change your code to something like this (untested)

local t1 = {}

for a = 0, 360, 60  do --calculate points round circle
    table.insert(t1, vec2(self.size * math.cos(math.rad(a)), self.size * math.sin(math.rad(a))))

--calculate triangles
for i=1,#t-1 do

self.m.vertices = t2

A very simple polygon class takes a series of vec2s and makes a mesh using triangulate:

function setup()
    fill(0, 97, 255, 255)
    poly=polygon (vec2(50,50), vec2(100,50), vec2(200,100), vec2(50, 200))

function draw()
    background(27, 27, 54, 255)

function polygon(...)
    local m=mesh()
    return m

@Ignatz As @yojimbo2000 recommended, why not just use triangulate(vertices) ?

I think you’ll find I said that, but I thought he might want to understand what was needed

@Ignatz Sorry, I missed that.