Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #include <time.h>
- #include <math.h>
- #include <SDL/SDL.h>
- #define PI 3.14159265
- SDL_Surface* screen = NULL;
- int width = 256;
- int height = 256;
- //start SDL
- bool init(){
- if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) {
- return false;
- }
- screen = SDL_SetVideoMode( width, height, 32, SDL_SWSURFACE);
- if(!screen){
- return false;
- }
- srand( time(NULL) );
- return true;
- }
- //make a color
- Uint32 color(int r, int g, int b){
- Uint32 c = SDL_MapRGB(screen->format, r, g, b);
- return(c);
- }
- //make a random number
- int randomNum(int min, int max){
- int ranNum = rand() % max + min;
- return(ranNum);
- }
- void point(float x, float y, Uint32 c){
- SDL_FillRect(screen, &SDL_Rect{x,y,1,1}, c);
- }
- float avg(long double x, long double y){
- return ((x+y)/2);
- }
- //SDL_FillRect(screen, &SDL_Rect {x, y, w, h}, color(r, g, b) );
- // SDL_FillRect(screen, &screen->clip_rect, color(0,0,0) );
- // sin(PI*_/180)
- int main ( int argc, char** argv )
- {
- long double r=0;
- long double g=0;
- long double b=0;
- double pi = PI/180;
- if(!init()){
- return(1);
- }
- for(int x=1; x < width; x++){
- //cout << sin(pi*/180)*128+128 << endl;
- for(int y=1; y<height; y++){
- r = avg(sin(x*x), cos(y*y))*sin(pi*x);
- //r = x*x + y*y;
- g = sin(pi*x*cos(pi*y*x));
- b = 0.7*(sin(pi*x*x)*cos(pi*y*y));
- cout << r << endl;
- point(x, y, color(r*128+128,g*128+128, b*128+128));
- }
- }
- SDL_Flip(screen);
- SDL_SaveBMP(screen, "picture");
- SDL_Delay(2000);
- SDL_FreeSurface(screen);
- SDL_Quit();
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement