8 comments

  • nicoburns 8 hours ago
    The list of "recommended reading" from one of the issues looks great:

    https://github.com/a-e-k/canvas_ity/issues/11#issuecomment-2...

  • a_e_k 2 hours ago
    Author here. What a pleasant surprise to see this trending on the front page!

    (I did post a Show HN at the time of the original release, https://news.ycombinator.com/item?id=33148540, but it never gained traction.)

    Just to answer some comments that I see:

    1. This was absolutely not vibecoded!

    I'd originally started with a different version control system and was still getting used to Git and GitHub at the time that I'd released this. (I was a latecomer to Git just because I hated the CLI so much.) It was easiest for me just to drop the whole thing as a snapshot in a single commit.

    But my private repo for it actually started in May 2017, and it had 320 commits leading up to its release, all human-written.

    For the v2.0 that I have in mind, I'm thinking of force-pushing to migrate the full development history to the public repo.

    And finally I'll add that I'm a graphics engineer by education and career. Where would the fun be in vibe-coding this? :-) Oh, and this compiles down to just ~36KiB of object code on x86-64 last I checked. Good luck vibe-coding that constraint.

    2. Why a single header with `#define CANVAS_ITY_IMPLEMENTATION`?

    I was inspired by the STB header ibraries (https://github.com/nothings/stb) and by libraries inspired by those, all of which I've found very convenient. In particular, I like their convenience for small utilities written in a single .cpp file where I can just `g++ -O3 -o prog prog.cpp` or such to compile without even bothering with a makefile or CMake.

    Since the implementation here is all within a single #ifdef block, I had figured that anyone who truly preferred separate .cpp and .h files could easily split it themselves in just a few minutes.

    But anyway, I thought this would be a fun way of "giving back" to the STB header ecosystem and filling what looked to me like an obvious gap among the available header libraries. It started as something that I'd wished I'd had before, for doing some lightweight drawing on top of images, and it just kind of grew from there. (Yes, there was Skia and Cairo, but both seemed way heavier weight than they ought to be, and even just building Skia was an annoying chore.)

    ----

    Since I mentioned a v2.0, I do have a roadmap in mind with a few things for it: beside the small upgrades mentioned in the GitHub issues to support parts of newer <canvas> API specs (alternate fill rules, conic gradients, elliptical arcs, round rectangles) and text kerning, I'm thinking about porting it to a newer C++ standard such as C++20 (I intentionally limited v1.0 to C++03 so that it could be used in as many places as possible), possibly including a small optional library on top of it to parse and rasterize a subset of SVG, and an optional Python binding.

  • msephton 6 hours ago
    The project is great. The HN comments are embarrassing. Isn’t it ironic to imply laziness by chiming in with “vibe coded” which in itself is such a lazy reaction.
  • PaulDavisThe1st 4 hours ago
    And thus random 2D drawing APIs begat Cairo, and then Cairo begat the Canvas, and thus the Canvas begat Canvas_ity, which looked almost like it's grandparent, and yet was very much it's own self.
  • Lerc 7 hours ago
    It would be interesting to compile to WASM to compare side by side for performance and accuracy.
    • a_e_k 2 hours ago
      Author here. I have a JavaScript port of my automated test suite (https://github.com/a-e-k/canvas_ity/blob/main/test/test.html) that I used to compare my library against browser <canvas> implementations. I was surprised by all of the browser quirks that I found!

      But compiling to WASM and running side-by-side on that page is definitely something that I've thought about to make the comparison easier. (For now, I just have my test suite write out PNGs and compare them in an image viewer split-screen with the browser.)

  • ddtaylor 6 hours ago
    Thank you for sharing. The only thing I don't understand why this is a header only implementation with a macro that goes in a C++ file.

        #define CANVAS_ITY_IMPLEMENTATION
    • erwincoumans 5 hours ago
      It is common for header-only libraries: you need to include this header in one c++ using the macro for linking (don't use that macro in other c++ files to avoid duplicate symbols). In C++, you can declare a function as many times as you want, but you can only define it (write the actual body) once in the entire project.
      • ddtaylor 4 hours ago
        I understand that part, but I don't see why do this instead of basic Makefile or CMake setup. It seems like more work than a regular linker at that point. For what purpose?
        • elteto 4 hours ago
          Because not everyone is using Makefiles or CMake.

          A true header-only library should be build-system agnostic and this is one way to do that.

          We can argue about build systems for C++ all day long and never come to an agreement. With this approach this piece of code can be used anywhere.

    • socalgal2 6 hours ago
      that's a common pattern in C++ land because there is no standard way to use libraries in C++

      https://github.com/p-ranav/awesome-hpp

  • taminka 4 hours ago
    i swear if someone starts another single header vs other options debate in this comment section i'm gonna explode
  • ranger_danger 8 hours ago
    vibe-coded?
    • nicoburns 8 hours ago
      Most likely not seeing as the commit containing the bulk of the implementation dropped in 2022.
      • ranger_danger 8 hours ago
        maybe just the README then
        • a_e_k 2 hours ago
          Author here. No vibe-coding, all human-written. Are you thinking of my use of GitHub emoji on the section headings in the README? I just found they helped my eye pick out the headings a little more easily and I'd seen some other nice READMEs at the time do that sort of thing when I went looking for examples to pattern it off of. I swear I'd had no idea it would become an LLM thing!
        • flowerbreeze 8 hours ago
          The README is older than ChatGPT too. It's very unlikely that it's vibe coded or vibe written.
    • peter-m80 7 hours ago
      Would that be an issue?
      • Amlal 7 hours ago
        Yes, it's a canvas library, there's a lot of risks of including AI generated code that hasn't been checked in a rasterizing library.
        • a_e_k 2 hours ago
          Author here. There's no AI-generated code in this. But yes, security hardening this has not been a priority of mine (though I do have some ideas about fuzz testing it), so for now - like with many small libraries of this nature - it's convenient but best used only with trusted inputs if that's a concern.
        • ivanjermakov 7 hours ago
          A lot of risks compared to what? I imagine bugs in kernel drivers or disk utilities be riskier.
        • JoeyJoJoJr 6 hours ago
          Such as?
      • 1bpp 7 hours ago
        Yes.