top | item 28506220

Pixie – A full-featured 2D graphics library for Nim

200 points| elcritch | 4 years ago |github.com

75 comments

order
[+] Guzba|4 years ago|reply
For those using Python, we just got our Python bindings for Pixie up onto pip. Repo here https://github.com/treeform/pixie-python

It's extremely fresh but our tests are working so consider giving it a try.

For those interested in Nim's meta-programming, we're generating those Python bindings for Pixie from our Nim code using https://github.com/treeform/genny here https://github.com/treeform/pixie/blob/master/bindings/bindi... More languages in the works.

[+] pjs_|4 years ago|reply
Unreal - I pip-installed the library, ran the demos, and it just worked! After years of mucking about with pyCairo this is a very pleasant surprise!
[+] chmod775|4 years ago|reply
This has a high risk of being confused with PixiJS, which is often just referred to as pixi, and is a popular 2D WebGL renderer.

https://github.com/pixijs/pixijs

This project is likely to get drowned out by pixi search results when its users try to Google anything related to it.

[+] hnlmorg|4 years ago|reply
It's almost impossible to come up with names these days due to the massive amount of software released every year. It's so bad that I automatically include the language name as well as the framework name in any search I do.

In this instance the Nim and JS libraries have different names (and even different spellings of the common subset) so I don't see an issue.

[+] tokai|4 years ago|reply
Its not a real HN library thread without unjustified irl-namespace collision claims.
[+] hutzlibu|4 years ago|reply
Yes, I also just came here to ask a question about pixijs ...
[+] christophilus|4 years ago|reply
I read the title, and thought pixijs had moved to nim + webassembly.
[+] tomrod|4 years ago|reply
Nim is such a breath of fresh air when I read it. This library looks great.

I've been trying to learn it / grok its documentation for awhile. Any suggestions on how to learn it better? I've given Exercism.IO a try (disclaimer: satisfied learner from there but not trying to shill) but I've had difficulty adopting the language from a Python background.

[+] elcritch|4 years ago|reply
Nim's a pleasant language to read/write! Out of curiosity, what aspects have you found challenging to learn? One caveat of imitating Python's syntax is that the semantics are not the same as in Python and are closer to Pascal/Ada in many ways.

If you haven't read through the Nim-for-Pythoners [1] it'd be good. I read the "nim manual" [2] constantly and just use ctrl-f. Though Nim Basics by narimiran is a nice tutorial form [3].

There's a few standard links: 1: https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programm... 2: https://nim-lang.org/docs/manual.html 3: https://narimiran.github.io/nim-basics/

[+] treeform|4 years ago|reply
To learn any new language or framework I just recommend diving in and doing things. Have some goal and mind that you want to create and work at it. Its usually hard to start at first but once you get going its just a little bit of progress at a time.
[+] foerbert|4 years ago|reply
Despite completely disagreeing with you on the first point, I've had some of the same experience too.

Some years ago when I was going through languages frequently, I was pretty interested in it for a bit, but found it kind of hard to get into and my interest ultimately wandered.

I thought a large part of that was due to my unusually strong dislike of the syntax, and that that was why I found it unusually difficult to grok. Maybe it wasn't. Interesting.

[+] diskzero|4 years ago|reply
This was the final presentation at NimConf in June and I was blown away, as I am sure many others were. The fact that this library exists makes the task of creating a high quality retained-mode UI library in Nim much easier. You don't have to try and wrangle Pango/Cairo/Skia to act as your foundation.
[+] treeform|4 years ago|reply
Thank you for watching our pixie presentation!
[+] analognoise|4 years ago|reply
Reminds me of BGRABitmap from Lazarus/FreePascal.

https://github.com/bgrabitmap/bgracontrols

(BGRAControls contains the BGRABitmap components).

It's sad Lazarus/FreePascal doesn't get much play, because high quality libraries like this have existed for years for it and it seems to not get much traction.

