Garry's Mod Wiki

surface.DrawLine

surface.DrawLine( number startX, number startY, number endX, number endY )

Description

Draws a line from one point to another.

This is a rendering function that requires a 2d rendering context.

This means that it will only work in 2d Rendering Hooks.

Arguments

1 number startX
The start x integer coordinate.
2 number startY
The start y integer coordinate.
3 number endX
The end x integer coordinate.
4 number endY
The end y integer coordinate.

Example

This example will draw a pixel perfect circle in the middle of your screen.

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 )

Page Links


Special Pages


Wikis

?

Render Time: 40ms

DB GetPage 4
Generate Html 12
SaveChanges (1) 9
Render Body 0
Render Sidebar 12