2121#define RAYGUI_IMPLEMENTATION
2222#include "raygui.h" // Required for GUI controls
2323
24- //----------------------------------------------------------------------------------
25- // Module Functions Declaration
26- //----------------------------------------------------------------------------------
27- static Vector2 CalculatePoint (Vector2 start , float angle , float length );
28- static void DrawTriangleCustom (Vector2 point1 , Vector2 point2 , Vector2 point3 , float angle , bool outline );
29-
3024//------------------------------------------------------------------------------------
3125// Program main entry point
3226//------------------------------------------------------------------------------------
@@ -54,18 +48,20 @@ int main(void)
5448 {
5549 // Update
5650 //----------------------------------------------------------------------------------
57-
5851 int pointCount = (int )(segments );
5952 float angleStep = (360.0f /pointCount )* DEG2RAD ;
6053
6154 for (int i = 0 , i2 = 0 ; i < pointCount ; i ++ , i2 += 2 )
6255 {
63- points [i2 ] = CalculatePoint (center , i * angleStep , insideRadius );
64- points [i2 + 1 ] = CalculatePoint (center , i * angleStep + angleStep /2.0f , outsideRadius );
56+ float angle1 = i * angleStep ;
57+ points [i2 ] = (Vector2 ){ center .x + cosf (angle1 )* insideRadius , center .y + sinf (angle1 )* insideRadius };
58+ float angle2 = angle1 + angleStep /2.0f ;
59+ points [i2 + 1 ] = (Vector2 ){ center .x + cosf (angle2 )* outsideRadius , center .y + sinf (angle2 )* outsideRadius };
6560 }
66-
61+
6762 points [pointCount * 2 ] = points [0 ];
6863 points [pointCount * 2 + 1 ] = points [1 ];
64+ //----------------------------------------------------------------------------------
6965
7066 // Draw
7167 //----------------------------------------------------------------------------------
@@ -75,8 +71,15 @@ int main(void)
7571
7672 for (int i = 0 , i2 = 0 ; i < pointCount ; i ++ , i2 += 2 )
7773 {
78- DrawTriangleCustom (points [i2 ], points [i2 + 1 ], points [i2 + 2 ], i * angleStep , outline );
79- DrawTriangleCustom (points [i2 + 2 ], points [i2 + 1 ], points [i2 + 3 ], i * angleStep + (angleStep /2 ), outline );
74+ float angle1 = i * angleStep ;
75+ Color color = ColorFromHSV (angle1 * RAD2DEG , 1.0f , 1.0f );
76+ DrawTriangle (points [i2 + 2 ], points [i2 + 1 ], points [i2 ], color );
77+ if (outline ) DrawTriangleLines (points [i2 ], points [i2 + 1 ], points [i2 + 2 ], BLACK );
78+
79+ float angle2 = angle1 + angleStep /2.0f ;
80+ color = ColorFromHSV (angle2 * RAD2DEG , 1.0f , 1.0f );
81+ DrawTriangle (points [i2 + 3 ], points [i2 + 1 ], points [i2 + 2 ], color );
82+ if (outline ) DrawTriangleLines (points [i2 + 2 ], points [i2 + 1 ], points [i2 + 3 ], BLACK );
8083 }
8184
8285 DrawLine (580 , 0 , 580 , GetScreenHeight (), (Color ){ 218 , 218 , 218 , 255 });
@@ -100,16 +103,4 @@ int main(void)
100103 //--------------------------------------------------------------------------------------
101104
102105 return 0 ;
103- }
104-
105- static Vector2 CalculatePoint (Vector2 start , float angle , float radius )
106- {
107- return (Vector2 ){ start .x + cosf (angle )* radius , start .y + sinf (angle )* radius };
108- }
109-
110- static void DrawTriangleCustom (Vector2 point1 , Vector2 point2 , Vector2 point3 , float angle , bool outline )
111- {
112- Color color = ColorFromHSV (angle * RAD2DEG , 1.0f , 1.0f );
113- DrawTriangle (point3 , point2 , point1 , color );
114- if (outline ) DrawTriangleLines (point1 , point2 , point3 , BLACK );
115106}
0 commit comments