# Creating a circle with sections, help needed!

Hi,

I have googled around a little but haven’t found anything related to this topic. Is it possible to create a circle object with sections like in the picture attached? (without the black borders)

I’m trying to achieve this programmatically so the color’s can change when a certain event happens in the game, and I also want to be able to check if another object is on top of a section. I’m quite new to Solar2D so I’m not sure if this is possible, but any help or tips are appreciated!

There are a couple ways.

The easiest would probably be to create 4 rectangles, place them like in the image above, and then apply a circular mask to each of them and move each rect’s mask to their shared corner.

1 Like

With polygons you could also approximate these sections. (A circle is actually doing this anyway.)

``````local R = 200

local points = { 0, 0, R, 0 }

for i = 1, 20 do
local angle = (math.pi / 2) * i / 20

points[#points + 1] = R * math.cos(angle)
points[#points + 1] = R * math.sin(angle)
end

local function MakeSection (rotation, r, g, b)
local p = display.newPolygon(0, 0, points)

p.anchorX, p.x = 0, display.contentCenterX
p.anchorY, p.y = 0, display.contentCenterY
p.rotation = rotation

p:setFillColor(r, g, b)
end

MakeSection(0, 0, 1, 0)
MakeSection(90, 1, 1, 0)
MakeSection(180, 1, 0, 0)
MakeSection(270, 0, 0, 1)
``````
2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.