Emojis in source code!

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SpiceWare

Quote from: Andrew Davie on 11 Jun 2026, 12:57 AMAs an aside, that ASCII-art representation on the side is done by a tool that modifies the source code to interpret the data. It's really useful to help visualise a character, but I do wish ASCII had a decent range of shaded blocks that were also fixed-width.

Have you tried emoji?  I just did a quick test:

  • Opened main.c for Draconian Deluxe
  • Started a comment with //
  • pressed <COMMAND><CONTROL><SPACE> to open character viewer
  • Located the colored blocks and clicked them to "type" them into the source
  • saved & compiled source without problem



Andrew Davie

Quote from: SpiceWare on 11 Jun 2026, 01:17 AMHave you tried emoji?  I just did a quick test:

I have not!  Good tip, I'll see what I can do.
Since the comments are added by a tool, I'll look to having the tool use emojis.
Normally I would never have thought of this - I absolutely despise emojis.
But this would be a good use-case.

Andrew Davie

#2
Quote from: SpiceWare on 11 Jun 2026, 01:17 AMHave you tried emoji?  I just did a quick test:

It's so awesome! TY for the suggestion.

Note: I don't type these in by hand - the tool I wrote parses the source code and adds the coloured comments/shapes automatically. Totally helps with finding the character(s) you want to modify.

Andrew Davie

#3
May extend the unicode stuff to player sprites too. Super!


SpiceWare

I edited the syntax highlighting rules of jEdit so I can see the graphics in the binary values.

Looks like jEdit doesn't support emoji very well - only the black and white squares showed up from my test, and they're not even the right color.


Andrew Davie

Quote from: SpiceWare on 11 Jun 2026, 02:31 AMI edited the syntax highlighting rules of jEdit so I can see the graphics in the binary values.

Looks like jEdit doesn't support emoji very well - only the black and white squares showed up from my test, and they're not even the right color.

That's a shame.

Andrew Davie

Quote from: Andrew Davie on 11 Jun 2026, 02:20 AMMay extend the unicode stuff to player sprites too. Super!

OK, I was kinda thinking "would be cool but can I be bothered?"
And then I remembered AI. I wrote a single prompt to Claude. It generated the tool from that prompt. No refinements, no changes. I haven't even looked at the code. I run it, it works perfectly first time. Sample result attached.

Here's the prompt/request I made.

Quotewrite python tool:

I have sprite shape definitions in code, like this...

const unsigned char shape_FRAME_ARMS_IN_AIR[] = {
    // 02

    SPRITE_DOUBLE | 24,
    2,
    5,

    SP(__X_____, _X______, HMT0, BONE),    // 00
    SP(__X_XXXX, _X______, HMT0, BONE),    // 01
    SP(_X_XXXXX, X_X_____, HMT0, BONE),    // 02
    SP(_X_X____, X_X_____, HMT1, BONE),    // 03
    SP(_XXX_X__, XXX_____, HMT1, BONE),    // 04
    SP(_XX_X___, _XX_____, HMT1, BONE),    // 05
    SP(_XX_X___, _XX_____, HMT1, BONE),    // 06
    SP(_XX_____, _XX_____, HMT2, BONE),    // 07
    SP(_XX_____, _XX_____, HMT2, BONE),    // 08
    SP(_XXX____, XXX_____, HMT2, BONE),    // 09
    SP(_XX_XXXX, _XX_____, HMT3, BONE),    // 10
    SP(__X_XXXX, _X______, HMT3, BONE),    // 11
    SP(__XX____, XX______, HMT3, BONE),    // 12
    SP(__XXXXXX, XX______, BDY1, BONE),    // 13
    SP(__XX_XX_, X_______, BDY0, BONE),    // 14
    SP(___X_XX_, X_______, BDY1, BONE),    // 15
    SP(____XXXX, ________, BDY2, BONE),    // 16
    SP(____XXXX, ________, BDY2, BONE),    // 17
    SP(_____XX_, ________, BDY2, BONE),    // 18
    SP(____X__X, ________, BDY2, BONE),    // 19
    SP(___XXXXX, X_______, HMT1, BONE),    // 20
    SP(___X_XX_, X_______, HMT1, BONE),    // 21
    SP(__XX____, XX______, HMT2, BONE),    // 22
    SP(__X_____, _X______, HMT0, BONE),    // 23
};


