Skip to content

Commit a9a4996

Browse files
authored
Merge pull request #66 from MatzElectronics/master
Added graphics functions for OLED display
2 parents 89f7156 + 46d2e13 commit a9a4996

File tree

10 files changed

+1348
-1140
lines changed

10 files changed

+1348
-1140
lines changed

Learn/Simple Libraries/Social/libbadgetools/Documentation badgetools Library.html

Lines changed: 478 additions & 92 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Learn/Simple Libraries/Social/libbadgetools/badgetools.h

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,105 @@ void line( int x0, int y0, int x1, int y1, int c);
875875
*/
876876
void box( int x0, int y0, int x1, int y1, int c);
877877

878+
/**
879+
* @brief Plot a filled box on the oLED screen.
880+
*
881+
* @param x0 The x coordinate of one corner of the box. Measured as a
882+
* number of pixels from left side of screen. The value increases
883+
* from 0 (left) to 127 (right).
884+
*
885+
* @param y0 The y coordinate of one corner of the box. Measured as a
886+
* number of pixels from the top of the screen. The value increases
887+
* from 0 (top) to 63 (bottom).
888+
*
889+
* @param x1 The x coordinate of a corner diagonal from the first corner.
890+
*
891+
* @param y1 The y coordinate of the corner diagonal from the first corner.
892+
*
893+
* @param c The pixel color 1 for white, 0 for black.
894+
*/
895+
void boxFilled( int x0, int y0, int x1, int y1, int c);
896+
897+
/**
898+
* @brief Plot a triangle on the oLED screen.
899+
*
900+
* @param x0 The x coordinate of one corner of the triangle. Measured as a
901+
* number of pixels from left side of screen. The value increases
902+
* from 0 (left) to 127 (right).
903+
*
904+
* @param y0 The y coordinate of one corner of the triangle. Measured as a
905+
* number of pixels from the top of the screen. The value increases
906+
* from 0 (top) to 63 (bottom).
907+
*
908+
* @param x1 The x coordinate of the second corner.
909+
*
910+
* @param y1 The y coordinate of the second corner.
911+
*
912+
* @param x2 The x coordinate of the third corner.
913+
*
914+
* @param y2 The y coordinate of the third corner.
915+
*
916+
* @param c The pixel color 1 for white, 0 for black.
917+
*/
918+
void triangle( int x0, int y0, int x1, int y1, int x2, int y2, int c);
919+
920+
/**
921+
* @brief Plot a filled triangle on the oLED screen.
922+
*
923+
* @param x0 The x coordinate of one corner of the triangle. Measured as a
924+
* number of pixels from left side of screen. The value increases
925+
* from 0 (left) to 127 (right).
926+
*
927+
* @param y0 The y coordinate of one corner of the triangle. Measured as a
928+
* number of pixels from the top of the screen. The value increases
929+
* from 0 (top) to 63 (bottom).
930+
*
931+
* @param x1 The x coordinate of the second corner.
932+
*
933+
* @param y1 The y coordinate of the second corner.
934+
*
935+
* @param x2 The x coordinate of the third corner.
936+
*
937+
* @param y2 The y coordinate of the third corner.
938+
*
939+
* @param c The pixel color 1 for white, 0 for black.
940+
*/
941+
void triangleFilled( int x0, int y0, int x1, int y1, int x2, int y2, int c);
942+
943+
/**
944+
* @brief Plot a circle on the oLED screen.
945+
*
946+
* @param x0 The x coordinate of the center of the circle. Measured as a
947+
* number of pixels from left side of screen. The value increases
948+
* from 0 (left) to 127 (right).
949+
*
950+
* @param y0 The y coordinate of the center of the circle. Measured as a
951+
* number of pixels from the top of the screen. The value increases
952+
* from 0 (top) to 63 (bottom).
953+
*
954+
* @param r The radius of the circle.
955+
*
956+
* @param c The pixel color 1 for white, 0 for black.
957+
*/
958+
void circle( int x0, int y0, int r, int c);
959+
960+
/**
961+
* @brief Plot a filled circle on the oLED screen.
962+
*
963+
* @param x0 The x coordinate of the center of the circle. Measured as a
964+
* number of pixels from left side of screen. The value increases
965+
* from 0 (left) to 127 (right).
966+
*
967+
* @param y0 The y coordinate of the center of the circle. Measured as a
968+
* number of pixels from the top of the screen. The value increases
969+
* from 0 (top) to 63 (bottom).
970+
*
971+
* @param r The radius of the circle.
972+
*
973+
* @param c The pixel color 1 for white, 0 for black.
974+
*/
975+
void circleFilled( int x0, int y0, int r, int c);
976+
878977
/**
879978
* @brief Place a shape defined by a char array of pixels on the oLED
880979
* display. See 11 Shapes to Display.side for example.
3.03 KB
Binary file not shown.

Learn/Simple Libraries/Social/libbadgetools/html/badgetools_8h.html

Lines changed: 477 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Learn/Simple Libraries/Social/libbadgetools/html/badgetools_8h_source.html

Lines changed: 69 additions & 957 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Learn/Simple Libraries/Social/libbadgetools/libbadgetools.side

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ peb_stringView.c
100100
peb_text.c
101101
sscan_ct.c
102102
peb_irclear.c
103+
oled_circle.c
104+
oled_triangle.c
103105
>compiler=C
104106
>memtype=cmm main ram compact
105107
>optimize=-Os
15.5 KB
Binary file not shown.

Learn/Simple Libraries/Social/libbadgetools/oled_box.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ void box(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t c)
1414
if (self->AutoUpdate) screen_update();
1515
}
1616

17+
void boxFilled(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t c)
18+
{
19+
// Draw a box formed by the coordinates of a diagonal line
20+
if(y0 < y1) {
21+
int temp = y0;
22+
y0 = y1;
23+
y1 = temp;
24+
temp = x0;
25+
x0 = x1;
26+
x1 = temp;
27+
}
28+
for(int idx = y0; idx <= y1; idx++) line(x0, idx, x1, idx, c);
29+
if (self->AutoUpdate) screen_update();
30+
}
31+
1732
/*
1833
TERMS OF USE: MIT License
1934
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include <stdlib.h>
2+
#include <propeller.h>
3+
#include "badgetools.h"
4+
5+
volatile screen *self;
6+
7+
void circle(int32_t x0, int32_t y0, int32_t r, int32_t c)
8+
{
9+
int f = 1 - r;
10+
int ddF_x = 1;
11+
int ddF_y = -2 * r;
12+
int x = 0;
13+
int y = r;
14+
15+
point(x0 , y0 + r, c);
16+
point(x0 , y0 - r, c);
17+
point(x0 + r, y0 , c);
18+
point(x0 - r, y0 , c);
19+
20+
while (x < y)
21+
{
22+
if (f >= 0) {
23+
y--;
24+
ddF_y += 2;
25+
f += ddF_y;
26+
}
27+
x++;
28+
ddF_x += 2;
29+
f += ddF_x;
30+
31+
point(x0 + x, y0 + y, c);
32+
point(x0 - x, y0 + y, c);
33+
point(x0 + x, y0 - y, c);
34+
point(x0 - x, y0 - y, c);
35+
point(x0 + y, y0 + x, c);
36+
point(x0 - y, y0 + x, c);
37+
point(x0 + y, y0 - x, c);
38+
point(x0 - y, y0 - x, c);
39+
}
40+
if (self->AutoUpdate) screen_update();
41+
}
42+
43+
void circleFilled(int32_t x0, int32_t y0, int32_t r, int32_t c)
44+
{
45+
// Draw a box formed by the coordinates of a diagonal line
46+
line(x0, y0 - r, x0, y0 + r, c);
47+
48+
int f = 1 - r;
49+
int ddF_x = 1;
50+
int ddF_y = -2 * r;
51+
int x = 0;
52+
int y = r;
53+
54+
while (x < y)
55+
{
56+
if (f >= 0) {
57+
y--;
58+
ddF_y += 2;
59+
f += ddF_y;
60+
}
61+
x++;
62+
ddF_x += 2;
63+
f += ddF_x;
64+
65+
int yD = 2 * y + 1;
66+
int xD = 2 * x + 1;
67+
68+
//if(y0 - y + yD > _height) yD = _height - y0 + y;
69+
//if(y0 - y + xD > _height) xD = _height - y0 + y;
70+
71+
line(x0 + x, y0 - y, x0 + x, y0 - y + yD - 1, c);
72+
line(x0 + y, y0 - x, x0 + y, y0 - x + xD - 1, c);
73+
line(x0 - x, y0 - y, x0 - x, y0 - y + yD - 1, c);
74+
line(x0 - y, y0 - x, x0 - y, y0 - x + xD - 1, c);
75+
}
76+
77+
if (self->AutoUpdate) screen_update();
78+
}
79+
80+
/*
81+
TERMS OF USE: MIT License
82+
83+
Permission is hereby granted, free of charge, to any person obtaining a
84+
copy of this software and associated documentation files (the "Software"),
85+
to deal in the Software without restriction, including without limitation
86+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
87+
and/or sell copies of the Software, and to permit persons to whom the
88+
Software is furnished to do so, subject to the following conditions:
89+
90+
The above copyright notice and this permission notice shall be included in
91+
all copies or substantial portions of the Software.
92+
93+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
94+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
95+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
96+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
97+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
98+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
99+
DEALINGS IN THE SOFTWARE.
100+
*/
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#include <stdlib.h>
2+
#include <propeller.h>
3+
#include "badgetools.h"
4+
5+
volatile screen *self;
6+
7+
void triangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t c)
8+
{
9+
// connect the dots, laa la la laaa! :)
10+
line(x0, y0, x1, y1, c);
11+
line(x1, y1, x2, y2, c);
12+
line(x2, y2, x0, y0, c);
13+
if (self->AutoUpdate) screen_update();
14+
}
15+
16+
void triangleFilled(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t c)
17+
{
18+
// Draw a box formed by the coordinates of a diagonal line
19+
int a, b, y, last;
20+
21+
// Sort coordinates by Y order (y2 >= y1 >= y0)
22+
if (y0 > y1) {
23+
screen_swap(y0, y1); screen_swap(x0, x1);
24+
}
25+
if (y1 > y2) {
26+
screen_swap(y2, y1); screen_swap(x2, x1);
27+
}
28+
if (y0 > y1) {
29+
screen_swap(y0, y1); screen_swap(x0, x1);
30+
}
31+
32+
if (y0 == y2) { // Handle awkward all-on-same-line case as its own thing
33+
a = b = x0;
34+
if (x1 < a) a = x1;
35+
else if (x1 > b) b = x1;
36+
if (x2 < a) a = x2;
37+
else if (x2 > b) b = x2;
38+
line(a, y0, b, y0, c);
39+
return;
40+
}
41+
42+
int
43+
dx01 = x1 - x0,
44+
dy01 = y1 - y0,
45+
dx02 = x2 - x0,
46+
dy02 = y2 - y0,
47+
dx12 = x2 - x1,
48+
dy12 = y2 - y1,
49+
sa = 0,
50+
sb = 0;
51+
52+
// For upper part of triangle, find scanline crossings for segments
53+
// 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1
54+
// is included here (and second loop will be skipped, avoiding a /0
55+
// error there), otherwise scanline y1 is skipped here and handled
56+
// in the second loop...which also avoids a /0 error here if y0=y1
57+
// (flat-topped triangle).
58+
if (y1 == y2) last = y1; // Include y1 scanline
59+
else last = y1 - 1; // Skip it
60+
61+
for (y = y0; y <= last; y++) {
62+
a = x0 + sa / dy01;
63+
b = x0 + sb / dy02;
64+
sa += dx01;
65+
sb += dx02;
66+
67+
if (a > b) screen_swap(a, b);
68+
line(a, y, b, y, c);
69+
}
70+
71+
// For lower part of triangle, find scanline crossings for segments
72+
// 0-2 and 1-2. This loop is skipped if y1=y2.
73+
sa = dx12 * (y - y1);
74+
sb = dx02 * (y - y0);
75+
for (; y <= y2; y++) {
76+
a = x1 + sa / dy12;
77+
b = x0 + sb / dy02;
78+
sa += dx12;
79+
sb += dx02;
80+
81+
if (a > b) screen_swap(a, b);
82+
line(a, y, b, y, c);
83+
}
84+
85+
if (self->AutoUpdate) screen_update();
86+
}
87+
88+
/*
89+
TERMS OF USE: MIT License
90+
91+
Permission is hereby granted, free of charge, to any person obtaining a
92+
copy of this software and associated documentation files (the "Software"),
93+
to deal in the Software without restriction, including without limitation
94+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
95+
and/or sell copies of the Software, and to permit persons to whom the
96+
Software is furnished to do so, subject to the following conditions:
97+
98+
The above copyright notice and this permission notice shall be included in
99+
all copies or substantial portions of the Software.
100+
101+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
102+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
103+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
104+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
105+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
106+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
107+
DEALINGS IN THE SOFTWARE.
108+
*/

0 commit comments

Comments
 (0)