Created
August 10, 2020 12:33
-
-
Save pcholt/8bde68ba806748c6ee06806de6c29be8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SDL.h> | |
#include <iostream> | |
SDL_Window *win; | |
SDL_Renderer *ren; | |
SDL_Event e; | |
#define RES_X 1920 | |
#define RES_Y 1080 | |
int createWindow() { | |
win = SDL_CreateWindow("Chaos", 100, 100, RES_X, RES_Y, SDL_WINDOW_SHOWN); | |
if (win == nullptr){ | |
std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl; | |
SDL_Quit(); | |
return 1; | |
} | |
SDL_SetWindowFullscreen(win, SDL_WINDOW_FULLSCREEN); | |
ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC ); | |
if (ren == nullptr){ | |
SDL_DestroyWindow(win); | |
std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl; | |
SDL_Quit(); | |
return 2; | |
} | |
return 0; | |
} | |
int startSdl() { | |
if (SDL_Init(SDL_INIT_VIDEO) != 0) { | |
std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl; | |
return 1; | |
} | |
return 0; | |
} | |
int loop() { | |
for (int tint=1000; tint<20000; tint++) { | |
double t = tint/20000.0; | |
while (SDL_PollEvent(&e)){ | |
//If user closes the window | |
if (e.type == SDL_QUIT){ | |
return 1; | |
} | |
//If user presses any key | |
if (e.type == SDL_KEYDOWN){ | |
return 1; | |
} | |
//If user clicks the mouse | |
if (e.type == SDL_MOUSEBUTTONDOWN){ | |
return 1; | |
} | |
} | |
SDL_SetRenderDrawColor(ren, 0, 0, 0, 255); | |
SDL_RenderClear(ren); | |
double x = t; | |
double y = t; | |
for (int points=0; points<10000; points++) { | |
SDL_SetRenderDrawColor(ren, 256-points % 256, points % 256, 256-points % 256, 100); | |
double tmp = x*x - x*t + y*t - x; | |
y = -y*y - t*t - x*y - x*t - y*t -y; | |
x = tmp; | |
SDL_RenderDrawPoint( | |
ren, | |
RES_X/2 + x*RES_Y/3, | |
RES_Y/2 + y*RES_Y/3 | |
); | |
} | |
SDL_RenderPresent(ren); | |
SDL_Delay(1); | |
} | |
} | |
int main(int argc, char const *argv[]) | |
{ | |
if (startSdl() != 0) return 1; | |
if (createWindow() != 0) return 2; | |
std::cout << "Start " << std::endl; | |
loop(); | |
SDL_DestroyRenderer(ren); | |
SDL_DestroyWindow(win); | |
SDL_Quit(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment