NoPaste

Kreisbild aus Punkten

von heinz
SNIPPET_DESC:
Kreisbild aus Punkten
SNIPPET_CREATION_TIME:
06.01.2019 18:56:36
SNIPPET_PRUNE_TIME:
Unendlich

SNIPPET_TEXT:
  1. /*
  2.   z2z
  3.   06.01.2019
  4. */
  5.  
  6.  
  7.  
  8. #include <stdlib.h>
  9. #include <time.h>
  10. #include <SDL.h>
  11. #include "SDL_gfxPrimitives.h"
  12.  
  13. // Bildschirmdaten
  14.  
  15. const int bX=1024;
  16. const int bY=768;
  17.  
  18. /*
  19. const int bX=2000;
  20. const int bY=2000;
  21. */
  22. const int bF=32;
  23.  
  24. // Grafik-Arbeitsbereich
  25. SDL_Surface* display=NULL;
  26. // Ereignisstapel fuer Tastatur- und Maus-Ereignisse
  27. SDL_Event ereignis;
  28.  
  29. const double Pi=3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. int main()
  38. {
  39.  
  40.   srandom(time(0));
  41.  
  42. // SDL
  43.   if(SDL_Init(SDL_INIT_VIDEO)<0)
  44.   {
  45.     fprintf(stderr,"\aSDL konnte nicht initialisiert werden:  %s\n",SDL_GetError());
  46.     exit(1);
  47.   }
  48.  
  49.   atexit(SDL_Quit);
  50.  
  51.   display=SDL_SetVideoMode(bX,bY,bF,SDL_SWSURFACE);
  52.   if(display==NULL)
  53.   {
  54.     fprintf(stderr,"\aKonnte kein Display %ix%ix%i erzeugen: %s\n",bX,bY,bF,SDL_GetError());
  55.     exit(1);
  56.   }
  57.  
  58.  
  59.  
  60.  
  61.  
  62.   for(int z=0 ; z<10000 ; z++)
  63.   {
  64.     float winkel=(float)(rand()%36000000)/100000.0;
  65.     float radius= (rand()% 2000) / 10.0;
  66.     float x = sin( winkel * (Pi / 180.0) ) * radius;
  67.     float y = cos( winkel * (Pi / 180.0) ) * radius;
  68.     pixelColor(display,x+bX/2,y+bY/2,0xffffffff);
  69.   }
  70.   SDL_Flip(display);
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. // Warte auf Taste oder Maus-Taste
  78.   bool programm_ende=false;
  79.   while(!programm_ende)
  80.   {
  81.     while(SDL_PollEvent(&ereignis))
  82.     {
  83.       if(ereignis.type==SDL_MOUSEBUTTONDOWN||ereignis.type==SDL_KEYDOWN)
  84.       {
  85.         programm_ende=true;
  86.       }
  87.     }
  88.     SDL_Delay(1);
  89.   }
  90.  
  91.   SDL_FreeSurface(display);
  92. }
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN