Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: meishe91 on March 26, 2011, 06:13:16 pm

Title: Sprite to Hex Routines
Post by: meishe91 on March 26, 2011, 06:13:16 pm
So SirCmpwn's new topic about his 60 byte converter got me thinking about trying to beat it in Pure TI-BASIC...however I don't think it's possible. So, I just decided to try to make the smallest one I could possible and thought I'd share what I came up with. However, that's not the point of this thread. This thread is for people to post their own Pure TI-BASIC routines to convert a image on the graph screen into hex data. Just thought it'd be interesting to see what other people come up with.

Spoiler For People's Codes:
Mine:
Code: (Slower; 92 bytes) [Select]
"_
For(A,0,7
For(B,0,1
Ans+sub("0123456789ABCDEF",sum(seq(2^(3-C)pxl-Test(A,4B+C),C,0,3))+1,1
End
End
sub(Ans,2,16

Code: (Faster; 103 bytes) [Select]
"_
For(A,0,7
For(B,0,1
Ans+sub("0123456789ABCDEF",8pxl-Test(A,4B)+4pxl-Test(A,4B+1)+2pxl-Test(A,4B+2)+pxl-Test(A,4B+3)+1,1
End
End
sub(Ans,2,16

Code: (Just displays; Based off of Nemo's; 85 bytes) [Select]
For(A,0,15
Output(1,A+1,sub("0123456789ABCDEF",sum(seq(2^(3-B)pxl-Test(iPart(A/2),B+8fPart(A/2)),B,0,3))+1,1
End

Code: (Same as above but uses Text() to shave off an extra byte) [Select]
For(A,0,15
Text(8,4A,sub("0123456789ABCDEF",sum(seq(2^(3-B)pxl-Test(iPart(A/2),B+8fPart(A/2)),B,0,3))+1,1
End

Code: (Just displays; Based off of Phenomist's optimization; 84 bytes) [Select]
For(A,0,7
For(B,0,1
Output(1,2A+B+1,sub("084C2A6E195D3B7F",sum(seq(2^Cpxl-Test(A,4B+C),C,0,3))+1,1
End
End

Code: (Same as above but uses Text() to shave off an extra byte) [Select]
For(A,0,7
For(B,0,1
Text(8,8A+4B,sub("084C2A6E195D3B7F",sum(seq(2^Cpxl-Test(A,4B+C),C,0,3))+1,1
End
End

Nemo's:
Code: (92 bytes) [Select]
"_
For(A,0,15
Ans+sub("0123456789ABCDEF",sum(seq(2^(3-B)pxl-Test(iPart(A/2),B+8fPart(A/2)),B,0,3))+1,1
End
sub(Ans,2,16

Phenomist's:
Code: (Optimized from my slower one; 88 bytes) [Select]
"_
For(A,0,7
For(B,0,1
Ans+sub("084C2A6E195D3B7F",sum(seq(2^Cpxl-Test(A,4B+C),C,0,3))+1,1
End
End
sub(Ans,2,16

See what you can come up with and I'll add them to the list :)

Mine so far is the smallest at 84 bytes, 83 byte if done on graph screen, but it only displays it. For storing it Phenomist now holds the record at 88 bytes. Can anyone beat them? ;)

P.S. Sorry for using [code][/code] tags inside the [spoiler][/spoiler] tags but just want to see what people come up with without being influenced by other people's code.
Title: Re: Sprite to Hex Routines
Post by: TIfanx1999 on March 26, 2011, 07:38:26 pm
TIfreak was using one for pokemon. IIRC it was basic, and written by Weregoose at UTI. You might want to take a look at his. :)
Title: Re: Sprite to Hex Routines
Post by: meishe91 on March 26, 2011, 07:53:32 pm
Is his to go to or from hex though? Or are you talking about he is using it to convert sprites to be put into the game?
Title: Re: Sprite to Hex Routines
Post by: DJ Omnimaga on March 26, 2011, 11:51:02 pm
I think it converted to hex, but I forgot what sizes it did.

Anyway nice to see how small you can get this.
Title: Re: Sprite to Hex Routines
Post by: phenomist on March 27, 2011, 12:30:07 am
Modification of meishe's "slow" code (should save 8 bytes, also minorly changed stuff so that the code works)

(84 bytes)
Code: [Select]
"[
For(A,0,7
For(B,0,1
Ans+sub("084C2A6E195D3B7F",sum(seq(2^Cpxl-Test(A,4B+C),C,0,3))+1,1
End
End
Ans+"]

Even provides the brackets necessary for Axe pics :P
Title: Re: Sprite to Hex Routines
Post by: leafy on March 27, 2011, 12:33:02 am
Well the end brackets aren't necessary, so I "optimize" even further. AHAHAHAHAHAHA

Code: [Select]
"[
For(A,0,7
For(B,0,1
Ans+sub("084C2A6E195D3B7F",sum(seq(2^Cpxl-Test(A,4B+C),C,0,3))+1,1
End
End
Title: Re: Sprite to Hex Routines
Post by: phenomist on March 27, 2011, 12:34:35 am
Hey, I save the user a keypress of the 2nd-].
Title: Re: Sprite to Hex Routines
Post by: leafy on March 27, 2011, 12:35:40 am
Well I never put end brackets anyways, since they're not needed by Axe and save space. The start brackets are necessary though.
Title: Re: Sprite to Hex Routines
Post by: phenomist on March 27, 2011, 12:36:27 am
Oh really?

Ok then. But my optimization actually required a bit of thinking -_-
Title: Re: Sprite to Hex Routines
Post by: meishe91 on March 27, 2011, 01:36:05 am
For the sake of the topic it is just to display it and/or store it so no need to make recalling it Axe friendly :P So I believe this will be the end of optimizations on that one :P (Unless further optimizations are made to make it smaller that displays the same thing, of course.) That is a very tricky optimization though, how did you figure out the string order?

Code: [Select]
"_
For(A,0,7
For(B,0,1
Ans+sub("084C2A6E195D3B7F",sum(seq(2^Cpxl-Test(A,4B+C),C,0,3))+1,1
End
End
sub(Ans,2,16
Title: Re: Sprite to Hex Routines
Post by: phenomist on March 27, 2011, 01:43:40 am
I reversed the bit order, so 0001 <=> 1000, 0010 <=> 0100, etc.

This was done to get rid of the (3-C).

(I do believe that you can perform a similar optimization to drop 4 bytes off the display-and-forget version, as well.)
Title: Re: Sprite to Hex Routines
Post by: meishe91 on March 27, 2011, 01:50:22 am
Ah okay, cool.
Title: Re: Sprite to Hex Routines
Post by: TIfanx1999 on March 27, 2011, 09:51:40 am
@ Meishe: TIfreak's drew the sprites to the graph screen from HEX data. So it was the opposite of what you guys are doing. Guess I overlooked that. :/ Still might be interesting to give it a look. :)
Title: Re: Sprite to Hex Routines
Post by: ztrumpet on March 27, 2011, 12:55:01 pm
Oh.  I got owned. :P  99 bytes > everything else.
I like the sum(seq( trick there - Nice coding! ;D
Title: Re: Sprite to Hex Routines
Post by: nemo on March 27, 2011, 01:35:13 pm
I reversed the bit order, so 0001 <=> 1000, 0010 <=> 0100, etc.

This was done to get rid of the (3-C).

(I do believe that you can perform a similar optimization to drop 4 bytes off the display-and-forget version, as well.)

yeah i was too lazy to switch that around when i wrote the original 92 byte one (it's on cemetech, probably posted about 6 months ago)