haxegon / zeedonk

Haxegon + Puzzlescript = Zeedonk!
http://www.zeedonk.net
12 stars 2 forks source link

sprite editor #182

Closed increpare closed 9 years ago

increpare commented 9 years ago

we could go for a direct pixel approach, or maybe something that would be suited to compression more - for instance, something more vector-like where you have square and circle primitives - then we could also add back animation, and it might keep the pasted file size low.

(if you're stuck for things to do next week, this might be a fun project to work on :D )

increpare commented 9 years ago

(i mean to say, in general, using as a design constraint that the pasted string should be as small as possible might be a good direction)

bfod commented 9 years ago

how big would a 2-bitplane image be for a 32x32 sprite, expressed as direct pixels? It's two 10-digit 32-bit uints, or one 18-digit 64-bit uint, right? That doesn't seem bad to me in terms of code mess. Then you could specify 3 colors plus transparent.

Gfx.LoadImage("192401295123721748",red,orange,black); -- something like that

if you add another bitplane you have to think about having a fixed palette because specifying 7 colors is gross.

bfod commented 9 years ago

the nice thing about using a straightforward bitplane int like this is that you could modify it in your game at runtime, using a simple bitshift function.

bfod commented 9 years ago

You could also make it that the loader requires sprite dimensions from the length of the parameter it gets, so the editor could support a few different bitmap sizes or depths. So, given the same data string:

Gfx.LoadImage("255",4,red); <--- an 4x4x1bit sprite, all pixels are red Gfx.LoadImage("255",32,blue,white,pink); <--- an 32x32x2bit sprite, 8 pixels at the top are blue (idk)

increpare commented 9 years ago

Custom 2-color sprite with real-time changeable background/foreground colours in addition to transparency? Sounds good to me :) Terry?

TerryCavanagh commented 9 years ago

Yeah, that sounds great. I was basically just gonna do png, but I think I prefer this

increpare commented 9 years ago

DO IT :D Poke me if you need help with bit fiddling.

TerryCavanagh commented 9 years ago

Ok; messed about with this for a while. Ran into a few problems implementing it, so I thought I'd try the PNG thing instead. This 32x32 truecolour PNG:

32x32

... seems to encode as this Base64 string:

wolQTkcNChoK

... So I think I'm just going to go for that approach!

TerryCavanagh commented 9 years ago

Meh, ok, that did seem way too good to be true. My haxe.io.bytes to flash.util.byteArray converter had a bug. It actually converts to this base64 string:

iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAALHRFWHRDcmVhdGlvbiBUaW1lAFR1ZSAxNCBKdWwgMjAxNSAxNjoyMjoxNSAtMDAwMBEwbaMAAAAHdElNRQffCQUSMTt9hg+RAAAACXBIWXMAAB7BAAAewQHDaVRTAAAABGdBTUEAALGPC/xhBQAAAUtJREFUeNq9VbkRAjEM9N2YkALI6YaIhJg2qIA2iEmI6IacAghJ8IwAW8/a8h3DZneWVl59Hq63R8DYrJehhTrDOJO9aTag+NntvoPep2c4XOo6bAUu9oT9Ihy3dR2xzb46G8HYzy3pSI5aB66BYEcgg48OqMBZzyZKHlIzTifzgQdIaUFVFf+RWcoVTxcPgDJu0qEYn8Yl5DmQZTD96QbiKE2D4v3SjvoXxFdfq7VKqqgP5nRUzxz8CH8PkPPTnGECr7BOL9umRvbry87qn8ArYaWoHJaKDsGuRowQof/xvSPlNjVvjZddVmDkx3RLb0DLrKQaZO/juzBq0qFP1RvHa+Bkr39ykuhlNA1IR9VyhM5OtCxjn49IveMePauinz3UatCfDaO1frnsLHagAPV4Dy9QoNbWFHZO8g6Q95+I4e9X7j7pTXajpHoBDFKV3QcEKnEAAAAASUVORK5CYII=
TerryCavanagh commented 9 years ago

