Forum

> > CS2D > Scripts > Draw a line from x1,y1 to x2,y2
Forums overviewCS2D overview Scripts overviewLog in to reply

English Draw a line from x1,y1 to x2,y2

4 replies
To the start Previous 1 Next To the start

old Re: Draw a line from x1,y1 to x2,y2

Infinite Rain
Reviewer Off Offline

Quote
1
2
3
4
5
6
7
8
drawLine(path, x1, y1, x2, y2)
	local dir = -math.deg(math.atan2(x1 - x2, y1 - y2))
	local dist = math.sqrt((x1 - x2)^2 + (y1 - y2)^2)
	local x, y = x1 + math.sin(math.rad(dir)) * dist/2, y1 - math.cos(math.rad(dir)) * dist/2
	local img = image(path, x, y, 1)
	imagepos(img, x, y, dir)
	imagescale(img, 1, dist)
end

"path" argument should be a path to the 1x1 pixel image. You can also make line wider by increasing the width (x) of the image.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview