Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Attrattore di Lorenz - attrattoredilorenz.c

attrattoredilorenz.c

Caricato da:
Scarica il programma completo

  1. /***************************************************************************
  2.  *   Copyright (C) 2008 by Lorenzo La Porta   *
  3.  *   lorelapo@gmail.com   *
  4.  *                                                                         *
  5.  *   This program is free software; you can redistribute it and/or modify  *
  6.  *   it under the terms of the GNU General Public License as published by  *
  7.  *   the Free Software Foundation; either version 2 of the License, or     *
  8.  *   (at your option) any later version.                                   *
  9.  *                                                                         *
  10.  *   This program is distributed in the hope that it will be useful,       *
  11.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  12.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  13.  *   GNU General Public License for more details.                          *
  14.  *                                                                         *
  15.  *   You should have received a copy of the GNU General Public License     *
  16.  *   along with this program; if not, write to the                         *
  17.  *   Free Software Foundation, Inc.,                                       *
  18.  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  19.  ***************************************************************************/
  20.  
  21.  
  22. #ifdef HAVE_CONFIG_H
  23. #include <config.h>
  24. #endif
  25.  
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <SDL.h>
  29. #include "SDL_gfxPrimitives.h"
  30. #include <math.h>
  31.  
  32. #define WIDTH 800
  33. #define HEIGHT 600
  34. #define BPP 4
  35. #define DEPTH 32
  36. #define SIGMA 10
  37. #define R 26
  38. #define B (8./3.)
  39. float x=10., y=10., z=10., t=0., k=10.;
  40.  
  41. void repaint(SDL_Surface *srf)
  42. {
  43.         float tx, ty, tz;
  44.         tx=x;
  45.         ty=y;
  46.         tz=z;
  47.         x=tx+0.01*SIGMA*(ty-tx);
  48.         y=ty+0.01*(-x*z+R*x-y);
  49.         z=tz+0.01*(x*y-B*z);
  50.         t+=0.01;
  51.         lineRGBA(srf,(int)(tx*k)+WIDTH/2,HEIGHT/2-(int)(ty*k),(int)(x*k)+WIDTH/2,HEIGHT/2-(int)(y*k),0xFF-(int)(t*11.0),0xFF-(int)(t*10.0),0xFF-(int)(t),0xFF-(int)(t*9.1));
  52. }
  53.  
  54. int main(int argc, char* argv[])
  55. {
  56.         SDL_Surface *screen;
  57.         SDL_Event event;
  58.         int keypress = 0;
  59.        
  60.         if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
  61.        
  62.         if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_HWACCEL/*|SDL_FULLSCREEN*/|SDL_HWSURFACE)))
  63.         {
  64.                 SDL_Quit();
  65.                 return 1;
  66.         }
  67.        
  68.         while(!keypress)
  69.         {
  70.                 repaint(screen);
  71.                 SDL_Flip(screen);
  72.                 while(SDL_PollEvent(&event))
  73.                 {      
  74.                         switch (event.type)
  75.                         {
  76.                                 case SDL_QUIT:
  77.                                         keypress = 1;
  78.                                         break;
  79.                                 case SDL_KEYDOWN:
  80.                                         switch(event.key.keysym.sym)
  81.                                         {
  82.                                                 case SDLK_ESCAPE:
  83.                                                         keypress = 1;
  84.                                                         break;
  85.                                                 case SDLK_F11:
  86.                                                         SDL_WM_ToggleFullScreen(screen);
  87.                                                         break;
  88.                                                 default:
  89.                                                         printf("Reached unknown keydown event.\n");
  90.                                         }
  91.                                         break;
  92.                                
  93.                                 default:
  94.                                         ;
  95.                         }
  96.                 }
  97.        
  98.         }
  99.         SDL_SaveBMP(screen,"SDLscreenONEXITSAVE.bmp");
  100.         SDL_FreeSurface(screen);
  101.         SDL_Quit();
  102.  
  103.         return 0;
  104. }