Hey all, I am making a basic sprite program and need help with the sub( command.

Code:

:"01010101010101010101010"-> Strg1  -(64 char) for 8*8 sprite
:zstandard
:zinteger
:axesoff
:clrdraw
:xmin->B
:ymax->C
:For(A,1,length(strg1)
:If sub(str1,?,?)="1"
:pt-on(B,C)
:If A=8:then
:xmin->B
:C-1->C
:end
:x+1->x
:End

This is supposed to draw a sprite using this, but I need help filling in the ?marks, if someone could help that would be great.
Thanks
p.s. this would allow for basic programmers to store sprites in their program (like axe/asm users) instead of a pic.
If sub(Str1,A,1)="1

However, that won't work. A will only be 8 once, then it's just going to keep going.

2 For( loops generally works best for this. But I think I would like to see you make the above work, first :p

Code:

:"01010101010101010101010"-> Strg1  -(64 char) for 8*8 sprite
:zstandard
:zinteger
:axesoff
:clrdraw
:xmin->B
:ymax->C
:0->D
:For(A,1,length(strg1)
:If sub(str1,?,?)="1"
:pt-on(B,C)
:If A=8*D:then
:B+8->B
:C-1->C
:D+1->D
:end
:x+1->x
:End

how about that?
What you actually want to do is check if A is a multiple of 8, correct? Therefore, you want to know if A mod 8 = 0, usually written A%8=0, which means that the remainder of A/8 is zero. You can calculate that like this:


Code:
If int(A/8) = A/8
KermMartian wrote:
What you actually want to do is check if A is a multiple of 8, correct? Therefore, you want to know if A mod 8 = 0, usually written A%8=0, which means that the remainder of A/8 is zero. You can calculate that like this:


Code:
If int(A/8) = A/8

You could optimize that to

Code:
not(fPart(A/8))
That would return 1 if A is divisible by 8.
You most certainly could. For future reference, if you want the actual mod value, rather than simply checking if it's zero, then A%B=BfPart(A/B).
That works, any way I could make this faster (wait it is stupid basic, my bad for even attempting to ask that lol), because that for( loop draws each pixel one at a time is pretty lame after programing axe and z80.
Unfortunately, you can't make that significantly faster by just using TI-BASIC. You could use an ASM lib to draw sprites for you, though. Smile
http://dcs.cemetech.net/index.php?title=BasicLibs:DrawSprite
souvik1997 wrote:
Unfortunately, you can't make that significantly faster by just using TI-BASIC. You could use an ASM lib to draw sprites for you, though. Smile
http://dcs.cemetech.net/index.php?title=BasicLibs:DrawSprite
Exactly this. Take a look at all the BASIC libraries that Doors CS gives you:

http://dcs.cemetech.net/index.php?title=Third-Party_BASIC_Libraries
http://dcs.cemetech.net/index.php?title=DCSB_Libs
That the whole point drawing sprites without the use of libraries, such as celtic,picarc,batlib,xlib,or doorslib. *curses basic
calcman wrote:
That works, any way I could make this faster (wait it is stupid basic, my bad for even attempting to ask that 0x5), because that for( loop draws each pixel one at a time is pretty lame after programing axe and z80.


I take offense to that 'it is stupid basic'

http://www.ticalc.org/archives/files/fileinfo/385/38508.html

It's not instant like asm, but it is as fast as it will get.

Edit:



The NPC sprites being displayed are with the program I linked to above. The program was first started by me and optimized by Weregoose a looong time ago.
I will find a way to make this faster (I think)
*takes a oath upon his calculator
calcman wrote:
I will find a way to make this faster (I think)
*takes a oath upon his calculator
You're not going to find a faster way than TIFreak8x's method; he's the undisputed king of pure BASIC graphics. Smile
Okay, I will do something else...


Edit: that screen show is very slow, no offense tifreak8x
calcman wrote:
Okay, I will do something else...

Edit: that screen show is very slow, no offense tifreak8x
For an icon routine written in pure BASIC, that's ridiculously fast. Smile
calcman wrote:
Okay, I will do something else...


Edit: that screen show is very slow, no offense tifreak8x


Depends on what browser you use. I am using Chrome, and it blazes, which is what it does on calc. There are some browsers that are stupidly slow displaying .gif files.
tifreak8x wrote:
calcman wrote:
Okay, I will do something else...


Edit: that screen show is very slow, no offense tifreak8x


Depends on what browser you use. I am using Chrome, and it blazes, which is what it does on calc. There are some browsers that are stupidly slow displaying .gif files.


Up to a few versions ago Chrome was one of those slow ones too. Glad they fixed that.

And even if you're seeing it in full speed, that is actually really fast for graphics in BASIC Smile
Oh, an optimization from the original poster's code, just to pretend that this topic is still any semblence of on-topic:


Code:
:If sub(str1,?,?)="1"
can be optimized to
Code:
:If "1"=sub(str1,?,?

OR

:If sub(Str1,?,?)="1
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement