GLBasic forum

Codesnippets => 2D-snippets => Topic started by: Hemlos on 2009-Dec-14

Title: Polygon() Function- Textured, Colored, Rotatable Shapes
Post by: Hemlos on 2009-Dec-14
This is something i whipped up today..

You can texture a circular polyvector with color masks for the center and edge of the circle.
It will blend nicely, and you can animate the colors, instead of animating with multiple textures.

Notes:
Really, its a simple function to use, however, I attached a simple button project here also.
You can use a radius collision instead of boxcoll for better accuracy...it is just a quick sample.
To make a circle, you need to set the function to use 36 sides.
If you use the angle input, keep in mind, this rotates the shape, not the image.

Code (glbasic) Select


FUNCTION DRAWPOLYGON: TextureBMP, X, Y, Radius, EdgeColor, CenterColor, Sides, Angle
//Function creates a filled polygon of specified radius
// Where:
// xy = center of image
// radius = width from center, ie you make this the width of image divided by 2, width/2
// triangles = # of Sides for polygon
// angle = rotate the shape, not the image.

LOCAL Tstep=360.0/Sides
FOR Cir = 0 TO 359 STEP Tstep
STARTPOLY TextureBMP , 0
CirXS = X + Radius * COS( Cir + Angle )
CirYS = Y + Radius * SIN( Cir + Angle )
CirXE = X + Radius * COS( Cir + Angle - Tstep )
CirYE = Y + Radius * SIN( Cir + Angle - Tstep )
POLYVECTOR CirXS, CirYS, CirXS - X - Radius, CirYS - Y - Radius, EdgeColor
POLYVECTOR CirXE, CirYE, CirXE - X - Radius, CirYE - Y - Radius, EdgeColor
POLYVECTOR X, Y, -Radius, -Radius, CenterColor
ENDPOLY
NEXT

ENDFUNCTION



Here is the sample button project(screenshot is below the link):



[attachment deleted by admin]
Title: Re: Polygon() Function- Textured, Colored, Rotatable Shapes
Post by: Schranz0r on 2009-Dec-20
cool Function !
Title: Re: Polygon() Function- Textured, Colored, Rotatable Shapes
Post by: Hemlos on 2009-Dec-21
Thanks F

I optimized the function, it had redundant math in the texuring part:
X-X
Y-Y

Title: Re: Polygon() Function- Textured, Colored, Rotatable Shapes
Post by: Kitty Hello on 2009-Dec-21
very cool.