surface.DrawLine

From GMod Wiki

Jump to: navigation, search
Function
Syntax surface.DrawLine( Number StartPos x, Number StartPos y, Number EndPos x, Number EndPos y )
Where is this used?
Description:
Draws a line from the Startpos to the Endpos on the screen.
Returns: nil
Part of Library: surface
Realm: NewerClient.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Surface.DrawLine]Surface.DrawLine [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]


Examples

DescriptionThis example will draw a crosshair in the center of the screen.
Used onNewerClient.png
Code
 
--gets the center of the screen
local x = ScrW() / 2
local y = ScrH() / 2
 
--set the drawcolor
surface.SetDrawColor( 0, 255, 0, 255 )
 
local gap = 5
local length = gap + 15
 
--draw the crosshair
surface.DrawLine( x - length, y, x - gap, y )
surface.DrawLine( x + length, y, x + gap, y )
surface.DrawLine( x, y - length, x, y - gap )
surface.DrawLine( x, y + length, x, y + gap )
 
OutputDraws a crosshair.


DescriptionThis example will draw a pixel perfect circle.
Used onNewerClient.png
Code
 
hook.Add( "HUDPaint", "Circle", function()
	local center = Vector( ScrW() / 2, ScrH() / 2, 0 )
	local scale = Vector( 100, 100, 0 )
	local segmentdist = 360 / ( 2 * math.pi * math.max( scale.x, scale.y ) / 2 )
	surface.SetDrawColor( 255, 0, 0, 255 )
 
	for a = 0, 360 - segmentdist, segmentdist do
		surface.DrawLine( center.x + math.cos( math.rad( a ) ) * scale.x, center.y - math.sin( math.rad( a ) ) * scale.y, center.x + math.cos( math.rad( a + segmentdist ) ) * scale.x, center.y - math.sin( math.rad( a + segmentdist ) ) * scale.y )
	end
end )
 
OutputDraws a pixel perfect circle on the screen.
Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox