I drew a smiley face!
-
After a ton of work hacking away at plutovg and integrating its functionality, I came up with this API
using color_t = color;
const int width = 80;
const int height = 80;
bmp = create_bitmap(size16(width,height));
bmp.fill(bmp.bounds(),color_t::blue);
float center_x = width / 2.f;
float center_y = height / 2.f;
float face_radius = 35;
float eye_radius = 5;
float mouth_radius = 25;
float eye_offset_x = 12;
float eye_offset_y = 10;
float eye_x = center_x - eye_offset_x;
float eye_y = center_y - eye_offset_y;
canvas c(size16(width,height));
c.on_write_callback([](const rect16& bounds, rgba_pixel<32> color, void* state){
return bmp.fill(bounds,color);
});
c.on_read_callback([](point16 location,rgba_pixel<32>* out_color, void* state){
return bmp.point(location,out_color);
});
c.initialize();
c.arc({center_x,center_y},face_radius,0,math::two_pi,0);
c.fill_color(color_t::yellow);
c.stroke_color(color_t::black);
canvas_stroke_style style = c.stroke_style();
style.width = 5;
c.stroke_style(style);
c.render();
c.arc({eye_x,eye_y},eye_radius,0,math::two_pi,false);
c.arc(pointf(eye_offset_x+center_x,eye_y),eye_radius,0,math::two_pi,false);
c.stroke_paint_type(canvas_paint_type::none);
c.fill_color(color_t::black);
c.render();
c.arc({center_x,center_y},mouth_radius,0,math::pi,0);
c.fill_paint_type(canvas_paint_type::none);
c.render();
print_ascii(bmp);
free(bmp.begin());This draws a smiley face, all pretty and anti-aliased. Unfortunately it's more complicated to use than I'd like owing to all the capabilities and options. Either way, I'm thrilled to have gotten this far. I had to gut plutovg, and I'll probably do more.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix