2
0

ScreenTransitionCircle.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // Circle screen transition effect using Bresenham circle.
  3. //
  4. //
  5. #include "raylib.h"
  6. //
  7. // Our function for transitioning the screen.
  8. void circletransition(int radius, int screenWidth, int screenHeight, Color col);
  9. // Helper functions for curcletransition....
  10. void circleBres(int xc, int yc, int r,int screenWidth, int screenHeight, Color col);
  11. void putpixelBres(int xc, int yc, int x, int y,int screenWidth, int screenHeight, Color col);
  12. int main(void)
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. int screenWidth = 800;
  17. int screenHeight = 450;
  18. InitWindow(screenWidth, screenHeight, "raylib example.");
  19. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  20. //--------------------------------------------------------------------------------------
  21. // transition setup(start with nothing to grow)
  22. int radius=0;
  23. int state=0;
  24. // Main game loop
  25. while (!WindowShouldClose()) // Detect window close button or ESC key
  26. {
  27. // Update
  28. //----------------------------------------------------------------------------------
  29. //
  30. // Here our transition effects is done.
  31. //
  32. // Draw our transition
  33. circletransition(radius,screenWidth,screenHeight,BLACK);
  34. // Grow our circle
  35. if(state==0 && radius<screenWidth/1.5){
  36. radius+=6;
  37. }else{
  38. state=1;
  39. }
  40. // Shrink our circle
  41. if(state==1 && radius>0){
  42. radius-=6;
  43. }else{
  44. state=0;
  45. }
  46. //----------------------------------------------------------------------------------
  47. // Draw
  48. //----------------------------------------------------------------------------------
  49. BeginDrawing();
  50. ClearBackground(RAYWHITE);
  51. for(int y=0;y<screenHeight;y+=30){
  52. for(int x=0;x<screenWidth;x+=250){
  53. DrawText("Hello this is a fade..",x,y,25,BLACK);
  54. }}
  55. EndDrawing();
  56. //----------------------------------------------------------------------------------
  57. }
  58. // De-Initialization
  59. //--------------------------------------------------------------------------------------
  60. CloseWindow(); // Close window and OpenGL context
  61. //--------------------------------------------------------------------------------------
  62. return 0;
  63. }
  64. void circletransition(int radius, int screenWidth, int screenHeight,Color col){
  65. int cx = screenWidth/2;
  66. int cy = screenHeight/2;
  67. for(int a=0;a<cy-radius;a++){
  68. DrawLine(0,a,screenWidth,a,col);
  69. }
  70. circleBres(cx,cy, radius,screenWidth,screenHeight,BLACK);
  71. for(int a=cy+radius;a<=screenHeight;a++){
  72. DrawLine(0,a,screenWidth,a,col);
  73. }
  74. }
  75. void circleBres(int xc, int yc, int r, int screenWidth, int screenHeight, Color col)
  76. {
  77. int x=0;
  78. int y=r;
  79. int p=1-r;
  80. while(x<=y){
  81. putpixelBres(xc,yc,x,y,screenWidth, screenHeight, col);
  82. if(p<=0){
  83. x=x+1;
  84. y=y;
  85. p=p+(x*2)+3;
  86. }else if(p>0)
  87. {
  88. x=x+1;
  89. y=y-1;
  90. p=p+(x*2)-(y*2)+5;
  91. }
  92. }
  93. }
  94. //
  95. // Here we draw from the circle outwards to the edges of the screen,.
  96. void putpixelBres(int xc, int yc, int x, int y, int screenWidth, int screenHeight, Color col) {
  97. DrawLine(screenWidth,yc+y,xc+x, yc+y, col);
  98. DrawLine(0,yc+y,xc-x, yc+y, col);
  99. DrawLine(screenWidth,yc-y,xc+x, yc-y, col);
  100. DrawLine(0,yc-y,xc-x, yc-y, col);
  101. DrawLine(0,yc-x,xc-y, yc-x, col);
  102. DrawLine(screenWidth,yc-x,xc+y, yc-x, col);
  103. DrawLine(0,yc+x,xc-y, yc+x, col);
  104. DrawLine(screenWidth,yc+x,xc+y, yc+x, col);
  105. }