Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
168 lines (149 sloc)
6.61 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <EEPROM.h> | |
#include <SPI.h> | |
#include <GD2.h> | |
#define PYTHAG_HANDLE 0 | |
#define GAUSS_HANDLE 1 | |
#define ASSETS_END 1024UL | |
static const PROGMEM uint8_t __assets[927] = { | |
0, 0, 0, 5, 0, 0, 0, 1, 1, 0, 0, 8, 1, 0, 28, 7, 1, 0, 0, 5, 0, 2, 0, | |
1, 1, 0, 0, 8, 1, 0, 28, 7, 34, 255, 255, 255, 0, 0, 0, 0, 120, 218, | |
99, 96, 96, 100, 98, 102, 97, 101, 99, 231, 224, 228, 226, 230, 225, | |
229, 227, 23, 16, 20, 18, 22, 17, 21, 21, 19, 151, 144, 148, 146, 150, | |
145, 149, 149, 147, 87, 80, 84, 82, 86, 86, 81, 85, 83, 215, 208, 208, | |
212, 210, 214, 209, 213, 213, 211, 55, 48, 48, 52, 50, 54, 49, 49, 53, | |
51, 55, 183, 176, 180, 178, 178, 182, 177, 181, 181, 179, 183, 119, | |
112, 116, 116, 114, 118, 113, 113, 117, 115, 115, 247, 240, 240, 244, | |
242, 242, 246, 246, 241, 245, 245, 243, 247, 15, 8, 8, 12, 10, 10, 14, | |
14, 9, 13, 13, 11, 11, 15, 143, 136, 136, 140, 138, 138, 142, 142, | |
137, 137, 141, 141, 139, 139, 143, 79, 72, 72, 76, 76, 74, 74, 78, 78, | |
73, 73, 73, 77, 77, 75, 75, 79, 207, 200, 200, 200, 204, 204, 202, | |
202, 202, 206, 206, 201, 201, 201, 205, 205, 203, 203, 203, 207, 207, | |
47, 40, 40, 40, 44, 44, 44, 42, 42, 42, 46, 46, 46, 1, 130, 210, 210, | |
210, 50, 32, 40, 7, 130, 10, 32, 168, 4, 129, 42, 16, 168, 6, 131, 26, | |
48, 168, 133, 130, 58, 36, 80, 79, 0, 32, 171, 133, 233, 135, 152, 6, | |
49, 25, 108, 9, 216, 58, 144, 189, 32, 251, 65, 238, 0, 58, 7, 228, | |
42, 160, 227, 128, 78, 4, 58, 20, 232, 92, 160, 163, 129, 78, 207, | |
205, 5, 122, 34, 59, 27, 232, 157, 204, 76, 160, 199, 210, 211, 211, | |
210, 82, 83, 129, 94, 77, 78, 78, 74, 74, 76, 76, 72, 136, 143, 143, | |
139, 139, 141, 141, 137, 137, 142, 142, 138, 138, 140, 136, 8, 15, 15, | |
11, 11, 13, 13, 9, 14, 14, 10, 10, 12, 8, 240, 247, 247, 243, 245, | |
245, 241, 246, 246, 242, 242, 244, 240, 112, 119, 115, 115, 117, 113, | |
113, 118, 114, 116, 116, 176, 183, 183, 179, 181, 181, 177, 182, 178, | |
178, 180, 48, 55, 55, 51, 53, 49, 49, 54, 50, 52, 48, 208, 215, 211, | |
213, 213, 209, 214, 210, 212, 208, 80, 87, 83, 85, 81, 86, 86, 82, 84, | |
144, 151, 147, 149, 149, 145, 150, 146, 148, 16, 23, 19, 21, 21, 17, | |
22, 18, 20, 224, 231, 227, 229, 225, 230, 226, 228, 96, 103, 99, 101, | |
97, 102, 98, 100, 96, 136, 141, 3, 197, 0, 40, 252, 65, 129, 15, 10, | |
249, 108, 80, 160, 231, 3, 131, 187, 168, 24, 24, 204, 101, 229, 192, | |
192, 173, 170, 174, 1, 6, 98, 125, 67, 99, 83, 115, 115, 75, 107, 91, | |
123, 71, 71, 103, 87, 119, 79, 111, 111, 95, 255, 132, 137, 147, 38, | |
79, 158, 50, 117, 218, 244, 25, 51, 103, 206, 154, 61, 103, 238, 188, | |
249, 243, 23, 44, 92, 180, 120, 201, 210, 165, 203, 150, 175, 88, 185, | |
106, 245, 234, 53, 107, 215, 173, 223, 176, 97, 227, 166, 205, 91, | |
182, 110, 221, 182, 125, 199, 206, 93, 187, 118, 239, 217, 187, 111, | |
223, 254, 3, 7, 15, 29, 58, 124, 228, 232, 177, 99, 199, 79, 156, 60, | |
121, 234, 244, 153, 51, 103, 207, 157, 63, 127, 225, 226, 165, 75, | |
151, 175, 92, 185, 122, 237, 250, 245, 27, 55, 111, 222, 186, 125, | |
251, 206, 221, 187, 247, 238, 223, 127, 240, 224, 225, 163, 71, 143, | |
31, 63, 121, 250, 244, 217, 179, 231, 47, 94, 188, 124, 249, 234, 213, | |
235, 215, 111, 222, 188, 125, 251, 238, 221, 251, 247, 31, 62, 124, | |
252, 248, 241, 211, 167, 207, 159, 191, 124, 249, 242, 245, 235, 215, | |
111, 223, 190, 127, 255, 254, 3, 8, 126, 254, 252, 249, 11, 8, 126, 3, | |
193, 31, 16, 248, 11, 1, 255, 80, 193, 255, 255, 104, 2, 80, 101, 96, | |
45, 32, 189, 32, 51, 128, 70, 129, 76, 4, 26, 252, 237, 27, 208, 10, | |
160, 69, 159, 63, 127, 250, 4, 180, 246, 195, 135, 247, 239, 223, 189, | |
123, 251, 246, 205, 155, 215, 175, 95, 189, 122, 249, 242, 197, 139, | |
231, 207, 158, 61, 125, 250, 228, 241, 227, 71, 143, 30, 62, 120, 112, | |
255, 254, 189, 187, 119, 239, 220, 190, 125, 235, 230, 205, 27, 215, | |
175, 95, 187, 122, 229, 202, 229, 75, 151, 46, 94, 56, 127, 254, 220, | |
217, 51, 103, 78, 159, 58, 121, 242, 196, 241, 99, 199, 142, 30, 57, | |
124, 232, 208, 193, 3, 251, 247, 237, 219, 187, 103, 247, 174, 93, 59, | |
119, 108, 223, 182, 117, 235, 150, 205, 155, 54, 110, 216, 176, 126, | |
221, 218, 53, 171, 87, 175, 90, 185, 98, 249, 178, 165, 75, 151, 44, | |
94, 180, 112, 193, 252, 249, 243, 230, 206, 153, 61, 107, 230, 204, | |
25, 211, 167, 77, 157, 50, 121, 242, 164, 137, 19, 250, 251, 122, 123, | |
123, 186, 187, 58, 59, 58, 218, 219, 90, 91, 154, 155, 155, 26, 27, | |
128, 137, 184, 182, 166, 26, 152, 74, 43, 202, 129, 41, 179, 164, 24, | |
152, 34, 11, 242, 65, 73, 49, 27, 148, 10, 65, 73, 16, 148, 254, 64, | |
169, 47, 46, 22, 0, 212, 3, 36, 81 | |
}; | |
#define LOAD_ASSETS() (GD.copy(__assets, sizeof(__assets)), GD.loadptr = ASSETS_END) | |
void setup() | |
{ | |
GD.begin(); | |
LOAD_ASSETS(); | |
GD.BitmapHandle(PYTHAG_HANDLE); | |
GD.BitmapSize(BILINEAR, REPEAT, REPEAT, GD.w, GD.h); | |
GD.BitmapHandle(GAUSS_HANDLE); | |
GD.BitmapSize(BILINEAR, REPEAT, REPEAT, GD.w, GD.h); | |
} | |
// Set the bitmap transform for horizonal (dir=0) or vertical (dir=1) | |
void align(int dir, int w, int h) | |
{ | |
GD.cmd32(0xffffff21UL); // bitmap transform | |
GD.cmd32( 0); GD.cmd32( 0); | |
GD.cmd32( w); GD.cmd32( 0); | |
GD.cmd32( 0); GD.cmd32( h); | |
GD.cmd32(0); GD.cmd32(0); | |
if (dir == 0) { | |
GD.cmd32(511); GD.cmd32(0); | |
GD.cmd32(0); GD.cmd32(511); | |
} else { | |
GD.cmd32(0); GD.cmd32(511); | |
GD.cmd32(511); GD.cmd32(0); | |
} | |
GD.cmd32(0); | |
} | |
void circular(int x0, int y0, | |
int x1, int y1, | |
uint32_t c0, uint32_t c1) | |
{ | |
int handle = GAUSS_HANDLE; | |
GD.SaveContext(); | |
GD.Begin(BITMAPS); | |
int w = x1 - x0; | |
int h = y1 - y0; | |
GD.ScissorXY(x0, y0); | |
GD.ScissorSize(w, h); | |
GD.ColorMask(0, 0, 0, 1); // Only touch the alpha channel | |
GD.BitmapHandle(handle); | |
GD.BlendFunc(ONE, ZERO); // Draw the X bitmap into alpha | |
align(0, w, h); | |
GD.Vertex2f(PIXELS(x0), PIXELS(y0)); | |
if (handle == PYTHAG_HANDLE) | |
GD.BlendFunc(ONE, ONE); // For pythagorean, want alpha addition | |
else | |
GD.BlendFunc(DST_ALPHA, ZERO); // But for Gaussian, multiplication | |
align(1, w, h); // Blend the Y bitmap into alpha | |
GD.Vertex2f(PIXELS(x0), PIXELS(y0)); | |
GD.ColorMask(1, 1, 1, 0); // Now use the alpha buffer | |
GD.Begin(RECTS); | |
GD.ColorRGB(c0); | |
GD.BlendFunc(ONE, ZERO); | |
GD.Vertex2f(PIXELS(x0), PIXELS(y0)); | |
GD.Vertex2f(PIXELS(x1), PIXELS(y1)); | |
GD.ColorRGB(c1); | |
GD.BlendFunc(DST_ALPHA, ONE_MINUS_DST_ALPHA); | |
GD.Vertex2f(PIXELS(x0), PIXELS(y0)); | |
GD.Vertex2f(PIXELS(x1), PIXELS(y1)); | |
GD.RestoreContext(); | |
} | |
uint32_t rand32() | |
{ | |
return ((uint32_t)GD.random() << 16) ^ GD.random(); | |
} | |
void loop1() | |
{ | |
GD.Clear(); | |
for (int y = 0; y < GD.h; y += 55) | |
for (int x = 0; x < GD.w; x += 96) | |
circular(x, y, x + 90, y + 50, rand32(), rand32()); | |
GD.swap(); | |
} | |
void loop2() | |
{ | |
circular(0, 0, GD.w, GD.h, 0x772b55, 0xef8619); | |
GD.cmd_text(GD.w / 2, GD.h / 2, 31, OPT_CENTER, "Hello world"); | |
GD.swap(); | |
} | |
void loop() { loop2(); } |