Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: guy6020665 on August 27, 2011, 05:27:18 pm

Title: How to draw a line using pxl-change?
Post by: guy6020665 on August 27, 2011, 05:27:18 pm
So I'm working on a level editor for a platformer that I am currently working on, and I can't use the built in line command because if i did use it, the way I programmed it would cause it to overlap places it shouldn't overlap. Help please? I'm using 0.5.3 by the way, haven't been able to update in a while.
Title: Re: How to draw a line using pxl-change?
Post by: LincolnB on August 27, 2011, 05:41:43 pm
Why don't you try Bresenham's line algorithm, but use pxl-change instead of pxl-on? I wrote a subroutine in Axe that does that, you can have it if you want it. I'll upload it as soon as I can, if you want.
Title: Re: How to draw a line using pxl-change?
Post by: fb39ca4 on August 27, 2011, 06:54:50 pm
I don't understand why the default line drawer would not work, could you please explain? Do you need to just have a line drawer that toggles pixels rather than sets them?
Title: Re: How to draw a line using pxl-change?
Post by: LincolnB on August 27, 2011, 07:45:20 pm
I don't understand why the default line drawer would not work, could you please explain? Do you need to just have a line drawer that toggles pixels rather than sets them?

Yes, I think that's it.

Anyways, here's the subroutine:

Code: [Select]
Lbl LN
r3-r1->A
r4-r2->B
r1*256->C
r2*256->G
If abs(A)>abs(B)
abs(A)->Z
Else
abs(B)->Z
End
Repeat r1=r3 or r2=r4 or getkey(15)
A*256//Z+C->C
B*256//Z+G->G
pxl-change(C//256,G//256)
End
Return

I'm 95% sure this will work. You'll probably want to look through it yourself.

The routine accepts four arguments, called like so: sub(LN,X1,Y1,X2,Y2) ; and the function draws a line between (X1,Y1) and (X2,Y2)
Title: Re: How to draw a line using pxl-change?
Post by: guy6020665 on August 28, 2011, 02:34:27 pm
Thanks. I'll give it a try.
Title: Re: How to draw a line using pxl-change?
Post by: LincolnB on August 28, 2011, 06:40:26 pm
Yep. Let me know how it turns out.
Title: Re: How to draw a line using pxl-change?
Post by: guy6020665 on August 29, 2011, 06:28:12 pm
I haven't yet had time to try the code you gave me yet but i am uploading my current version of the game. After lvl 3 the screen will clear and leave only the person, just hit clear to exit. I'm also planning on adding Jumping code and moving platforms. (run no-stub) It's also currently unnamed.
Title: Re: How to draw a line using pxl-change?
Post by: AngelFish on August 29, 2011, 08:56:32 pm
So I'm working on a level editor for a platformer that I am currently working on, and I can't use the built in line command because if i did use it, the way I programmed it would cause it to overlap places it shouldn't overlap. Help please? I'm using 0.5.3 by the way, haven't been able to update in a while.

Hm, shouldn't that be just a change in from an OR to a XOR in the Axe line routine? I'm not sure if Axe's line routine is included in the documentation, but if it is, then that'd almost certainly be the best way to go.
Title: Re: How to draw a line using pxl-change?
Post by: chattahippie on August 29, 2011, 09:48:02 pm
So I'm working on a level editor for a platformer that I am currently working on, and I can't use the built in line command because if i did use it, the way I programmed it would cause it to overlap places it shouldn't overlap. Help please? I'm using 0.5.3 by the way, haven't been able to update in a while.

Hm, shouldn't that be just a change in from an OR to a XOR in the Axe line routine? I'm not sure if Axe's line routine is included in the documentation, but if it is, then that'd almost certainly be the best way to go.

Qwerty.55 is right
XOR would turn black pixels white, while OR would leave them black, as 1 XOR 1 is 0
Title: Re: How to draw a line using pxl-change?
Post by: Quigibo on August 30, 2011, 02:15:07 am
This would be an extremely easy Axiom to make since the routine is already written, you could just change a couple or's to xor's like others have been saying.  In fact its so easy, I just did it right now in 5 minutes.  Here you go, just include #Axiom(XLINE) and the syntax is DrawL(x1,y1,x2,y2) to make an inverted line.  Enjoy!  ;D
Title: Re: How to draw a line using pxl-change?
Post by: DJ Omnimaga on August 30, 2011, 02:32:02 am
By the way the game seems interesting so far. I'm curious how this will turn out. Also I'm glad you're still around and programming guy602665.
Title: Re: How to draw a line using pxl-change?
Post by: guy6020665 on August 30, 2011, 07:10:28 pm
This would be an extremely easy Axiom to make since the routine is already written, you could just change a couple or's to xor's like others have been saying.  In fact its so easy, I just did it right now in 5 minutes.  Here you go, just include #Axiom(XLINE) and the syntax is DrawL(x1,y1,x2,y2) to make an inverted line.  Enjoy!  ;D

Wow that easy?
Thanks    ;D

By the way the game seems interesting so far. I'm curious how this will turn out. Also I'm glad you're still around and programming guy602665.

Thanks DJ. I kind of stopped programming for a while because I was overloaded with school work, then when school started we went on a trip to visit practically all my family members, but now I'm back!  :)

EDIT: Just wondering, will this work on the back buffer too?
Title: Re: How to draw a line using pxl-change?
Post by: chattahippie on August 30, 2011, 07:17:17 pm
EDIT: Just wondering, will this work on the back buffer too?

It should, but I'm no Axe expert

EDIT: Wow, wasn't even thinking about the Axiom posted.  I was still referring to the code above.
Title: Re: How to draw a line using pxl-change?
Post by: Quigibo on August 31, 2011, 04:23:37 am
EDIT: Just wondering, will this work on the back buffer too?

The one I posted is only a routine for the front buffer, but I can add a 5 argument version if you need that functionality.
Title: Re: How to draw a line using pxl-change?
Post by: guy6020665 on August 31, 2011, 07:40:02 pm
That would be great.

Also, is DrawL a token or do i manually type it in?
Title: Re: How to draw a line using pxl-change?
Post by: LincolnB on August 31, 2011, 11:12:32 pm
I'm sure it's a token, but the question is, which TI-OS token does it replace?
Title: Re: How to draw a line using pxl-change?
Post by: guy6020665 on September 01, 2011, 08:18:38 pm
I've searched through the catalog but I didn't find anything.