Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //function that returns random floats
- float frand() {
- srand(time(NULL));
- return (float)((rand() % 100 + 1) % (rand() % 10 + 1)) / 10;
- }
- //function that does pretty things inside any window
- void illusion(SDL_Window *window) {
- const int screen_width = 500;
- const int screen_height = 500;
- SDL_Renderer *renderer = SDL_CreateRenderer(window, 0, SDL_RENDERER_ACCELERATED);
- SDL_Rect rectangle, rectangle2;
- //default values
- bool quit = false;
- double rect1_x = screen_width / 2, rect1_y = screen_height / 2, rect1_width = 5, rect1_height = 5;
- double rect2_x = screen_width / 2, rect2_y = screen_height / 2, rect2_width = 5, rect2_height = 5;
- while (quit == false)
- {
- float p = frand(), q = frand(), r = frand(), s = frand();
- SDL_Event event;
- while (SDL_PollEvent(&event))
- if (event.type == SDL_QUIT) quit = true;
- rectangle.x = rect1_x, rectangle.y = rect1_y, rectangle.h = rect1_height, rectangle.w = rect1_width;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
- SDL_RenderFillRect(renderer, &rectangle);
- rect1_x -= p;
- rect1_y -= q;
- rect1_width += p*2;
- rect1_height += q*2;
- if (rect1_x < 0 || rect1_y < 0)
- {
- rect1_height = 0;
- rect1_width = 0;
- rect1_x = 0;
- rect1_y = 0;
- if (rect1_x < 250 || rect1_y < 250)
- {
- rectangle2.x = rect2_x;
- rectangle2.y = rect2_y;
- rectangle2.h = rect2_height;
- rectangle2.w = rect2_width;
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- SDL_RenderFillRect(renderer, &rectangle2);
- rect2_x -= r;
- rect2_y -= s;
- rect2_width += 2*r;
- rect2_height += 2*s;
- }
- }
- if (rect2_x < 0 || rect2_y < 0)
- {
- rect2_height = 0;
- rect2_width = 0;
- rect2_x = 250;
- rect2_y = 250;
- rect1_height = 5;
- rect1_width = 5;
- rect1_x = 250;
- rect1_y = 250;
- SDL_Delay(rand() % 10);
- }
- SDL_RenderPresent(renderer);
- }
- }
- /*
- YOU can randomize almost everything! colors! delays!! sprites!! shaders!!! :P
- shapes are tough to randomise, I am just a noob in sdl :(
- */
Add Comment
Please, Sign In to add comment