[+] diskzero|4 years ago|reply
Why do you think that is? Pascal as a language? The IDE? Is there a lack of success stories or high profile applications?
[+] tomcam|4 years ago|reply
Stunning. Already supports all popular font types, image types, and SVG.
[+] jahewson|4 years ago|reply
It’s really great work. The font support is a bit behind the times though, and text shaping is non-existent. I see so many libraries fall at that hurdle, they think they can do it themselves then when they realise it’s hard and requires a team of people they either abandon it or tell you to use harfbuzz without the necessary integration points. Hopefully that won’t be the case here!
[+] elcritch|4 years ago|reply
Not to mention operations like "complex blends: Darken, Multiply, Color Dodge, Hue, Luminosity... etc" and many SIMD accelerations. It also has Node, Python, and C interfaces. Though I haven't found an excuse to use it yet. Surely there's got to be some excuse... ;)
[+] RodgerTheGreat|4 years ago|reply
Dug into the source for the GIF decoder a bit and it looks like it only supports the most basic features- no windowing, animation, local colortables, or background colors. I suspect many optimized static GIFs won't decode correctly. Still, everything has to start somewhere!
[+] Guzba|4 years ago|reply
SVG support has been really helpful for me to see a diverse and "real world" set of rendering results when working on Pixie. And for testing it's great to be able to grab huge sets of open source SVG files and check our results.

For example, I have a few "megatests" where I render entire icon sets or emoji sets such as https://raw.githubusercontent.com/treeform/pixie/master/test... and https://raw.githubusercontent.com/treeform/pixie/master/test...

Running these tests helps me feel more confident that changes I'm making are not breaking things.

[+] habibur|4 years ago|reply
I had been using ImageMagick for these types of things. Wondering how pixie improves over it.

Without knowing how much overhead Nim brings in, I still believe it would have been better if this library preliminary was a C or C++ lib and then had binding for all the other languages.

[+] cyber_kinetist|4 years ago|reply
Nim nowadays (with the new ARC/ORC memory management) seems to be similar with C++ in terms of runtime overhead, so I don’t think you need to be too worried about it.
[+] diskzero|4 years ago|reply
I am not sure Pixie improves over ImageMagick. Perhaps it has some more advanced blend modes or other algorithms that ImageMagick hasn't implemented. ImageMagick is really great for pipelines of conversions. I see Pixie being more of a Quartz, Cairo, Skia, etc. for the Nim platform that can serve as the low-level canvas for a lot of higher-level functionality. Sadly, I am not enough of a Nim expert to know the trade-offs between using native code or importing C libraries.
[+] RattleyCooper|4 years ago|reply
I actually wrote a small program for batch scaling images using pixie a couple weeks ago and it was a bit faster than ImageMagick, and the results looked the same. The scaling in pixie is a little less flexible though.

I haven't really compared any other features though. Scaling images does appear to be quicker though (when compiled with -d:release -d:danger --opt:speed)

[+] gnramires|4 years ago|reply
I'll probably take this up for my artistic work (currently using PyGame and p5.js). Thanks!
[+] jb1991|4 years ago|reply
After the conference talk, I rushed to try it out. I remember having quite some difficulty getting the demos to work well on a Mac and eventually gave up.
[+] treeform|4 years ago|reply
Can you give us more details on what did not work for you? We would love to fix it.
[+] tenaciousDaniel|4 years ago|reply
I've been looking for an alternative to Skia so this looks interesting. Why Nim though? I've never heard of it before.
[+] treeform|4 years ago|reply
I chose to write Pixie in Nim because I really like Nim:

* Nim very fast. I can beat any C/C++ program in performance using same tricks as they do. Cleaver Memory management, inlining, static analysis, SIMD. There is no wall that you run where you need to drop into "C".

* Nim is very easy to write, I came from Python/CoffeeScript and it was a very easy transition. Nim feels like Python with Types.

* Nim is very powerful with generics/templates/macros allowing you to write DSLs quickly.

* Nim has very easy interop with C. So its very easy to use existing C libraries or low level operating system APIs.

* Nim works everywhere: From Desktop Windows/Mac/Linux, to mobile iOS/Android to embeaded devices. It even compiles to JavaScript (like CoffeeScript/Typescript or WASM) or GL shader language. It run anywhere.

* Nim has a smaller community that has not been overrun by complexity or apathy. Everything feels green and fresh and everyone helps everyone else. But still big enough that there are libraries for most things.

[+] MattRix|4 years ago|reply
Looks like a great library, though the name is going to cause some people to think it’s related to pixi.js
[+] treeform|4 years ago|reply
That's unfortunate. I did not know about pixi.js when we picked the name. It feels like all of the cool names are taken! When we were thinking of a name we just looked around the Nim community for name collisions.
[+] tomrod|4 years ago|reply
Is pixi.js pretty big? I haven't heard of it before tonight, and I thought I'd had exposure to most of the bigger JS frameworks via HN (I'm not a JS guy, more Python).
[+] eyelidlessness|4 years ago|reply
I for one welcome the butt caps.
[+] eyelidlessness|4 years ago|reply
I guess some people don’t welcome butt caps. The world is a complex place.