Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Plot() a circle?

    Advanced
    2
    4
    59
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • HeyoMayo
      HeyoMayo last edited by HeyoMayo

      I'm switching from circle() to plot() to have more control over my drawing app, the pixels are just a big array of strings (runs surprisingly better). How do I plot a circle using like

      function makeCircle(x,y,colorID)
         setPixel(x,y,colorID)
         setPixel(x - 1,  y - 0, colorID)
         setPixel(x + 1, y - 0, colorID)
      return void
      

      (this is just a example of how i'm trying to do it)

      I'm also thinking of a system for brushes, so i'm kinda trying to set myself up to be able to do that later. Would be cool of the size was adjustable (maybe a for loop) but that's unnecessary

      vinicity 1 Reply Last reply Reply Quote 0
      • vinicity
        vinicity F @HeyoMayo last edited by vinicity

        @heyomayo If you want to use plot() to draw circles you could do something like:

        function plotCircle(x, y, r, n, colour)
          for t = 0 to n loop
            pos = {x, y} + r * sinCos(360 * t / n)
            plot(pos.x, pos.y, colour)
          repeat
        return void
        

        ...where n is the number of pixels drawn. It's a bit cumbersome since it would depend on the resolution and the size of the circle. A small circle of course needs less pixels and thus a smaller number for n. And r is the radius of the circle.

        In order to get a continuous circle no matter the size, one could use line() instead to connect the points, and n then would mean the number of vertices...

        EDIT: I missed the part where you said you stored the pixels in an array, but it should be the same thing either way using either setPixel() or plot().

        1 Reply Last reply Reply Quote 1
        • vinicity
          vinicity F last edited by vinicity

          In reality, a better approach is probably Bresenham's Circle Algorithm:
          https://en.wikipedia.org/wiki/Midpoint_circle_algorithm

          I also found this post, which seems to indicate that you can set n to 5.657 * r. I haven't tried that myself, but the maths seems to check out.
          https://math.stackexchange.com/questions/167289/determining-the-minimum-number-of-pixels-on-the-boundary-of-a-circle-drawn-in-di

          Then the function would become:

          function plotCircle(x, y, r, colour)
            n =  round(5.657 * r)
            for t = 0 to n loop
              pos = {x, y} + r * sinCos(360 * t / n)
              plot(pos.x, pos.y, colour)
            repeat
          return void
          
          HeyoMayo 1 Reply Last reply Reply Quote 3
          • HeyoMayo
            HeyoMayo @vinicity last edited by

            @vinicity Thank you so much for the function, i'll try it out

            1 Reply Last reply Reply Quote 1
            • First post
              Last post