Last active
December 4, 2025 14:35
-
-
Save suarezvictor/c322e58dd731a40f5a4fd87557a86e3d to your computer and use it in GitHub Desktop.
OSHW logo animation example
This file contains hidden or 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
| // This file is Copyright (c) 2025 Victor Suarez Rovere <[email protected]> | |
| // SPDX-License-Identifier: AGPL-3.0-only | |
| #include "misc.h" | |
| #include "processing_api.h" | |
| using namespace processing; | |
| PGraphics canvas; | |
| PImage background; | |
| PFont font; | |
| const int ANIM_FRAMES = 24; | |
| void setup() | |
| { | |
| println("load images and fonts..."); | |
| background = createImage("pcb.bmp"); | |
| font = createFont("NovaMono-OpenHardwareLogo.ttf", 100); | |
| } | |
| void draw_frame(int frame) | |
| { | |
| canvas.image(background, 0, 0); | |
| canvas.fill(SHADOW); | |
| draw_gear(canvas.width/2+15, canvas.height/2.1+15, canvas.height/2.5, frame+1); | |
| canvas.fill(0x07, 0x0f, 0x3b, 240); | |
| canvas.lastshape(-15, -15); | |
| canvas.fill(0x07, 0x0f, 0x3b, 240); | |
| canvas.textFont(font); | |
| canvas.text("open hardware", canvas.width/4, canvas.height-11); | |
| } | |
| void draw_gear(int cx, int cy, int radius, unsigned rotation) | |
| { | |
| float r_outer = radius*.75, r_inner = radius*.28; | |
| float start = radians(112), end = radians(360+68); | |
| canvas.beginShape(); | |
| PGraphics::path_t& path = canvas.lastshape(); | |
| agg::bezier_arc inner_arc(cx, cy, r_inner, r_inner, end, start - end); | |
| path.concat_path(inner_arc); | |
| const unsigned steps = ANIM_FRAMES/6; //set angular resolution | |
| for(unsigned i = steps*3; i <= steps*(8*6-3); ++i) | |
| { | |
| unsigned a = (steps*8*6-i+rotation) % (steps*6); | |
| if(a == steps || a == steps*5 || i == steps*(8*6-3)); | |
| else if(a == steps*2 || a == steps*4 || i == steps*3); | |
| else continue; | |
| float u = (a < steps*2 || a > steps*4); | |
| if(rotation) | |
| { | |
| const int b = 6; | |
| if(i <= steps*(3+b)) | |
| u *= float(i-steps*3)/(steps*b); | |
| if(i >= steps*(8*6-3-b)) | |
| u *= float(steps*(8*6-3)-i)/(steps*b); | |
| } | |
| float r = radius*u+r_outer*(1-u); | |
| float w = 2*i*M_PI/(steps*8*6); | |
| canvas.vertex(cx - r*sin(w), cy+r*cos(w)); //line_to | |
| } | |
| canvas.endShape(CLOSE); | |
| } | |
| void draw() | |
| { | |
| static int frame = 0; | |
| draw_frame(frame); | |
| if(++frame == ANIM_FRAMES) | |
| frame = 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment