-
Notifications
You must be signed in to change notification settings - Fork 0
/
Confetti.h
executable file
·99 lines (82 loc) · 2.27 KB
/
Confetti.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Authors: Maggie Burton, Rachel Bugge, Elise Hebert, Mackensi Holt, and
* Darius Sherman
* Assignment Title: Tiger Game
* File Description: Contains functions to draw confetti on the game
* Due Date: 4/26/2018
* Date Created: 4/13/2018
* Date Modified:
* 4/13/2018: file created
* 4/21/2018: file modified and added to game
*/
#ifndef CONFETTI_H_INCLUDED
#define CONFETTI_H_INCLUDED
#include <iostream>
#include "SDL_Plotter.h"
#include "Circle.h"
#include <ctime>
#include <string>
using namespace std;
/*
* description: sets the color of the confetti circles
* return: void
* precondition: none
* postcondition: the color of the confetti is set
*/
void setColorBasedOnTime(int& r, int& g, int& b){
time_t currentTime;
struct tm *localTime;
long int start, stop;
start = clock();
time( ¤tTime );
localTime = localtime( ¤tTime );
int Hour = localTime->tm_hour;
int Min = localTime->tm_min;
int Sec = localTime->tm_sec;
stop = clock();
r = 20;
b = ((stop - start)*1250) % Sec * 10;
g = ((stop - start)*1250) % Hour * 17;
}
/*
* description: creates a random rgb value for the confetti
* return: void
* precondition: none
* postcondition: the color of the confetti is set
*/
void setColorRandomly(int&r, int& g, int& b){
r = rand() % 256;
g = rand() % 256;
b = rand() % 256;
}
/*
* description: initiates a circle object
* return: void
* precondition: none
* postcondition: circle is drawn in the Plotter
*/
void confetti( SDL_Plotter* graphics, int radius){
int x, y, R, G, B;
Circle theCircle;
theCircle.setRadius(radius);
x = rand() % graphics->getCol() + 1;
y = rand() % graphics->getRow() + 1;
//setColorBasedOnTime(R, G, B);
setColorRandomly(R, G, B);
theCircle.setCenter(x, y);
theCircle.setColor(R, G, B);
theCircle.draw(graphics);
}
/*
* description: an array of confetti circles is created and drawn
* return: void
* precondition: an SDL Plotter exists
* postcondition: confetti circles are drawn to the Plotter
*/
void drawConfetti( SDL_Plotter* graphics, int count, int radius){
for ( int i = 0; i < count; i++ ){
confetti(graphics, radius);
graphics->update();
}
}
#endif // CONFETTI_H_INCLUDED