GrowZonesProcess.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // Create zones - this version kind of creates those military camouflage patterns.
  3. //
  4. #include "raylib.h"
  5. int numzones = 30;
  6. int map[100][100];
  7. int main(void)
  8. {
  9. // Initialization
  10. //--------------------------------------------------------------------------------------
  11. const int screenWidth = 800;
  12. const int screenHeight = 450;
  13. InitWindow(screenWidth, screenHeight, "raylib example.");
  14. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  15. //--------------------------------------------------------------------------------------
  16. // First put the id's on the map
  17. for(int i=0;i<numzones;i++){
  18. int x = GetRandomValue(0,100);
  19. int y = GetRandomValue(0,100);
  20. map[x][y] = i;
  21. }
  22. // grow the zones. pick a random spot. with that value grow one around it.
  23. for(int i=0;i<100*100*100;i++){
  24. int x = GetRandomValue(1,99);
  25. int y = GetRandomValue(1,99);
  26. int z = map[x][y];
  27. if(z>0){
  28. int y1=GetRandomValue(-1,1);
  29. int x1=GetRandomValue(-1,1);
  30. if(map[x+x1][y+y1]==0){
  31. map[x+x1][y+y1]=z;
  32. }
  33. }
  34. }
  35. // pick random spot. With that value draw a rect there (3*3) (blockize)
  36. for(int i=0;i<100*100*100;i++){
  37. int x = GetRandomValue(1,99);
  38. int y = GetRandomValue(1,99);
  39. int z = map[x][y];
  40. if(z>0){
  41. for(int y1=-1;y1<2;y1++){
  42. for(int x1=-1;x1<2;x1++){
  43. if(x+x1<0 || y+y1<0 || x+x1>99 || y+y1>99) continue;
  44. map[x+x1][y+y1]=z;
  45. }}
  46. }
  47. }
  48. // Main game loop
  49. while (!WindowShouldClose()) // Detect window close button or ESC key
  50. {
  51. // Update
  52. //----------------------------------------------------------------------------------
  53. //----------------------------------------------------------------------------------
  54. // Draw
  55. //----------------------------------------------------------------------------------
  56. BeginDrawing();
  57. ClearBackground(RAYWHITE);
  58. for(int y=0;y<100;y++){
  59. for(int x=0;x<100;x++){
  60. int m=map[x][y];
  61. float col = (255.0f/(float)numzones)*(float)m;
  62. Color c = (Color){col,col,col,255};
  63. DrawRectangle(x*7,y*4,7,4,c);
  64. }}
  65. EndDrawing();
  66. //----------------------------------------------------------------------------------
  67. }
  68. // De-Initialization
  69. //--------------------------------------------------------------------------------------
  70. CloseWindow(); // Close window and OpenGL context
  71. //--------------------------------------------------------------------------------------
  72. return 0;
  73. }