GianaRectCOLOR.c 5.3 KB

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