ScreenCircleTransitionCLEAN.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // Circle screen transition effect (CLEAN)
  3. //
  4. // Draw a circle on the screen but draw from the edges of this circle
  5. // to the edges of the screen.
  6. //
  7. //
  8. #include "raylib.h"
  9. void circletransition(int r, int screenWidth, int screenHeight, Color col);
  10. int main(void)
  11. {
  12. // Initialization
  13. //--------------------------------------------------------------------------------------
  14. const int screenWidth = 800;
  15. const int screenHeight = 450;
  16. InitWindow(screenWidth, screenHeight, "raylib example.");
  17. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  18. //--------------------------------------------------------------------------------------
  19. int radius = 0;
  20. int state = 0;
  21. // Main game loop
  22. while (!WindowShouldClose()) // Detect window close button or ESC key
  23. {
  24. // Update
  25. //----------------------------------------------------------------------------------
  26. if(state==0 && radius<screenWidth/1.5){
  27. radius+=10;
  28. }else{
  29. state = 1;
  30. }
  31. if(state==1 && radius>0){
  32. radius-=10;
  33. }else{
  34. state = 0;
  35. }
  36. //----------------------------------------------------------------------------------
  37. // Draw
  38. //----------------------------------------------------------------------------------
  39. BeginDrawing();
  40. ClearBackground(RAYWHITE);
  41. for(int y=0;y<screenHeight;y+=30){
  42. for(int x=0;x<screenWidth;x+=250){
  43. DrawText("Hello this is a fade..",x,y,25,BLACK);
  44. }}
  45. circletransition(radius,screenWidth,screenHeight,BLACK);
  46. EndDrawing();
  47. //----------------------------------------------------------------------------------
  48. }
  49. // De-Initialization
  50. //--------------------------------------------------------------------------------------
  51. CloseWindow(); // Close window and OpenGL context
  52. //--------------------------------------------------------------------------------------
  53. return 0;
  54. }
  55. //
  56. // Our circle transition effect.
  57. //
  58. void circletransition(int radius, int screenWidth, int screenHeight, Color col) {
  59. int xc = screenWidth/2;
  60. int yc = screenHeight/2;
  61. // Draw the line above and below the circle...
  62. for(int a=0;a<yc-radius;a++){
  63. DrawLine(0,a,screenWidth,a,BLACK);
  64. }
  65. for(int a=yc+radius;a<=screenHeight;a++){
  66. DrawLine(0,a,screenWidth,a,BLACK);
  67. }
  68. // Draw from the edges of the circle to the edges of the screen.
  69. int largestX = radius;
  70. for (int y = 0; y <= radius; ++y) {
  71. for (int x = largestX; x >= 0; --x) {
  72. if ((x * x) + (y * y) <= (radius * radius)) {
  73. DrawLine(0,yc-y,xc-x,yc-y,col);
  74. DrawLine(0,yc+y,xc-x,yc+y,col);
  75. DrawLine(xc+x,yc-y,screenWidth,yc-y,col);
  76. DrawLine(xc+x,yc+y,screenWidth,yc+y,col);
  77. largestX = x;
  78. break; // go to next y coordinate
  79. }
  80. }
  81. }
  82. }