I wrote this as a mesh example for @bee, but it’s a pretty handy class so I decided to give it its own thread. It just generates a star mesh. Setting up texture coordinates is left as an exercise for the reader.
Edit: Because it’s a mesh you can very easily do things like set the colour of the central vertices, giving it a gradient look:
Main
-- Main function setup() iparameter( "NumPoints", 2, 20, 5 ) parameter( "InnerRadius", 30, 300, 100 ) parameter( "OuterRadius", 100, 300, 200 ) end function draw() -- Normally we'd only create the star once -- This lets us parameterise it for the sake of explanation star = StarMesh( NumPoints, InnerRadius, OuterRadius ) star.position = vec2(WIDTH/2,HEIGHT/2) -- This sets a dark background color background(40, 40, 50) -- Do your drawing here star:draw() end ``` **StarMesh**StarMesh = class() function StarMesh:init(numPoints, outerRad, innerRad) self.mesh = mesh() self.color = color(241, 208, 20, 255) self.position = vec2(0,0) -- Convenience innerRad = innerRad or outerRad * 0.5 local tris = {} local totalPoints = numPoints*2 for i=1,totalPoints do local i1 = i-1 local i2 = i local r1 = i1/totalPoints * math.pi * 2 local r2 = i2/totalPoints * math.pi * 2 local p1 = vec2( math.cos(r1), math.sin(r1) ) local p2 = vec2( math.cos(r2), math.sin(r2) ) local rad1, rad2 if i1%2 == 0 then rad1 = outerRad rad2 = innerRad else rad1 = innerRad rad2 = outerRad end table.insert( tris, p1 * rad1 ) table.insert( tris, p2 * rad2 ) table.insert( tris, vec2(0,0) ) -- center end self.mesh.vertices = tris end function StarMesh:draw() pushStyle() pushMatrix() translate(self.position.x,self.position.y) fill(self.color) self.mesh:draw() popMatrix() popStyle() end ```