I want to create a comment at the end of every line in the file with the numbered comment at the end and containing the SP or SP2 macro.  I want to produce a comment representation of the contents of the definition (with the underscore and the X).  For underscore I want to use a black emoji box character. For the X I want to use a yellow emoji box character. The end result would look something like this...

const unsigned char shape_FRAME_HUNCH[] = {
    // 03

    26,
    4 + 0,
    0,

    SP2(___XXX__, HMT0),    // 00 ◼️◼️◼️🟨🟨🟨◼️◼️
    SP2(_XXXXXX_, HMT0),    // 01 ◼️🟨🟨🟨🟨🟨🟨◼️
    SP2(_XXXXXX_, HMT0),    // 02 ◼️🟨🟨🟨🟨🟨🟨◼️
    SP2(XXXX__XX, HMT1),    // 03 🟨🟨🟨🟨◼️◼️🟨🟨
    SP2(XXX__X_X, HMT1),    // 04 🟨🟨🟨◼️◼️🟨◼️🟨
    SP2(X_X_X__X, HMT1),    // 05 🟨◼️🟨◼️🟨◼️◼️🟨
    SP2(X_X_X__X, HMT1),    // 06 🟨◼️🟨◼️🟨◼️◼️🟨
    SP2(X_X____X, HMT2),    // 07 🟨◼️🟨◼️◼️◼️◼️🟨
    SP2(XXX____X, HMT2),    // 08 🟨🟨🟨◼️◼️◼️◼️🟨
    SP2(XXX____X, HMT2),    // 09 🟨🟨🟨◼️◼️◼️◼️🟨
    SP2(_XXX__X_, HMT3),    // 10 ◼️🟨🟨🟨◼️◼️🟨◼️
    SP2(_XXX__X_, HMT3),    // 11 ◼️🟨🟨🟨◼️◼️🟨◼️
    SP2(__XXXX__, HMT3),    // 12 ◼️◼️🟨🟨🟨🟨◼️◼️
    SP2(_X____X_, BDY1),    // 13 ◼️🟨◼️◼️◼️◼️🟨◼️
    SP2(XXXXXXXX, BDY0),    // 14 🟨🟨🟨🟨🟨🟨🟨🟨
    SP2(XX_XX_XX, BDY1),    // 15 🟨🟨◼️🟨🟨◼️🟨🟨
    SP2(X_XXXX_X, BDY2),    // 16 🟨◼️🟨🟨🟨🟨◼️🟨
    SP2(X_XXXX_X, BDY2),    // 17 🟨◼️🟨🟨🟨🟨◼️🟨
    SP2(_X_XX_X_, BDY2),    // 18 ◼️🟨◼️🟨🟨◼️🟨◼️
    SP2(_X____X_, BDY2),    // 19 ◼️🟨◼️◼️◼️◼️🟨◼️
    SP2(___XX___, HMT1),    // 20 ◼️◼️◼️🟨🟨◼️◼️◼️
    SP2(__XXXX__, HMT2),    // 21 ◼️◼️🟨🟨🟨🟨◼️
    SP2(___XX___, HMT2),    // 22 ◼️◼️◼️🟨🟨◼️◼️◼️
    SP2(__X__X__, HMT2),    // 23 ◼️◼️🟨◼️◼️🟨◼️◼️
    SP2(__X__XX_, HMT2),    // 24 ◼️◼️🟨◼️◼️🟨🟨◼️
    SP2(__X__X__, HMT0),    // 25 ◼️◼️🟨◼️◼️🟨◼️◼️

};


(different frame shown)


