How draw a line
How draw a line
Hey guys, so I want to do a function that connects two points, I have a point already defined and a point b that is defined when I click on the screen, I need to draw circles from a to b, can somone help me ?
- Sir_Silver
- Party member
- Posts: 286
- Joined: Mon Aug 22, 2016 2:25 pm
- Contact:
Re: How draw a line
When you say draw circles from a to b, do you mean you should draw one circle, where the center of the circle is point a and the edge of the circle is point b?
Re: How draw a line
Something like this?"I need to draw circles from a to b"
Code: Select all
function drawCircles( p1, p2, dia )
local sn = p2.x < p1.x and -1 or 1
local an = math.tan( (p2.y-p1.y) / (p2.x-p1.x) )
for x = p1.x, p2.x, 2*sn*dia do
y = sn * x * math.atan( an ) + p1.y
love.graphics.circle( 'line', x, y, dia )
end
end
Re: How draw a line
i need draw little circles, like points in a cartesian plane.Sir_Silver wrote:When you say draw circles from a to b, do you mean you should draw one circle, where the center of the circle is point a and the edge of the circle is point b?
Re: How draw a line
Ref wrote:Something like this?"I need to draw circles from a to b"Code: Select all
function drawCircles( p1, p2, dia ) local sn = p2.x < p1.x and -1 or 1 local an = math.tan( (p2.y-p1.y) / (p2.x-p1.x) ) for x = p1.x, p2.x, 2*sn*dia do y = sn * x * math.atan( an ) + p1.y love.graphics.circle( 'line', x, y, dia ) end end
i will test
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How draw a line
>Draw a line
>Draw circles
>Draw points
[wiki]love.graphics.line[/wiki]
[wiki]love.graphics.circle[/wiki]
[wiki]love.graphics.points[/wiki]
You know, in case you're overcomplicating things
>Draw circles
>Draw points
[wiki]love.graphics.line[/wiki]
[wiki]love.graphics.circle[/wiki]
[wiki]love.graphics.points[/wiki]
You know, in case you're overcomplicating things
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
- Sir_Silver
- Party member
- Posts: 286
- Joined: Mon Aug 22, 2016 2:25 pm
- Contact:
Re: How draw a line
I'm pretty sure this isn't going to be exactly what you wanted, but maybe you can gather something from it. It is a "Cartesian Plane" where you can press lmb and start dragging, then release to create two points connected by a line.
If you just want to see the code without downloading:
If you just want to see the code without downloading:
Code: Select all
local start_x, start_y
local draw_line = false
function love.load()
love.window.setMode(600, 600)
love.graphics.setBackgroundColor(255, 255, 255)
background = love.graphics.newCanvas()
love.graphics.setCanvas(background)
for y = 0, 600 / 50 do
for x = 0, 600 / 50 do
love.graphics.setColor(0, 0, 0)
love.graphics.setLineWidth(y == math.floor(600 / 50 / 2) and 2 or 1)
love.graphics.line(0, y * 50, 600, y * 50)
love.graphics.setLineWidth(x == math.floor(600 / 50 / 2) and 2 or 1)
love.graphics.line(x * 50, 0, x * 50, 600)
end
end
love.graphics.setCanvas()
end
function love.update(dt)
if love.mouse.isDown(1) then
if start_x and start_y then
draw_line = true
end
else
draw_line = false
end
end
function love.draw()
love.graphics.setColor(255, 255, 255)
love.graphics.draw(background)
if draw_line then
local end_x, end_y = love.mouse.getPosition()
love.graphics.setColor(0, 0, 0)
love.graphics.circle("fill", end_x, end_y, 5)
love.graphics.line(start_x, start_y, end_x, end_y)
end
end
function love.mousepressed(x, y, button)
if button == 1 then
love.graphics.setCanvas(background)
love.graphics.setColor(0, 0, 0)
love.graphics.circle("fill", x, y, 5)
love.graphics.setCanvas()
start_x, start_y = x, y
end
end
function love.mousereleased(x, y, button)
if button == 1 then
love.graphics.setCanvas(background)
love.graphics.setColor(0, 0, 0)
love.graphics.circle("fill", x, y, 5)
love.graphics.line(start_x, start_y, x, y)
love.graphics.setCanvas()
start_x, start_y = nil, nil
end
end
Re: How draw a line
....
It is important that read wiki two times.
Though I know it is hard to do.
It is important that read wiki two times.
Though I know it is hard to do.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests