This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
TheManFish's profile picture

how do i draw ellipses?

Started by TheManFish, 15 April 2015 - 08:28 PM
TheManFish #1
Posted 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?
Creator #2
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 ;)/>
Dog #3
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.
flaghacker #4
Posted 16 April 2015 - 08:59 PM

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.
CrazedProgrammer #5
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
Edited on 16 April 2015 - 07:02 PM
Creator #6
Posted 16 April 2015 - 09:00 PM
Yeah, so you should multiply y axis by 0.(6) which is 2/3 0r 0.666666….
CrazedProgrammer #7
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
flaghacker #8
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…
CrazedProgrammer #9
Posted 16 April 2015 - 09:05 PM

	  if x*x*height*height+y*y*width*width <= height*height*width*width then

Lua has a ^ (power) operator…
I converted the code from this page to lua and I didn't think of that, but it works :P/>
Edited on 16 April 2015 - 07:05 PM