This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
how do i draw ellipses?
Started by TheManFish, 15 April 2015 - 08:28 PMPosted 15 April 2015 - 10:28 PM
So today i've been trying to draw ellipses with no success. Could someone explain how to do so or link me to where you can find a working example of ellipses?
Posted 16 April 2015 - 08:39 PM
Sofware Rasterization Algorithms for drawing filled triangles
Triangle fillers
Polygon Fill Teaching Tool
Circle and ellipse drawing algorithm - Math Open Reference
Here are some links. I hope they can help you ;)/>
Triangle fillers
Polygon Fill Teaching Tool
Circle and ellipse drawing algorithm - Math Open Reference
Here are some links. I hope they can help you ;)/>
Posted 16 April 2015 - 08:52 PM
Another thing to keep in mind is that CC's pixels aren't square - iirc, their width is roughly 2/3 their height.
Posted 16 April 2015 - 08:59 PM
Sofware Rasterization Algorithms for drawing filled triangles
Triangle fillers
Polygon Fill Teaching Tool
Circle and ellipse drawing algorithm - Math Open Reference
Here are some links. I hope they can help you ;)/>
Your first 3 aren't really relevant, he's trying to draw Ellipses, not triangles.
And if it's for a static image (e.g. a background) you might be better of using the in-game paint and the paintutils.drawImage function. That will probably have a much better performance.
Posted 16 April 2015 - 09:00 PM
You can use the surf:fillEllipse function of my Surface API, but if you want to implement it yourself please look at these pages:
Simple algorithm for drawing filled ellipses - Stack Overflow
Circle and ellipse drawing algorithm - Math Open Reference
Simple algorithm for drawing filled ellipses - Stack Overflow
Circle and ellipse drawing algorithm - Math Open Reference
Edited on 16 April 2015 - 07:02 PM
Posted 16 April 2015 - 09:00 PM
Yeah, so you should multiply y axis by 0.(6) which is 2/3 0r 0.666666….
Posted 16 April 2015 - 09:02 PM
You can use this function which uses the sqrt scanline algorithm:
function fillEllipse(ox, oy, width, height, color)
for y=-height,height,1 do
for x=-width,width,1 do
if x*x*height*height+y*y*width*width <= height*height*width*width then
paintutils.drawPixel(ox+x, oy+y, color)
end
end
end
end
fillEllipse(25, 9, 20, 5, colors.white) -- Draws a big white ellipse at origin (25, 9) with size (20, 5)
Edited on 16 April 2015 - 07:03 PM
Posted 16 April 2015 - 09:03 PM
if x*x*height*height+y*y*width*width <= height*height*width*width then
Lua has a ^ (power) operator…
Posted 16 April 2015 - 09:05 PM
I converted the code from this page to lua and I didn't think of that, but it works :P/>if x*x*height*height+y*y*width*width <= height*height*width*width then
Lua has a ^ (power) operator…
Edited on 16 April 2015 - 07:05 PM