Draw polygons on GUI - free script & demo

Hello Guys,

Today I’ve written a little script and I just want to share it with you :slight_smile:

The story in short: today I’ve tried to find a script on on the web to make freehand polygons on Roblox GUI (sg like in Godot).

I had no luck, so I wrote one to myself…

I plan to make it more flexible in the weekend, e.g. enabling filled shapes and to create a shape as one object and to move, resize them etc. That probably will be a paid solution for some Robux (will be a more serious work), but the core of the math is free, you can access the demo game with the code here:

This is one single script with 90 lines + 3 GUI objects only, probably the simplest project I’ve ever shared :slight_smile: but I think it can help for some of you too.

image

The function that draws a line between two GUI points (a1 and a2):

function drawCandidate(a1:Vector3,a2:Vector3)	
	local x1:number = (a1.X + a2.X) / 2
	local y1:number = (a1.Y + a2.Y) / 2	
	
	line.Position = UDim2.fromOffset(x1,y1)
	line.Size = UDim2.fromOffset((a2-a1).Magnitude, lineWidth)	
	
	local r = math.deg(-math.asin(CFrame.new(a1,a2).LookVector.X)-math.pi/2)	
	if a2.Y<a1.Y then r = -r end	
	
	line.Rotation = r		
end

(line is a Frame object, anchorpoint set to 0.5,0.5 - see in the demo!)

That’s all, I hope you find it useful!
Check out all of my stuffs, demos, games and plugins :slight_smile:

Have a nice day!

15 Likes