DrawColoredPillar01.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #include "raylib.h"
  2. void drawpillar01(int x, int y, int w, int h, int thick, Color col);
  3. // Raylibs built in Clamp seems not to work?
  4. static float Clamp(float value, float min, float max);
  5. int main(void)
  6. {
  7. // Initialization
  8. //--------------------------------------------------------------------------------------
  9. const int screenWidth = 800;
  10. const int screenHeight = 450;
  11. InitWindow(screenWidth, screenHeight, "raylib example.");
  12. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  13. //--------------------------------------------------------------------------------------
  14. int time=0;
  15. Color col=(Color){GetRandomValue(0,255),GetRandomValue(0,255),GetRandomValue(0,255),255};
  16. // Main game loop
  17. while (!WindowShouldClose()) // Detect window close button or ESC key
  18. {
  19. // Update
  20. //----------------------------------------------------------------------------------
  21. time++;
  22. if(time>60){
  23. time=0;
  24. col=(Color){GetRandomValue(0,255),GetRandomValue(0,255),GetRandomValue(0,255),255};
  25. }
  26. //----------------------------------------------------------------------------------
  27. // Draw
  28. //----------------------------------------------------------------------------------
  29. BeginDrawing();
  30. Color mycol = (Color){ Clamp((col.r/100)*110,0,255),
  31. Clamp((col.g/100)*110,0,255),
  32. Clamp((col.b/100)*110,0,255),255};
  33. ClearBackground(mycol);
  34. for(int x=0;x<screenWidth;x+=200){
  35. for(int y=0;y<screenHeight;y+=256){
  36. drawpillar01(x,y,96,256,8,col);
  37. }
  38. }
  39. EndDrawing();
  40. //----------------------------------------------------------------------------------
  41. }
  42. // De-Initialization
  43. //--------------------------------------------------------------------------------------
  44. CloseWindow(); // Close window and OpenGL context
  45. //--------------------------------------------------------------------------------------
  46. return 0;
  47. }
  48. void drawpillar01(int x, int y, int w, int h,int thick, Color col){
  49. Color col1 = (Color){63,30,3,255};
  50. Color col2 = (Color){81,40,0,255};
  51. Color col3 = (Color){119,61,7,255};
  52. Color col4 = (Color){159,116,2,255};
  53. Color col5 = (Color){198,181,0,255};
  54. int gc=0;
  55. gc=(col1.r+col1.g+col1.b)/3;
  56. col1 = (Color){ Clamp(gc/2+(col.r/100)*50,0,255),
  57. Clamp(gc/2+(col.g/100)*50,0,255),
  58. Clamp(gc/2+(col.b/100)*50,0,255),255};
  59. gc=(col2.r+col2.g+col2.b)/3;
  60. col2 = (Color){ Clamp(gc/2+(col.r/100)*50,0,255),
  61. Clamp(gc/2+(col.g/100)*50,0,255),
  62. Clamp(gc/2+(col.b/100)*50,0,255),255};
  63. gc=(col3.r+col3.g+col3.b)/3;
  64. col3 = (Color){ Clamp(gc/2+(col.r/100)*50,0,255),
  65. Clamp(gc/2+(col.g/100)*50,0,255),
  66. Clamp(gc/2+(col.b/100)*50,0,255),255};
  67. gc=(col4.r+col4.g+col4.b)/3;
  68. col4 = (Color){ Clamp(gc/2+(col.r/100)*50,0,255),
  69. Clamp(gc/2+(col.g/100)*50,0,255),
  70. Clamp(gc/2+(col.b/100)*50,0,255),255};
  71. gc=(col5.r+col5.g+col5.b)/3;
  72. col5 = (Color){ Clamp(gc/2+(col.r/100)*50,0,255),
  73. Clamp(gc/2+(col.g/100)*50,0,255),
  74. Clamp(gc/2+(col.b/100)*50,0,255),255};
  75. // TOP OF PILLAR
  76. DrawRectangle(x,y,w,thick*8,col1);
  77. DrawRectangle(x+w/2-thick*3,y,thick*6,4,col2);
  78. DrawRectangle(x+thick,y+thick,w-thick*2,thick*5,col2);
  79. DrawRectangle(x+w/2-thick*4,y+thick*2,thick*8,thick*3,col3);
  80. DrawRectangle(x+w/2-thick*2,y+thick*3,thick*4,thick,col4);
  81. DrawRectangle(x+w/2-thick*3,y+thick*5,thick,thick,col3);
  82. DrawRectangle(x+w/2-thick*2,y+thick*5,thick*4,thick,col4);
  83. DrawRectangle(x+w/2+thick*2,y+thick*5,thick,thick,col3);
  84. y+=thick*6;
  85. //
  86. // MIDDLE PILLAR
  87. //
  88. h-=thick*2;
  89. // Inner pillar
  90. DrawRectangle(x+thick,y,w/2,h,col2);
  91. DrawRectangle(x+w/2,y,w/2,h,col2);
  92. // Outer pillar line
  93. DrawRectangle(x,y,thick,h,col1);
  94. DrawRectangle(x+w-thick,y,thick,h,col1);
  95. // Pillar inner edge
  96. DrawRectangle(x+w/2-thick*3,y,thick,h,col3);
  97. DrawRectangle(x+w/2-thick*2,y,thick,h,col4);
  98. DrawRectangle(x+w/2-thick,y,thick*2,h,col5);
  99. DrawRectangle(x+w/2+thick,y,thick,h,col4);
  100. DrawRectangle(x+w/2+thick*2,y,thick,h,col3);
  101. h+=thick*2;
  102. //
  103. // BOTTOM PILLAR
  104. //
  105. DrawRectangle(x,y+h-thick*2,w,thick*2,col1);
  106. DrawRectangle(x+w/2-thick*5,y+h-thick*2,thick*10,thick,col2);
  107. DrawRectangle(x+w/2-thick*6,y+h-thick,thick*12,thick,col2);
  108. DrawRectangle(x+w/2-thick*3,y+h-thick,thick*2,thick*2,col3);
  109. DrawRectangle(x+w/2-thick*2,y+h-thick*2,thick,thick*2,col3);
  110. DrawRectangle(x+w/2-thick,y+h-thick*2,thick*2,thick*2,col4);
  111. DrawRectangle(x+w/2+thick*1,y+h-thick*2,thick,thick*2,col3);
  112. DrawRectangle(x+w/2+thick*2,y+h-thick,thick,thick*2,col3);
  113. }
  114. // Clamp float value
  115. float Clamp(float value, float min, float max)
  116. {
  117. const float res = value < min ? min : value;
  118. return res > max ? max : res;
  119. }