basic blob
This commit is contained in:
parent
50de931e8a
commit
91c1bc50f3
@ -41,6 +41,15 @@ int end_y = 27;
|
||||
int anchor_x = 16;
|
||||
int anchor_y = 24;
|
||||
|
||||
#define BLOB_POINTS 14
|
||||
#define BLOB_RADIUS 12
|
||||
typedef struct {
|
||||
int x_coords[BLOB_POINTS];
|
||||
int y_coords[BLOB_POINTS];
|
||||
} Blob;
|
||||
|
||||
Blob blob;
|
||||
|
||||
void setup(){
|
||||
Serial.begin(BAUD_RATE);
|
||||
pinMode(ONBOARD_LED, OUTPUT);
|
||||
@ -62,6 +71,15 @@ void setup(){
|
||||
matrix->begin();
|
||||
matrix->setBrightness8(64);
|
||||
matrix->fillScreenRGB888(0, 0, 0);
|
||||
|
||||
for(int i = 0; i < BLOB_POINTS; i++) {
|
||||
//float angle = (360 / BLOB_POINTS) * (i+1);
|
||||
float angle = ((PI * 2) / BLOB_POINTS) * (i+1);
|
||||
blob.x_coords[i] = random(-6, 7) + 31 + round(BLOB_RADIUS * sin(angle));
|
||||
blob.y_coords[i] = random(-2, 7) + 15 + round(BLOB_RADIUS * cos(angle));
|
||||
//blob.x_coords[i] = random(0, 64);
|
||||
//blob.y_coords[i] = random(0, 32);
|
||||
}
|
||||
}
|
||||
|
||||
int interpolate(int from, int to, float percent) {
|
||||
@ -69,11 +87,12 @@ int interpolate(int from, int to, float percent) {
|
||||
return from + ( difference * percent );
|
||||
}
|
||||
|
||||
void draw_bezier(int x1, int y1, int x2, int y2, int x3, int y3, float percent) {
|
||||
void draw_bezier(int x1, int y1, int x2, int y2, int x3, int y3) {
|
||||
// draw lines to p2
|
||||
matrix->drawLine(x1, y1, x2, y2, matrix->color565(16, 16, 16));
|
||||
matrix->drawLine(x2, y2, x3, y3, matrix->color565(16, 16, 16));
|
||||
//matrix->drawLine(x1, y1, x2, y2, matrix->color565(16, 16, 16));
|
||||
//matrix->drawLine(x2, y2, x3, y3, matrix->color565(16, 16, 16));
|
||||
|
||||
for (float percent = 0; percent < 1; percent += 0.02) {
|
||||
int xa = interpolate(x1, x2, percent);
|
||||
int ya = interpolate(y1, y2, percent);
|
||||
int xb = interpolate(x2, x3, percent);
|
||||
@ -83,23 +102,46 @@ void draw_bezier(int x1, int y1, int x2, int y2, int x3, int y3, float percent)
|
||||
int x = interpolate(xa, xb, percent);
|
||||
int y = interpolate(ya, yb, percent);
|
||||
|
||||
matrix->drawPixel(x, y, matrix->color565(255, 255, 255));
|
||||
matrix->drawPixel(x, y, matrix->color565(255, 80, 83));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loop() {
|
||||
// matrix ->flipDMABuffer();
|
||||
matrix->clearScreen();
|
||||
// delay(25);
|
||||
anchor_y += 1;
|
||||
if (anchor_y >= 32) {
|
||||
anchor_y = 0;
|
||||
//matrix->clearScreen();
|
||||
matrix->fillScreenRGB888(15, 0, 10);
|
||||
// draw grid
|
||||
|
||||
int h_lines = PANEL_HEIGHT / 7;
|
||||
int v_lines = PANEL_WIDTH / 7;
|
||||
for(int i = 0; i < PANEL_WIDTH; i++) {
|
||||
if(i % 7 == 2) {
|
||||
matrix->drawFastVLine(i, 0, PANEL_HEIGHT, matrix->color565(41, 17, 76));
|
||||
}
|
||||
for (float i = 0; i < 1; i += 0.02) {
|
||||
draw_bezier(start_x, start_y, anchor_x, anchor_y, end_x, end_y, i);
|
||||
}
|
||||
matrix->drawPixel(start_x, start_y, matrix->color565(255, 0, 0));
|
||||
matrix->drawPixel(end_x, end_y, matrix->color565(255, 0, 0));
|
||||
matrix->drawPixel(anchor_x, anchor_y, matrix->color565(255, 0, 255));
|
||||
delay(100);
|
||||
for(int i = 0; i <= h_lines; i++) {
|
||||
matrix->drawFastHLine(0, 7*i + 1, PANEL_WIDTH, matrix->color565(41, 17, 76));
|
||||
}
|
||||
|
||||
for(int i = 0; i < BLOB_POINTS; i+=2) {
|
||||
int end_offset = i + 2;
|
||||
if ( end_offset >= BLOB_POINTS) {
|
||||
end_offset = 0;
|
||||
}
|
||||
draw_bezier(blob.x_coords[i],
|
||||
blob.y_coords[i],
|
||||
blob.x_coords[i+1],
|
||||
blob.y_coords[i+1],
|
||||
blob.x_coords[end_offset],
|
||||
blob.y_coords[end_offset]
|
||||
);
|
||||
matrix->drawPixel(blob.x_coords[i], blob.y_coords[i], matrix->color565(128, 128, 128));
|
||||
//matrix->drawPixel(blob.x_coords[i], blob.y_coords[i], matrix->color565(0, 0, 128));
|
||||
//matrix->drawPixel(blob.x_coords[i+1], blob.y_coords[i+1], matrix->color565(128, 0, 0));
|
||||
//matrix->drawPixel(blob.x_coords[end_offset], blob.y_coords[end_offset], matrix->color565(0, 0, 128));
|
||||
}
|
||||
delay(500);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user