Here's its response...

QuoteLooking at the patterns, the SP macro takes two 8-bit patterns plus other args, and SP2 takes one 8-bit pattern. I need to:

Parse SP/SP2 lines, extract the bit pattern(s)
Replace _ with ◼️ and X with 🟨
Append/replace the trailing comment with the visual

Let me build this.Sprite comment visualiser toolSprite comment visualiser toolQuick smoke test with your example:Test with sample inputTest with sample inputWorks. Though I notice the trailing _ padding chars on the second pattern (e.g. _X______) are rendering — that's technically correct per the source, but you might want to strip trailing black boxes from each pattern. Call it now:Presented filePresented fileDoes the job. A few notes:
Trailing padding: The SP macro's second pattern like _X______ — those trailing underscores render as 8 black boxes each. If that's intentional (full 8-bit width always shown) it's fine. If you'd rather strip trailing black boxes from each pattern, easy one-liner change in pattern_to_emoji.
Column alignment: Comments align to column 50. The emoji characters are double-width in most terminals/editors so visual alignment will be off in anything other than a monospace emoji-aware renderer. Nothing to be done about that really.
Idempotent: Run it twice, it re-generates the comment from the source pattern each time — won't accumulate junk.
In-place usage: python3 sprite_vis.py shapes.c rewrites the file. Pass a second arg for a separate output.



What a remarkable time to be alive. It would have taken me a "can't be stuffed" amount of time to write the tool and get it working properly. The AI method took me about 2 minutes. Total, including asking for a solution.

Generated code attached.

SpiceWare

Nice! The multi-color looks odd to me, such as the Red square seems like it should be Cyan on the assumption that the left column of binary is Red, middle is Green, and right is Blue.

in _CHAR_ROCK:

  • Black is correct
  • Yellow should be Purple
  • Blue is correct
  • Red should be Cyan.

in _CHAR_GEODOGE:

  • Black is correct
  • Purple should be Yellow
  • Green is correct
  • Red should be Cyan
  • White is correct

Andrew Davie

Quote from: SpiceWare on 11 Jun 2026, 02:53 AMNice! The multi-color looks odd to me, such as the Red square seems like it should be Cyan on the assumption that the left column of binary is Red, middle is Green, and right is Blue.

in _CHAR_ROCK:

  • Black is correct
  • Yellow should be Purple
  • Blue is correct
  • Red should be Cyan.

in _CHAR_GEODOGE:

  • Black is correct
  • Purple should be Yellow
  • Green is correct
  • Red should be Cyan
  • White is correct


Easy to change - I selected colours that made each character look most-like onscreen (to me).
Not saying you're wrong - I just wanted things to look OK-ish.
They're not red/green/blue colours in the game. They're colourA/colourB/colourC.
I'll have a play.


Andrew Davie

#9
I don't see a cyan block in the emoji set.
In any case, screenshot shows that colours vary so much it's pointless trying to match R/G/B.
Just "visually distinct" is all I want/need.


SpiceWare

Quote from: Andrew Davie on 11 Jun 2026, 03:03 AMThey're not red/green/blue colours in the game. They're colourA/colourB/colourC.

Ah, that's right.

QuoteI don't see a cyan block in the emoji set.
You're right, could add in some hearts which have a few more color options:

🟥🟧🟨
🟩🟦🟪
⬛️⬜️🟫
🩷❤️🧡
💛💚🩵
💙💜🖤
🩶🤍🤎

Andrew Davie

Can also define the binary values as colour labels, so you can do this....




Andrew Davie


SpiceWare

That's slick, sadly it doesn't work on my setup.

Andrew Davie

#14
Quote from: SpiceWare on 11 Jun 2026, 08:18 AMThat's slick, sadly it doesn't work on my setup.

Uh, I didn't mention -- NONE of the black emojis work. Nor white, apparently. That's why I had red/yellow (now blue/yellow) combinations. Try again without the black!  I've attached my source defs to save you the trouble!