Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: meishe91 on April 12, 2010, 04:09:56 pm

Title: Fast Image Copy-Paste Routine
Post by: meishe91 on April 12, 2010, 04:09:56 pm
So I recently made a copy and pasting program, some of you may know that already, but Builderboy gave me a idea about a different way of doing it that just has more restrictions. So since it is a pretty simple routine I came up with I thought I would share it here for anyone interested.

Note:
Really the only drawback with this method is that if you need to move the image somewhere where it would overlap the original position it will not work properly (sometimes it will, depending on the image; I may give an example of both).


Ok, the code for it:

Code: [Select]
For(A,Y',Y") //Y' is the starting Y coordinate and Y" is the ending.
For(B,X',X") //Same deal. X' is starting X coordinate and X" is the ending coordinate.
If pxl-Test(A,B
pxl-On(A±C,B±D //C and D are used to shift the image into the spot you want. Say the image is at (32,36) and
pxl-Off(A,B    //you want it at (0,0). C would equal -32 and D would be -36.
End
End

I hope this makes sense and is helpful to someone. I'll go over it later and try to show an example of when a pic can overlap coordinates, if I can manage it. Enjoy.

Edit:
I made it so that restriction is no longer applicable.
Title: Re: Fast Image Copy-Paste Routine
Post by: DJ Omnimaga on April 12, 2010, 10:39:51 pm
Nice, it might come useful for moving sprites around in a sprite sheet when you don't have xLIB, CODEX or Celtic handy. It might be best if you added Input Y':Input Y":Input X':Input X" at the beginning, though, for more user-friendliness :P
Title: Re: Fast Image Copy-Paste Routine
Post by: meishe91 on April 12, 2010, 10:43:37 pm
Well this is just the routine that does the work that I thought someone could just type in real fast when needed. I'm probably going to implement this method into my copy-paste program because this is smaller and more efficient.
Title: Re: Fast Image Copy-Paste Routine
Post by: DJ Omnimaga on April 12, 2010, 11:35:40 pm
Aaah ok, I just thought it might be better for user-friendliness. It's up to you, though.
Title: Re: Fast Image Copy-Paste Routine
Post by: meishe91 on April 13, 2010, 12:08:39 am
Well I mean I could its just that either way the person will have to type the program in manually because I don't plan to post a program file for that is all. They could just add it themselves. The reasons I put the variables there isn't to be used in the program but to be substituted for those values. I don't know if that makes sense but ya.
Title: Re: Fast Image Copy-Paste Routine
Post by: DJ Omnimaga on April 13, 2010, 12:21:59 am
Aaah ok I understand :)
Title: Re: Fast Image Copy-Paste Routine
Post by: meishe91 on April 13, 2010, 06:12:23 pm
I figured out today that if speed is more important then use this. It just is a added Then and End, oh and take the parentheses off the For('s. It doesn't make it a whole lot faster but it is faster none the less :P It is only two bytes bigger too. So yup. Works the same way.

Code: [Select]
For(A,Y',Y" //Y' is the starting Y coordinate and Y" is the ending.
For(B,X',X" //Same deal. X' is starting X coordinate and X" is the ending coordinate.
If pxl-Test(A,B
Then
pxl-On(A±C,B±D //C and D are used to shift the image into the spot you want. Say the image is at (32,36) and
pxl-Off(A,B    //you want it at (0,0). C would equal -32 and D would be -36.
End
End
End
Title: Re: Fast Image Copy-Paste Routine
Post by: DJ Omnimaga on April 13, 2010, 06:38:48 pm
Mhmm right I forgot about that part x.x
Title: Re: Fast Image Copy-Paste Routine
Post by: meishe91 on April 13, 2010, 06:54:12 pm
What part?
Title: Re: Fast Image Copy-Paste Routine
Post by: DJ Omnimaga on April 13, 2010, 07:34:18 pm
the optimization you just did. I didn't realize about it until you posted it, even thought I did that before x.x
Title: Re: Fast Image Copy-Paste Routine
Post by: meishe91 on April 13, 2010, 07:47:06 pm
Oh lol, ok. It doesn't make a huge difference in speed, about a second according to the timer fuction, but never tested with super big area.