Hey, uh, am I missing something obvious here? A 32x32 image with just on and off pixels is 1024 binary characters, right? So surely it's a lot more than 10 digits?

Main.hx:89: 1111111111111111111111111111111111000000000000000000000000000001101000000000000000000000000000011001000000000000000000000000000110001000000000000000000000000001100001000000000000000000000000011000001000000000000000000000000110000001000000000000000000000001100000001000000000000000000000011000000001000000000000000000000110000000001000000000000000000001100000000001000000000000000000011000000000001000000000000000000110000000000001000000000000000001100000000000001000000000000000011000000000000001000000000000000110000000000000001000000000000001100000000000000001000000000000011000000000000000001000000000000110000000000000000001000000000001100000000000000000001000000000011000000000000000000001000000000110000000000000000000001000000001100000000000000000000001000000011000000000000000000000001000000110000000000000000000000001000001100000000000000000000000001000011000000000000000000000000001000110000000000000000000000000001001100000000000000000000000000001011000000000000000000000000000001111111111111111111111111111111111
Main.hx:90: Base 16: "ffffffffc0000001a000000190000001880000018400000182000001810000018080000180400001802000018010000180080001800400018002000180010001800080018000400180002001800010018000080180000401800002018000010180000081800000418000002180000011800000098000000580000003ffffffff", 256 characters
Main.hx:91: Base 64: "*****8AAAAGgAAABkAAAAYgAAAGEAAABggAAAYEAAAGAgAABgEAAAYAgAAGAEAABgAgAAYAEAAGAAgABgAEAAYAAgAGAAEABgAAgAYAAEAGAAAgBgAAEAYAAAgGAAAEBgAAAgYAAAEGAAAAhgAAAEYAAAAmAAAAFgAAAA*****8", 171 characters
Main.hx:92: Base 128: "))))—!!!!Œ!!!'B!!!S!!!$%!!!:2!!Ðbb!!½#!!!„*!!'!B!!RÐ!!$!%!!:!2!Ðb!b!½!#!!„!*!'!!B!R!Ð!$!!%!:!!2Ðb!!b½!!#!„!!*'!!!BR!!Ð$!!!%:!!!3b!!!n!!!#„!!!1))))„", 147 characters
bfod commented 9 years ago

Hah, yeah not exactly my finest moment in mathematics. 32x32x2 bit would be 64 32-bit uints.

TerryCavanagh commented 9 years ago

oh, haha! Ok, I was very sure I was just missing something obvious - thanks for clearing it up.

Currently investigating the rabbithole of base 65536

bfod commented 9 years ago

if you can encode in base 65536, what's a reasonable length of a string? 32 characters doesn't seem so bad? How many pixels and bitplanes can you get there?

TerryCavanagh commented 9 years ago

I think Stephen has basically ruled this out already actually: https://twitter.com/increpare/status/638140240985747457

