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

0 Members and 1 Guest are viewing this topic.

Offline guy6020665

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 481
  • Rating: +7/-1
    • View Profile
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.

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
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)



Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
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?

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
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 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)
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)



Offline guy6020665

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 481
  • Rating: +7/-1
    • View Profile
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.

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
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)



Offline guy6020665

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 481
  • Rating: +7/-1
    • View Profile
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.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
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²        ℏ²Ψ

Offline chattahippie

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +27/-0
  • Super Member! :D
    • View Profile
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

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
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!  ;D
___Axe_Parser___
Today the calculator, tomorrow the world!

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: 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.

Offline guy6020665

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 481
  • Rating: +7/-1
    • View Profile
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!  ;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?
« Last Edit: August 30, 2011, 07:13:25 pm by guy6020665 »

Offline chattahippie

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +27/-0
  • Super Member! :D
    • View Profile
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 »

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
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!

Offline guy6020665

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 481
  • Rating: +7/-1
    • View Profile
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 »