Pixilated circle

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: Pixilated circle

Post by darkfrei »

How to make it without canvas?

Code: Select all

function love.draw()
	love.graphics.scale(20) -- really huge scale
	love.graphics.setDefaultFilter( 'nearest', 'nearest' )
	love.graphics.setLineStyle( "rough" )
	
	love.graphics.circle('line', width/2, height/2, height/2)
end
Expected: pixelated circle as above, got: almost smooth line.
Attachments
2021-07-29T21_43_04-Untitled.png
2021-07-29T21_43_04-Untitled.png (9.09 KiB) Viewed 3086 times
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
RNavega
Party member
Posts: 239
Joined: Sun Aug 16, 2020 1:28 pm

Re: Pixilated circle

Post by RNavega »

@darkfrei The canvas in that case is the one used by the window. If you don't / can't afford to use a Canvas object, then you need to manually plot the "pixels" of the circle using huge square rectangles, with the coordinates themselves scaled so that each circle pixel involves huge steps of screen pixels.

There's some sample code in here, but without this special scaled treatment I said above:
https://rosettacode.org/wiki/Bitmap/Mid ... orithm#Lua
Yozzaxia
Prole
Posts: 10
Joined: Fri Jul 16, 2021 3:36 pm

Re: Pixilated circle

Post by Yozzaxia »

If you're using the midpoint circle func mentioned above, I suggest using love.graphics.points:

Code: Select all

function drawPixelCircle(x, y, radius, pixelsize)
  local points = {}
  local dx, dy, err = math.floor(radius / pixelsize), 0, 1-math.floor(radius / pixelsize)
  
  while dx >= dy do
    local pdx, pdy = dx * pixelsize, dy * pixelsize
    points[#points + 1] = pdx
    points[#points + 1] = pdy
    points[#points + 1] = -pdx
    points[#points + 1] = pdy
    points[#points + 1] = pdx
    points[#points + 1] = -pdy
    points[#points + 1] = -pdx
    points[#points + 1] = -pdy
    points[#points + 1] = pdy
    points[#points + 1] = pdx
    points[#points + 1] = -pdy
    points[#points + 1] = pdx
    points[#points + 1] = pdy
    points[#points + 1] = -pdx
    points[#points + 1] = -pdy
    points[#points + 1] = -pdx
    
    dy = dy + 1
    if err < 0 then
      err = err + 2 * dy + 1
    else
      dx, err = dx-1, err + 2 * (dy - dx) + 1
    end
  end
  
  love.graphics.setPointSize(pixelsize)
  love.graphics.push()
  love.graphics.translate(x, y)
  love.graphics.points(points)
  love.graphics.pop()
end
RNavega
Party member
Posts: 239
Joined: Sun Aug 16, 2020 1:28 pm

Re: Pixilated circle

Post by RNavega »

@Yozzaxia I hadn't thought of drawing using thick points. Nice code!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], dusoft and 38 guests