Team Spartan Cookies & Milk Forums
E2 egp hexagon - Printable Version

+- Team Spartan Cookies & Milk Forums (https://teamscm.co.uk)
+-- Forum: Garry's Mod (https://teamscm.co.uk/forum-4.html)
+--- Forum: Expression 2 (https://teamscm.co.uk/forum-6.html)
+--- Thread: E2 egp hexagon (/thread-718.html)



E2 egp hexagon - Skyteks - 04-02-2015

Hey guys,
i need a function for e2 where i can enter a radius, x and y coord. to produce a hexagon with all sides same size.
My idea was afunction that gives me 6 coordiantes which i can connect then.
If someone could help me out here? Huh


RE: E2 egp hexagon - TheOneAndOnlyTee - 05-02-2015

this should work but i haven't tested it and is probably wrong since i did this off the top of my head

just mess around with the EdgeOffset, anything between 1 and 0 should work how you want it to, i'd start by testing 0.50

X and Y are obvious
XSize and YSize control the width,height from the center
The offset controls how far point 1,3 is from 2 and 4,6 from 5.


Code:
function void wirelink:egpHex( Index , X , Y , XSize , YSize , EdgeOffset ) { Pos[1,vec2] = vec2(X-XSize,Y) Pos[2,vec2] = vec2(X-(XSize*EdgeOffset),Y+YSize) Pos[3,vec2] = vec2(X+(XSize*EdgeOffset),Y+YSize) Pos[4,vec2] = vec2(X+XSize,Y) Pos[5,vec2] = vec2(X+(XSize*EdgeOffset),Y-YSize) Pos[6,vec2] = vec2(X-(XSize*EdgeOffset),Y-YSize) Screen:egpPoly(Index, Pos) } function void wirelink:egpHexOutline( Index , X , Y , XSize , YSize , EdgeOffset ) { Pos[1,vec2] = vec2(X-(XSize*EdgeOffset),Y-YSize) Pos[2,vec2] = vec2(X-XSize,Y) Pos[3,vec2] = vec2(X-(XSize*EdgeOffset),Y+YSize) Pos[4,vec2] = vec2(X+(XSize*EdgeOffset),Y+YSize) Pos[5,vec2] = vec2(X+XSize,Y) Pos[6,vec2] = vec2(X+(XSize*EdgeOffset),Y-YSize) Screen:egpPolyOutline(Index, Pos) } Example: EGP:egpHex(1, 256, 256, 50, 20, 0.50 ) That would create it in the center of the screen with a size of 100,40. The offset controls how far point 1,3 is from 2 and 4,6 from 5.

   
just a visualization on how the sizing works and the point positions if i didn't screw the function up