Advertisement
dbright

circle and squares fractal with Quadrance

Jul 17th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. // study in quadrance / Wildberger's chromogeometry
  2. // https://www.flickr.com/photos/140786894@N03/albums/72157670200898221/with/28173892446/
  3. // https://www.youtube.com/watch?v=xgS9JBs5RV0
  4.  
  5. #include <SDL.h>
  6. #include <stdio.h>
  7.  
  8. #define pixelsize 4
  9. Uint32 pixels[256*256*pixelsize];
  10. struct pixl8_t {
  11. Uint8 blue,green,red,alpha;
  12. };
  13.  
  14. void quitf() {
  15. printf("%s\n",SDL_GetError() );
  16. exit(0);
  17. }
  18.  
  19. int main( int argc, char* args[] )
  20. {
  21. if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) quitf();
  22. if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) ) quitf();
  23. SDL_Window *window = SDL_CreateWindow( "mpixel",
  24. SDL_WINDOWPOS_UNDEFINED,
  25. SDL_WINDOWPOS_UNDEFINED,
  26. 256,256,
  27. SDL_WINDOW_SHOWN );
  28. if (!window) quitf();
  29. SDL_Renderer* renderer = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED );
  30. if (!renderer) quitf();
  31. SDL_SetRenderDrawColor( renderer, 0, 0, 0, 255 );
  32. SDL_RenderClear( renderer );
  33. // http://gamedev.stackexchange.com/questions/87727/sdl-updatetexture-is-slow
  34. SDL_Texture* texture = SDL_CreateTexture(renderer,
  35. SDL_PIXELFORMAT_ARGB8888,
  36. SDL_TEXTUREACCESS_STREAMING,
  37. 256, 256);
  38. if( !texture ) quitf();
  39. bool quit = false;
  40. while (!quit)
  41. {
  42. SDL_Event event;
  43. while( SDL_PollEvent( &event ) )
  44. {
  45. if( event.type == SDL_QUIT ) quit = true;
  46. if( event.type == SDL_KEYDOWN ) {
  47. if ( event.key.keysym.sym == SDLK_ESCAPE ) quit = true;
  48. }
  49. }
  50. for (Uint32 i=0;i<256;i++) {
  51. for (Uint32 j=0;j<256;j++) {
  52. struct pixl8_t *p;
  53. p = (struct pixl8_t *)&pixels[j*256+i];
  54. p->red = p->green = p->blue = i*i+j*j;
  55. }
  56. }
  57. SDL_Delay(400);
  58. SDL_UpdateTexture( texture, NULL, pixels, 256 * pixelsize);
  59. SDL_RenderCopy( renderer, texture, NULL, NULL );
  60. SDL_RenderPresent( renderer );
  61. }
  62. SDL_DestroyTexture( texture );
  63. SDL_DestroyRenderer( renderer );
  64. SDL_DestroyWindow( window );
  65. SDL_Quit();
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement