Page 2 of 2
Re: Pixilated circle
Posted: Thu Jul 29, 2021 7:44 pm
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.
Re: Pixilated circle
Posted: Thu Jul 29, 2021 9:50 pm
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
Re: Pixilated circle
Posted: Fri Jul 30, 2021 5:57 pm
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
Re: Pixilated circle
Posted: Fri Jul 30, 2021 6:11 pm
by RNavega
@Yozzaxia I hadn't thought of drawing using thick points. Nice code!