Author Topic: Polygon() Function- Textured, Colored, Rotatable Shapes  (Read 3660 times)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
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]
« Last Edit: 2009-Dec-21 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5024
  • O Rly?
    • View Profile
cool Function !
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
Thanks F

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

Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10715
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
very cool.