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. Woohoo! My vector canvas is performing better than my old one

Woohoo! My vector canvas is performing better than my old one

Scheduled Pinned Locked Moved The Lounge
graphicsdata-structuresperformanceannouncement
3 Posts 2 Posters 2 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

    gfx 2.0 vector canvas performance test - YouTube[^] 22 frames per second on an ESP32 WROVER based M5 Stack Core2 @ 320x240 (clock is 128x128) mem usage: 34.66KB code (forgive the lengthy paste, but I wanted to give a good idea of how much it was doing per frame, and what that looks like)

    tbmp.fill(tbmp.bounds(),color_t::white);

    pointf offset(0, 0);
    pointf center(0, 0);
    time_t time = current_time;
    float rotation(0);
    float ctheta, stheta;
    ssize16 size = (ssize16)clock_canvas.dimensions();
    rectf b = gfx::sizef(size.width, size.height).bounds();
    b.inflate_inplace(-face_border_width - 1, -face_border_width - 1);
    float w = b.width();
    float h = b.height();
    if(w>h) w= h;
    rectf sr(0, w / 30, w / 30, w / 5);
    sr.center_horizontal_inplace(b);
    center = gfx::pointf(w * 0.5f + face_border_width + 1, w * 0.5f + face_border_width + 1);
    clock_canvas.fill_color(face_color);
    clock_canvas.stroke_color(face_border_color);
    clock_canvas.stroke_width(face_border_width);

    clock_canvas.ellipse(center, {center.x - 1, center.x - 1});
    clock_canvas.render();

    bool toggle = false;
    clock_canvas.stroke_color(tick_border_color);
    clock_canvas.fill_color(tick_color);
    clock_canvas.stroke_width(tick_border_width);

    for (float rot = 0; rot < 360.0f; rot += rot_step) {
    rotation = rot;
    update_transform(rotation, ctheta, stheta);
    toggle = !toggle;
    if (toggle) {
    clock_canvas.move_to(translate(ctheta, stheta, center, offset, sr.x1, sr.y1));
    clock_canvas.line_to(translate(ctheta, stheta, center, offset, sr.x2, sr.y1));
    clock_canvas.line_to(translate(ctheta, stheta, center, offset, sr.x2, sr.y2));
    clock_canvas.line_to(translate(ctheta, stheta, center, offset, sr.x1, sr.y2));

    } else {
        clock\_canvas.move\_to(translate(ctheta, stheta, center, offset, sr.x1, sr.y1));
        clock\_canvas.line\_to(translate(ctheta, stheta, center, offset, sr.x2, sr.y1));
        clock\_canvas.line\_to(translate(ctheta, stheta, center, offset, sr.x2, sr.y2 - sr.height() \* 0.5f));
        clock\_canvas.line\_to(translate(ctheta, stheta, center, offset, sr.x1, sr.y2 - sr.height() \* 0.5f));
    }
    clock\_canvas.render();
    

    }
    sr = gfx::rectf(0, w / 40, w / 16, w / 2);
    sr.center_horizontal_inplace(b);
    rotation = (fmodf(time / 60.0f, 60) / 60.0f) * 360.0f;
    update_transform(rotation, ctheta, stheta);
    clock_canvas.move_to(translate(cthe

    M 1 Reply Last reply
    0
    • H honey the codewitch

      gfx 2.0 vector canvas performance test - YouTube[^] 22 frames per second on an ESP32 WROVER based M5 Stack Core2 @ 320x240 (clock is 128x128) mem usage: 34.66KB code (forgive the lengthy paste, but I wanted to give a good idea of how much it was doing per frame, and what that looks like)

      tbmp.fill(tbmp.bounds(),color_t::white);

      pointf offset(0, 0);
      pointf center(0, 0);
      time_t time = current_time;
      float rotation(0);
      float ctheta, stheta;
      ssize16 size = (ssize16)clock_canvas.dimensions();
      rectf b = gfx::sizef(size.width, size.height).bounds();
      b.inflate_inplace(-face_border_width - 1, -face_border_width - 1);
      float w = b.width();
      float h = b.height();
      if(w>h) w= h;
      rectf sr(0, w / 30, w / 30, w / 5);
      sr.center_horizontal_inplace(b);
      center = gfx::pointf(w * 0.5f + face_border_width + 1, w * 0.5f + face_border_width + 1);
      clock_canvas.fill_color(face_color);
      clock_canvas.stroke_color(face_border_color);
      clock_canvas.stroke_width(face_border_width);

      clock_canvas.ellipse(center, {center.x - 1, center.x - 1});
      clock_canvas.render();

      bool toggle = false;
      clock_canvas.stroke_color(tick_border_color);
      clock_canvas.fill_color(tick_color);
      clock_canvas.stroke_width(tick_border_width);

      for (float rot = 0; rot < 360.0f; rot += rot_step) {
      rotation = rot;
      update_transform(rotation, ctheta, stheta);
      toggle = !toggle;
      if (toggle) {
      clock_canvas.move_to(translate(ctheta, stheta, center, offset, sr.x1, sr.y1));
      clock_canvas.line_to(translate(ctheta, stheta, center, offset, sr.x2, sr.y1));
      clock_canvas.line_to(translate(ctheta, stheta, center, offset, sr.x2, sr.y2));
      clock_canvas.line_to(translate(ctheta, stheta, center, offset, sr.x1, sr.y2));

      } else {
          clock\_canvas.move\_to(translate(ctheta, stheta, center, offset, sr.x1, sr.y1));
          clock\_canvas.line\_to(translate(ctheta, stheta, center, offset, sr.x2, sr.y1));
          clock\_canvas.line\_to(translate(ctheta, stheta, center, offset, sr.x2, sr.y2 - sr.height() \* 0.5f));
          clock\_canvas.line\_to(translate(ctheta, stheta, center, offset, sr.x1, sr.y2 - sr.height() \* 0.5f));
      }
      clock\_canvas.render();
      

      }
      sr = gfx::rectf(0, w / 40, w / 16, w / 2);
      sr.center_horizontal_inplace(b);
      rotation = (fmodf(time / 60.0f, 60) / 60.0f) * 360.0f;
      update_transform(rotation, ctheta, stheta);
      clock_canvas.move_to(translate(cthe

      M Offline
      M Offline
      megaadam
      wrote on last edited by
      #2

      Stunning performance on such hardware! Very nice. why ((time % 60) / 60.0f) * 360.0f though? I daresay (59 / 60.0f) * 360.0f == 59 * 60.0f == 354.0f Most compilers will of course see this...

      "If we don't change direction, we'll end up where we're going"

      H 1 Reply Last reply
      0
      • M megaadam

        Stunning performance on such hardware! Very nice. why ((time % 60) / 60.0f) * 360.0f though? I daresay (59 / 60.0f) * 360.0f == 59 * 60.0f == 354.0f Most compilers will of course see this...

        "If we don't change direction, we'll end up where we're going"

        H Offline
        H Offline
        honey the codewitch
        wrote on last edited by
        #3

        Probably because it accurately computes the angle I'm looking for. I'm not sure your code does. Edit: I see it now. I literally copied and pasted these sections of code and modified. That's why.

        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