Author Topic: Hex to Sprite  (Read 2523 times)

0 Members and 1 Guest are viewing this topic.

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Hex to Sprite
« on: August 25, 2010, 10:44:41 pm »
it's memory consuming, and takes up your variables A-F, but for BASIC it's fast. your sprite data is in Str1.
Code: [Select]
10->A:11->B:12->C
13->D:14->E:15->F
For(Z,0,15
8fPart(Z/2->G
iPart(Z/2->H
expr(sub(Str1,Z+1,1
If Ans>7
Pxl-Change(H,G
If (Ans>3 and Ans<8) or Ans>11
Pxl-Change(H,G=1
If (Ans>1 and Ans<4) or (Ans>9 and Ans<12) or Ans=6 or Ans=7 or Ans>13
Pxl-Change(H,G+2
If fPart(Ans/2
Pxl-Change(H,G+3
End

to make it faster, you can change all the If's to If-Then-End's.

i also made a routine for octal data, where your sprite size is 9x8, since the data fitting into a byte isn't very important in basic. i think the following would work:
Code: [Select]
For(Z,0,23
int(9fPart(Z/3->A
iPart(Z/3->B
expr(sub(Str1,Z+1,1
If Ans>3
Pxl-Change(B,A
If Ans=2 or Ans=3 or Ans=6 or Ans=7
Pxl-Change(B,A+1
If fPart(Ans/2
Pxl-Change(B,A+2
End

but that code gives me a domain error on pxl-change, even when B and A are definitely in-bounds..



« Last Edit: October 31, 2010, 02:43:31 pm by nemo »


Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Hex to Sprite
« Reply #1 on: August 26, 2010, 01:08:09 am »
change 9fPart(Z/3->A to int(9fPart(Z/3->A and it should work.  The problem is rounding errors when dividing by odd numbers.  Since dividing by 3 always leaves a repeating decimal, the calculator is forced to round *somewhere*.  Then, you multiply by 3 again (when you multiply by 9 you multiply by 3 twice) and the rounded error is not lost.  So you end up with 6.000000000000001 or something.  On the homescreen this is actually displayed as 6, but if you try to pass it as an argument it gives errors.

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: Hex to Sprite
« Reply #2 on: August 26, 2010, 04:14:18 am »
Interesting, I wonder how fast does this runs? I might try it but not now because the code format isn't Source Coder and I don't feel like modifying it all right now :P.

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: Hex to Sprite
« Reply #3 on: August 26, 2010, 10:09:17 am »
Nice job!  That should run pretty fast.  Great work. :)