Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. I drew a smiley face!

I drew a smiley face!

Scheduled Pinned Locked Moved The Lounge
designcomgraphicsiotjson
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    honey the codewitch
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups