### Author Topic: How to draw a line using pxl-change?  (Read 7632 times)

0 Members and 1 Guest are viewing this topic.

#### guy6020665

• LV6 Super Member (Next: 500)
• Posts: 481
• Rating: +7/-1
##### How to draw a line using pxl-change?
« 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.

#### LincolnB

• Check It Out Now
• LV9 Veteran (Next: 1337)
• Posts: 1115
• Rating: +125/-4
• By Hackers For Hackers
##### Re: How to draw a line using pxl-change?
« Reply #1 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.
Completed Projects:
>> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
>> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.

Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)

#### fb39ca4

• LV10 31337 u53r (Next: 2000)
• Posts: 1749
• Rating: +60/-3
##### Re: How to draw a line using pxl-change?
« Reply #2 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?

#### LincolnB

• Check It Out Now
• LV9 Veteran (Next: 1337)
• Posts: 1115
• Rating: +125/-4
• By Hackers For Hackers
##### Re: How to draw a line using pxl-change?
« Reply #3 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 LNr3-r1->Ar4-r2->Br1*256->Cr2*256->GIf abs(A)>abs(B)abs(A)->ZElseabs(B)->ZEndRepeat r1=r3 or r2=r4 or getkey(15)A*256//Z+C->CB*256//Z+G->Gpxl-change(C//256,G//256)EndReturn
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)
Completed Projects:
>> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
>> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.

Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)

#### guy6020665

• LV6 Super Member (Next: 500)
• Posts: 481
• Rating: +7/-1
##### Re: How to draw a line using pxl-change?
« Reply #4 on: August 28, 2011, 02:34:27 pm »
Thanks. I'll give it a try.

#### LincolnB

• Check It Out Now
• LV9 Veteran (Next: 1337)
• Posts: 1115
• Rating: +125/-4
• By Hackers For Hackers
##### Re: How to draw a line using pxl-change?
« Reply #5 on: August 28, 2011, 06:40:26 pm »
Yep. Let me know how it turns out.
Completed Projects:
>> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
>> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.

Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)

#### guy6020665

• LV6 Super Member (Next: 500)
• Posts: 481
• Rating: +7/-1
##### Re: How to draw a line using pxl-change?
« Reply #6 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.

#### AngelFish

• Is this my custom title?
• LV12 Extreme Poster (Next: 5000)
• Posts: 3242
• Rating: +270/-27
• I'm a Fishbot
##### Re: How to draw a line using pxl-change?
« Reply #7 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.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

#### chattahippie

• LV6 Super Member (Next: 500)
• Posts: 358
• Rating: +27/-0
• Super Member! :D
##### Re: How to draw a line using pxl-change?
« Reply #8 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

#### Quigibo

• The Executioner
• CoT Emeritus
• LV11 Super Veteran (Next: 3000)
• Posts: 2031
• Rating: +1075/-24
##### Re: How to draw a line using pxl-change?
« Reply #9 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!
___Axe_Parser___
Today the calculator, tomorrow the world!

#### DJ Omnimaga

• Former TI programmer
• CoT Emeritus
• LV15 Omnimagician (Next: --)
• Posts: 55927
• Rating: +3152/-232
• CodeWalrus founder & retired Omnimaga founder
##### Re: How to draw a line using pxl-change?
« Reply #10 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.

#### guy6020665

• LV6 Super Member (Next: 500)
• Posts: 481
• Rating: +7/-1
##### Re: How to draw a line using pxl-change?
« Reply #11 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!

Wow that easy?
Thanks

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?
« Last Edit: August 30, 2011, 07:13:25 pm by guy6020665 »

#### chattahippie

• LV6 Super Member (Next: 500)
• Posts: 358
• Rating: +27/-0
• Super Member! :D
##### Re: How to draw a line using pxl-change?
« Reply #12 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.
« Last Edit: August 31, 2011, 06:28:40 am by chattahippie »

#### Quigibo

• The Executioner
• CoT Emeritus
• LV11 Super Veteran (Next: 3000)
• Posts: 2031
• Rating: +1075/-24
##### Re: How to draw a line using pxl-change?
« Reply #13 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.
___Axe_Parser___
Today the calculator, tomorrow the world!

#### guy6020665

• LV6 Super Member (Next: 500)
• Posts: 481
• Rating: +7/-1
##### Re: How to draw a line using pxl-change?
« Reply #14 on: August 31, 2011, 07:40:02 pm »
That would be great.

Also, is DrawL a token or do i manually type it in?
« Last Edit: August 31, 2011, 08:13:04 pm by guy6020665 »