Closed Thread Icon

Topic awaiting preservation: Playing with RLE... (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=22086" title="Pages that link to Topic awaiting preservation: Playing with RLE... (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Playing with RLE... <span class="small">(Page 1 of 1)</span>\

 
Iron Wallaby
Nervous Wreck (II) Inmate

From: USA
Insane since: May 2004

posted posted 06-07-2004 22:56

http://www.rpi.edu/~laporj2/panda.html

A cute little panda made from a string using RLE.

Even with the RLE, the panda image is 69 bytes long (the picture is 308 bits). I *want* to use each byte for holding the first n bits of the image (eg. use a hex byte to store the first 4 bits, use base 32 to hold the first 5 bits, etc), since if I used higher bases, I imagine I could get the image size down quite a bit with little or no additional code. I think I'll play more if I have the time.

Either way, it's still the first time I've made a meaningful Javascript program in under 256 bytes (I could make it smaller, but this one is cross-browser in MSIE, Mozilla, and Opera )

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 06-07-2004 23:38

he's cute.

Since the resolution is rather small, I think you could use the ascii code of the characters in a string to store the number of plain/empty pixels in the image. Here it goes :

[edit2] I've uploaded a 218bytes version, and removed the useless 223bytes script in this post. [/edit2]



(Edited by poi on 06-07-2004 23:42)

(Edited by poi on 06-08-2004 01:36)

Iron Wallaby
Nervous Wreck (II) Inmate

From: USA
Insane since: May 2004

posted posted 06-08-2004 00:15

o.o!!

Wow. Once I figure out how that works, I'll praise it even more.

[edit] Aha, I think I got it. You basically removed my additional conversion loops by moving it into the other one, and instead of using parseInt made use of the difference in ASCII values to store the string. Very interesting!

(Edited by Iron Wallaby on 06-08-2004 00:23)

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 06-08-2004 01:13

Yep, that's it. I didn't used your BASE36 thing 'cause it complexify the things and offers a smaller range of possible values ( 36 in your case, while the vanilla ASCII codes theorically offers 256 minus some special characters such as \00 \0a \0d ). And I didn't used a temporary array since it's not absolutely required to "unpack" the picture.

BTW, sorry for not uploading the script, I was playing Dark Age Of Camelot when I wrote it

Iron Wallaby
Nervous Wreck (II) Inmate

From: USA
Insane since: May 2004

posted posted 06-08-2004 02:58

Not a problem, I was able to grab it quite easily myself. I have it down to 193 bytes, and it's still going down, so perhaps I can use it along with other methods of drawing the image (tables, most likely) for drawing the picture and still have it in under 256 bytes.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 06-08-2004 03:20

As it is, you can quickly shrink it to 189bytes.

Iron Wallaby
Nervous Wreck (II) Inmate

From: USA
Insane since: May 2004

posted posted 06-08-2004 04:42

Yup, it isn't too difficult to do so. I wonder if my optimizations are the same as yours (I took to editing the original version of my own code rather than editing yours, though I did take your nice version of the line wrapping code and your ASCII, of course...).

code:
<pre><script>for(m=i=0;i<69;++i)for(j=34;j++<"#&#,#&#(,,0)2'4$#
#4###&$*$&$%$##(##$%$%&(&%$&$$&$$&###*$*#%#2#'$.$*.'".charCodeAt
(i);)document.write((i%2?'MD':' ')+(++m%22?'':'\n'))</script>



http://www.rpi.edu/~laporj2/panda.html

Also, an additional byte can be removed easily by taking the last bit off of the image string (since it's rendered as white anyway)... but I won't do that since it technically alter's the picture. If I wanted to alter the picture I could change all the MD's to X's and have the image's proportion ruined, heh. ;p

[edit] Also exploited some sillyness and got it down to 182: http://www.rpi.edu/~laporj2/panda2.html

(Edited by Iron Wallaby on 06-08-2004 05:53)

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 06-08-2004 10:32

Yep the 189byte version is the same. That was a quiiiiick update.
Oh, well done with the rewriting of the 2 ternary operators I had tried doing that but didn't thought to change their order.

Iron Wallaby
Nervous Wreck (II) Inmate

From: USA
Insane since: May 2004

posted posted 06-08-2004 21:25

Up to 217, but significantly cuter.

http://www.rpi.edu/~laporj2/panda3.html

(Edited by Iron Wallaby on 06-08-2004 21:40)

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 06-08-2004 22:31

couldn't you just store half the bear, and get the other half by swapping the columns in your array?

Iron Wallaby
Nervous Wreck (II) Inmate

From: USA
Insane since: May 2004

posted posted 06-09-2004 00:28

Using a different storage method, yes. Using RLE, it is only a little extra space to store both halves, so it takes less space than writing code to draw the two halves of the image.

If I stored all of the data, and only held half of it, it may be possible to shrink the code. Probably something to toy with.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 06-09-2004 06:43

well, I'd compress the 'real' half of the image via rle, of course (possibly turning it by 90 degrees to have longer parts that can be run length encoded...)

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 06-09-2004 09:27

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Iron Wallaby
Nervous Wreck (II) Inmate

From: USA
Insane since: May 2004

posted posted 06-09-2004 13:43

I look forward to see what you come up with.

215 bytes, by the way. It's better to store each individual character, not groups of 2 characters. I don't think I can do any better without changing the way it's stored.

http://www.rpi.edu/~laporj2/panda4.html

Still havn't attempted storing just half yet.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 06-09-2004 13:51

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 06-09-2004 16:16

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Iron Wallaby
Nervous Wreck (II) Inmate

From: USA
Insane since: May 2004

posted posted 06-09-2004 16:28

Yes... I've read that LZW compression of binary data is either highly effective (when the data and dictionary work together well) or really bad (when they do not). I suppose it would take quite a bit of tweaking to make it work effectively.

I'm starting to play with splitting the panda head in two... problem is, with RLE, the panda becomes 42 bytes. For it to be worthwhile, we have to squeeze the line-doubling code in 69-42=27 bytes, and I am really not sure that it is possible. At least not with the techniques I've tried thus far.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

Iron Wallaby
Nervous Wreck (II) Inmate

From: USA
Insane since: May 2004

posted posted 06-09-2004 23:17

Down to 210 - http://www.rpi.edu/~laporj2/panda5.html (Without solid coloring, it's 175).

So done by changing the loop conditions to more... tricky methods.

[edit- I dropped it an extra byte, heh ;p]

(Edited by Iron Wallaby on 06-09-2004 23:22)

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 06-09-2004 23:31

Damn, I was about to post a 202 bytes version

[edit] Here goes a 201 bytes version. And YES I use some character with ASCII code below 32. Save the page locally and open it in an editor supporting these characters, such as UltraEdit. [/edit]



(Edited by poi on 06-09-2004 23:42)

Iron Wallaby
Bipolar (III) Inmate

From: USA
Insane since: May 2004

posted posted 06-09-2004 23:38

I can't see you're source, heh... were you using special control characters?

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 06-10-2004 03:05

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 06-10-2004 03:26

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Iron Wallaby
Bipolar (III) Inmate

From: USA
Insane since: May 2004

posted posted 06-10-2004 04:43

Yeah... looking at your LZW source, you only used homogenous keys. The strength of LZW is finding common patterns, unlike RLE, which relies on infrequency of color changes.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 06-10-2004 08:28

Notice: I was about to post a 206 bytes version, but when I was typing my post I found another trick to go down to 201. Meanwhile Iron Wallaby posted his 210 bytes one. Oh, and the 202 bytes version is plain stupid, I forgot to remove the semicolon after the document.write()

It's interresting to see that several persons working on the same subject use exactly the same tricks. It's certainly due the extremely small size of the "project".

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 06-10-2004 12:31

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Iron Wallaby
Bipolar (III) Inmate

From: USA
Insane since: May 2004

posted posted 06-10-2004 14:09
quote:
InI said:

The problem is mirroring: I "need" those patterns to be able to mirror my stuff later on.



Could you use symettric patterns for your keys?

And yes, it's really amusing how we both make the same optimizations. It leads me to believe that either A) you're my clone ir B) There are only so many ways to compress code.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 06-10-2004 14:44

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Iron Wallaby
Bipolar (III) Inmate

From: USA
Insane since: May 2004

posted posted 06-10-2004 15:27

http://www.rpi.edu/~laporj2/panda6.html is 203 bytes, without using any special control characters.

http://www.rpi.edu/~laporj2/panda7.html is 200 bytes, using the control characters. It will say that it's 201 bytes, since the program I use always writes a trailing newline.

Both use a different drawing command than poi's (I say it's better since it draws pure black and not really dark gray ).

(Edited by Iron Wallaby on 06-10-2004 15:51)

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 06-10-2004 15:44

I must be completely dumb, I had added a \0 at the end of my RLE string to get a terminal condition, but the \0 WAS already there due to the way the string are stored. So, I have a 200 bytes version too. But I'm preparing something else...

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 06-10-2004 21:42

Like you I have a verions in 175 bytes ... of the cute panda. I've changed the method of compression, BTW I don't really consider it as a compression in fact. The text only version takes ~153bytes.



(Edited by poi on 06-10-2004 21:50)

Iron Wallaby
Bipolar (III) Inmate

From: USA
Insane since: May 2004

posted posted 06-10-2004 21:51

There is a tiny mistake of the left cheek of the panda, BTW.

And do you mind explaining what it does? I can't figure it out, heh... control characters warp my mind in knots. It seems like you stored the actual bits of the image in some way?

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 06-10-2004 22:01

Oops, I'll try to fix the left cheek Hope I didn't hurt him/her.

In fact, the picture is simply stored in binary. The "compressed" string is 39 bytes long which is : 22 x 14 / 8 = 38.5 ~ 39bytes;
The values are XORed by a certain value to avoid controls characters not accepted by the browsers ( IE and Mozilla ) and the rest the "decompression" simply pick the bits one by one to display a white or a black ( hum, sorry, a really dark gray ) square.

[edit] cheek fixed [/edit]

[edit2] 171 bytes [/edit2]



(Edited by poi on 06-10-2004 22:09)

(Edited by poi on 06-11-2004 00:22)

Iron Wallaby
Bipolar (III) Inmate

From: USA
Insane since: May 2004

posted posted 06-11-2004 15:38

Very nice. I don't think I can top that one, at least using the method I am. If I somehow find the ideal LZW, it might be possible, but somehow I'm not so sure.

Maybe I'll make a color one next.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

« BackwardsOnwards »

Show Forum Drop Down Menu