A 16x16 sprite with four colours is only 86 characters at base 64, which is pretty decent really. Will probably just go with that. (Base 128 looks really weird and isn't really that much smaller).

bfod commented 9 years ago

ok this seems like a good tradeoff. I think it's still great if you can also save out 8x8 or 4x4 sprites?

TerryCavanagh commented 9 years ago

Yeah, 8x8 is only 22 characters, which is great!

Also, can now independently confirm that base 256 probably isn't going to work out

Main.hx:141: Base 128: "))²!á!$2!†!:B'%ÐbbR*½Ð$!2„#:!H!&b!))²", 37 characters
Main.hx:142: Base 256: "みみリÐヅÐシÐケÐオÐウÐイÐアイアcアCア3ア+ア&ア$みみ", 32 characters
TerryCavanagh commented 9 years ago

OH, or maybe it is! I found a good list of european special characters and symbols. Here's base 256:

Main.hx:144: Base 16: "ffffc001a001900188018401820181018081804180218011800980058003ffff", 64 characters
Main.hx:145: Base 64: "áááAAaABkAGIAYQBggGBAYCBgEGAIYARgAmABYADáá8", 43 characters
Main.hx:146: Base 128: "ķķîANADQAéAYgGEBÀÀwIMBDAQèCYAmAFÀAķķî", 37 characters
Main.hx:147: Base 256: "ŽŽŨBŘBÒBÑBŁBĻBĺBĹĺĹàĹhĹRĹJĹFĹDŽŽ", 32 characters

Here's the character list:

var BASE16:String = "0123456789abcdef";
var BASE64:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789éá";
var BASE128:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ÄäÀàÁáÂâÃãÅåǍǎĄąĂăÆæÇçĆćĈĉČčĎđĐďðÈèÉéÊêËëĚěĘęĜĝĢģĞğĤĥÌìÍíÎîÏïıĴĵĶķ";
var BASE256:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ÄäÀàÁáÂâÃãÅåǍǎĄąĂăÆæÇçĆćĈĉČčĎđĐďðÈèÉéÊêËëĚěĘęĜĝĢģĞğĤĥÌìÍíÎîÏïıĴĵĶķĹĺĻļŁłĽľÑñŃńŇňÖöÒòÓóÔôÕõŐőØøŒœŔŕŘřẞߌśŜŝŞşŠšȘșŤťŢţÞþȚțÜüÙùÚúÛûŰűŨũŲųŮůŴŵÝýŸÿŶŷŹźžŻż¡¿|~€¾ƒ„…†‡ˆ‰Š‹¢£¥¦§¨ª«¬­¯°±²³´µ–—!#$%&*+,-½Ž";
TerryCavanagh commented 9 years ago

Ok, I think I've found a working BASE512:


Main.hx:157: 1111111111111111110000000000000110100000000000011001000000000001100010000000000110000100000000011000001000000001100000010000000110000000100000011000000001000001100000000010000110000000000100011000000000001001100000000000010110000000000000111111111111111111
Main.hx:158: Base 16: "ffffc001a001900188018401820181018081804180218011800980058003ffff", 64 characters
Main.hx:159: Base 64: "áááAAaABkAGIAYQBggGBAYCBgEGAIYARgAmABYADáá8", 43 characters
Main.hx:160: Base 128: "ķķîANADQAéAYgGEBÀÀwIMBDAQèCYAmAFÀAķķî", 37 characters
Main.hx:161: Base 256: "ŽŽŨBŘBÒBÑBŁBĻBĺBĹĺĹàĹhĹRĹJĹFĹDŽŽ", 32 characters
Main.hx:162: Base 512: "ɏɏAaAêAҘDQMgwÀŨĺЀІBYCèEҐLAfɏӰ", 29 characters

Here it is! Checked for control characters and uniqueness:

var BASE512:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ÄäÀàÁáÂâÃãÅåǍǎĄąĂăÆæÇçĆćĈĉČčĎđĐďðÈèÉéÊêËëĚěĘęĜĝĢģĞğĤĥÌìÍíÎîÏïıĴĵĶķĹĺĻļŁłĽľÑñŃńŇňÖöÒòÓóÔôÕõŐőØøŒœŔŕŘřẞߌśŜŝŞşŠšȘșŤťŢţÞþȚțÜüÙùÚúÛûŰűŨũŲųŮůŴŵÝýŸÿŶŷŹźžŻż¡¿|~€¾ƒ„…†‡ˆ‰ψ‹¢£¥¦§¨ª«¬ξ¯°±²³´µ–—!#$%&*+,-½ŽЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюяѐёђѓєѕіїјљњћќѝўџѠѡѢѣѤѥѦѧѨѩѪѫѬѭѮѯѰѱѲѳѴѵѶѷѸѹѺѻѼѽѾѿҐґҒғҔҕҖҗҘҙҚқҜҝҞҟҠҡҢңҤҥҦҧҨҩҪҫҬҭҮүҰұҲҳҴҵҶҷҸҹҺһҼҽҾҿӀӁӂӃӄӅӆӇӈӉӊӋӌӍӎӏӐӑӒӓӔӕӖӗӘәӚӛӜӝӞӟӠӡӢӣӤӥӦӧӨөӪӫӬӭӮӯӰӱӲӳӴӵӶӷӸӹӺӻӼӽӾӿɀɁɂɃɄɅɆɇɈɉɊɋɌɍɎɏ";

1024 seems possible!

increpare commented 9 years ago

I got a base 16k implementation working - here's the code i stole from - it requires input as hex characters

https://gist.github.com/commi/1583588

On Sat, Sep 5, 2015 at 11:14 PM, Terry Cavanagh notifications@github.com wrote:

Ok, I think I've found a working BASE512:

Main.hx:157: 1111111111111111110000000000000110100000000000011001000000000001100010000000000110000100000000011000001000000001100000010000000110000000100000011000000001000001100000000010000110000000000100011000000000001001100000000000010110000000000000111111111111111111 Main.hx:158: Base 16: "ffffc001a001900188018401820181018081804180218011800980058003ffff", 64 characters Main.hx:159: Base 64: "áááAAaABkAGIAYQBggGBAYCBgEGAIYARgAmABYADáá8", 43 characters Main.hx:160: Base 128: "ķķîANADQAéAYgGEBÀÀwIMBDAQèCYAmAFÀAķķî", 37 characters Main.hx:161: Base 256: "ŽŽŨBŘBÒBÑBŁBĻBĺBĹĺĹàĹhĹRĹJĹFĹDŽŽ", 32 characters Main.hx:162: Base 512: "ɏɏAaAêAҘDQMgwÀŨĺЀІBYCèEҐLAfɏӰ", 29 characters

Here it is! Checked for control characters and uniqueness:

var BASE512:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ÄäÀàÁáÂâÃãÅåǍǎĄąĂăÆæÇçĆćĈĉČčĎđĐďðÈèÉéÊêËëĚěĘęĜĝĢģĞğĤĥÌìÍíÎîÏïıĴĵĶķĹĺĻļŁłĽľÑñŃńŇňÖöÒòÓóÔôÕõŐőØøŒœŔŕŘřẞߌśŜŝŞşŠšȘșŤťŢţÞþȚțÜüÙùÚúÛûŰűŨũŲųŮůŴŵÝýŸÿŶŷŹźžŻż¡¿|~€¾ƒ„…†‡ˆ‰ψ‹¢£¥¦§¨ª«¬ξ¯°±²³´µ–—!#$%&*+,-½ŽЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюяѐёђѓєѕіїјљњћќѝўџѠѡѢѣѤѥѦѧѨѩѪѫѬѭѮѯѰѱѲѳѴѵѶѷѸѹѺѻѼѽѾѿҐґҒғҔҕҖҗҘҙҚқҜҝҞҟҠҡҢңҤҥҦҧҨҩҪҫҬҭҮүҰұҲҳҴҵҶҷҸҹҺһҼҽҾҿӀӁӂӃӄӅӆӇӈӉӊӋӌӍӎӏӐӑӒӓӔӕӖӗӘәӚӛӜӝӞӟӠӡӢӣӤӥӦӧӨөӪӫӬӭӮӯӰӱӲӳӴӵӶӷӸӹӺӻӼӽӾӿɀɁɂɃɄɅɆɇɈɉɊɋɌɍɎɏ";

1024 seems possible!

— Reply to this email directly or view it on GitHub https://github.com/increpare/terrylib_online/issues/182#issuecomment-138003160 .

bfod commented 9 years ago

I guess it doesn't matter how you have to input it since users will only ever be copy and pasting.

bfod commented 9 years ago

If you make the sprite editor a hackable example file, then it'll be easy for people to write their own sprite editors! Whee

increpare commented 9 years ago

yay! :+1: