-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunit-circle.cc
More file actions
117 lines (91 loc) · 3.21 KB
/
unit-circle.cc
File metadata and controls
117 lines (91 loc) · 3.21 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// The following piece of software has been built upon
// the original project made by hzeller
// https://github.com/hzeller/rpi-rgb-led-matrix/
//
/* The MIT License (MIT)
Copyright (c) 2014-2015 Timothy Roe, Jr. & Roeboat, LLC.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
//
// --Code Starts Below this Line--
#include <stdio.h>
#include "led-matrix.h"
#include "threaded-canvas-manipulator.h"
#include <unistd.h>
#include <math.h>
using rgb_matrix::GPIO;
using rgb_matrix::RGBMatrix;
using rgb_matrix::Canvas;
static void DrawOnCanvas(Canvas *led) {
int center_x = led->width() / 2;
int center_y = led->height() / 2;
float radius_max = led->width() / 2;
float angle_step = 1.0 / 360;
for (float a = 0, r = 0; r < radius_max; a += angle_step, r += angle_step) {
float dot_x = cos(a * 2 * M_PI) * r;
float dot_y = sin(a * 2 * M_PI) * r;
led->SetPixel(center_x + dot_x, center_y + dot_y,
96, 96, 96);
usleep(1 * 1000);
}
int width = led->width();
int height = led->height();
for (int x = 0; x < width; x++) {
led->SetPixel(x, x, 255, 0, 0);
led->SetPixel(height - x, x, 255, 0, 0);
}
for (int x = 0; x < width; x++) {
led->SetPixel(x, height/2, 0, 255, 0);
}
for (int y = 0; y < height; y++) {
led->SetPixel(width/2, y, 0, 255, 0);
}
int y2;
int z;
for (y2 = 16, z = 0; y2 < height; y2++, z++) {
float t = 16+1.7321*z;
led->SetPixel(t, y2, 255, 0, 255);
led->SetPixel(height - t, y2, 255, 0, 255);
led->SetPixel(t, width - y2, 255, 0, 255);
led->SetPixel(height - t, width - y2, 255, 0, 255);
}
int x2;
int z2;
for (x2 = 16, z2 = 0; x2 < width; x2++, z2++) {
float s = 16+1.7321*z2;
led->SetPixel(x2, s, 255, 255, 0);
led->SetPixel(width-x2, s, 255, 255, 0);
led->SetPixel(x2, height - s, 255, 255, 0);
led->SetPixel(width - x2, height - s, 255, 255, 0);
}
}
int main(int argc, char *argv[]) {
GPIO io;
if (!io.Init())
return 1;
int rows = 32; // A 32x32 display. Use 16 when this is a 16x32 display.
int chain = 1; // Number of boards chained together.
Canvas *led = new RGBMatrix(&io, rows, chain);
led->Clear();
DrawOnCanvas(led);
printf("Press <RETURN> to Reset LEDs\n");
getchar();
led->Clear();
delete led;
return 0;
}
// --END CODE--