Author Topic: Sprite to Hex Routines  (Read 5506 times)

0 Members and 1 Guest are viewing this topic.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Sprite to Hex Routines
« 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.
« Last Edit: March 27, 2011, 01:50:55 am by meishe91 »
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Sprite to Hex Routines
« Reply #1 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. :)

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Sprite to Hex Routines
« Reply #2 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?
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Sprite to Hex Routines
« Reply #3 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.

Offline phenomist

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 132
  • Rating: +46/-3
    • View Profile
Re: Sprite to Hex Routines
« Reply #4 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
« Last Edit: March 27, 2011, 12:30:29 am by phenomist »
Level Designer for Graviter

[Disclaimer: I can't program for my life.]

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Sprite to Hex Routines
« Reply #5 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
In-progress: Graviter (...)

Offline phenomist

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 132
  • Rating: +46/-3
    • View Profile
Re: Sprite to Hex Routines
« Reply #6 on: March 27, 2011, 12:34:35 am »
Hey, I save the user a keypress of the 2nd-].
Level Designer for Graviter

[Disclaimer: I can't program for my life.]

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Sprite to Hex Routines
« Reply #7 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.
In-progress: Graviter (...)

Offline phenomist

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 132
  • Rating: +46/-3
    • View Profile
Re: Sprite to Hex Routines
« Reply #8 on: March 27, 2011, 12:36:27 am »
Oh really?

Ok then. But my optimization actually required a bit of thinking -_-
Level Designer for Graviter

[Disclaimer: I can't program for my life.]

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Sprite to Hex Routines
« Reply #9 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
« Last Edit: March 27, 2011, 01:39:01 am by meishe91 »
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline phenomist

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 132
  • Rating: +46/-3
    • View Profile
Re: Sprite to Hex Routines
« Reply #10 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.)
« Last Edit: March 27, 2011, 01:45:18 am by phenomist »
Level Designer for Graviter

[Disclaimer: I can't program for my life.]

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Sprite to Hex Routines
« Reply #11 on: March 27, 2011, 01:50:22 am »
Ah okay, cool.
« Last Edit: March 27, 2011, 01:50:47 am by meishe91 »
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Sprite to Hex Routines
« Reply #12 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. :)

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Sprite to Hex Routines
« Reply #13 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

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Sprite to Hex Routines
« Reply #14 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)