-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPie_Chart.cpp
More file actions
47 lines (34 loc) · 847 Bytes
/
Copy pathPie_Chart.cpp
File metadata and controls
47 lines (34 loc) · 847 Bytes
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
/**
* Pie Chart
* Translated to C++ by Jose Llamas.
*
* Uses the arc() function to generate a pie chart from the data
* stored in an array.
*/
int angles[] = { 30, 10, 45, 35, 60, 38, 75, 67 };
int anglesCount = sizeof(angles) / sizeof(angles[0]);
void pieChart(float diameter, int data[], int length) {
float lastAngle = 0;
for (int i = 0; i < length; i++) {
float gray = map(i, 0, length, 0, 255);
fill(gray);
arc(
width / 2,
height / 2,
diameter,
diameter,
lastAngle,
lastAngle + radians(data[i])
);
lastAngle += radians(data[i]);
}
}
void setup() {
size(640, 360);
noStroke();
noLoop(); // Run once and stop
}
void draw() {
background(100);
pieChart(300, angles, anglesCount);
}