So today I was trying to make a circle in CC.
I googled a bit and understood, I had to use math.cos and math.sin.
Well I'm still lost :P/>
If someone could explain me, that would be awsome!
Thanks!
--# sX = x position, sY = y position, sR = radius
function circle(sX,sY,sR)
local radius = math.pi * sR
for i = 1, 360 do
local x = math.sin(radius*i)
local y = math.cos(radius*i)
term.setCursorPos(sX+x,sY+y)
term.write(" ")
end
end
Maybe it's wrong, idk
function circleRender(x1,x2,y1,y2,color)
if not (x1 and x2 and y1 and y2) then
return
end
local x = {
max = math.max(x1,x2), --right most x
min = math.min(x1,x2) --left most x
}
x.rad = math.floor(x.max-x.min)/2 --radius
x.center = x.rad+x.min --circle x-axis center
local y = {
max = math.max(y1,y2), --bottom y
min = math.min(y1,y2) --top y
}
y.rad = (y.max-y.min)/2
y.center = y.rad+y.min --circle y-axis center
local thetha = 0
local tPoints = {}
while thetha <= 360 do
local xP = math.floor(x.center+x.rad*math.cos(thetha)) --calculate x point
local yP = math.floor(y.center+y.rad*math.sin(thetha)) --calculate y point
tPoints[xP] = tPoints[xP] or {} --countine existing x-axis or create new one
tPoints[xP][yP] = true -- mark point on y axis along x axis
thetha = thetha+1
end
for x,yT in pairs(tPoints) do
for y in pairs(yT) do
if y <= canvasEdge then
paintutils.drawPixel(x,y,color)
end
end
end
end
function drawCircle( centerX, centerY, radius, color )
local isAdvanced = term.isColor and term.isColor()
local char = isAdvanced and " " or "|"
if isAdvanced then term.setBackgroundColor( color ) end
local radStep = 1/(1.5*radius)
for angle = 1, math.pi+radStep, radStep do
local pX = math.cos( angle ) * radius * 1.5
local pY = math.sin( angle ) * radius
for i=-1,1,2 do
for j=-1,1,2 do
term.setCursorPos( centerX + i*pX, centerY + j*pY )
write( char )
end
end
end
end
here's one I've thrown together in the past (slightly different version is also in my thread)function drawCircle( centerX, centerY, radius, color ) local isAdvanced = term.isColor and term.isColor() local char = isAdvanced and " " or "|" if isAdvanced then term.setBackgroundColor( color ) end local radStep = 1/(1.5*radius) for angle = 1, math.pi+radStep, radStep do local pX = math.cos( angle ) * radius * 1.5 local pY = math.sin( angle ) * radius for i=-1,1,2 do for j=-1,1,2 do term.setCursorPos( centerX + i*pX, centerY + j*pY ) write( char ) end end end end
it also supports non-advanced computers by having a char that it can print instead of colours.