dMZX Forums: How to draw a line like a boss - dMZX Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to draw a line like a boss

#1 User is offline   Graham 

  • . "@Master Procrastinator"
  • PipPipPipPip
  • Group: Members
  • Posts: 625
  • Joined: 28-December 12
  • Gender:Male
  • Location:Oregon

Posted 16 January 2013 - 09:45 PM

I'm trying to figure out how to draw a line on the board, connecting two blocks. It has to be a dynamic program that can redraw the line depending on where one block moves in relation to the other.

This is for a laser sight I'm building into my players gun. I'm sure this is possible somehow, but I never excelled at math and it seems like a math problem. Something like dividing the X by the Y axis to determine the angle. For instance, it may drop 1 block vertically for every 4 blocks it travels horizontally. I'd need to pixel edit the 4 blocks so a line appears to travel through them diagonally and repaste those 4 blocks along the path of the line until it reaches the destination block. Probably involve sprites somehow. I love using sprites.

Thing is, I have limited characters to work with. I couldn't justify setting aside more than 4 chars at most. Any thoughts? Am I nuts for wanting to do this? Should I settle for a single character with just a simple dot in the middle, so it appears as a dotted line between two locations?
Currently working on Servo for MegaZeux, I hope to complete it by the middle of 2015? Who knows...

"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
0

#2 User is offline   Graham 

  • . "@Master Procrastinator"
  • PipPipPipPip
  • Group: Members
  • Posts: 625
  • Joined: 28-December 12
  • Gender:Male
  • Location:Oregon

Posted 16 January 2013 - 10:11 PM

Along these same lines, I need to create a curved trajectory for a sprite to follow. This simulates a bomb being tossed through the air. Like a sign wave. This is probably a much simpler problem to solve with math in robotic. Thing is, I don't even understand how to create a sign wave.
Currently working on Servo for MegaZeux, I hope to complete it by the middle of 2015? Who knows...

"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
0

#3 User is offline   Lachesis 

  • the pinnacle of human emotion
  • Group: DigiStaff
  • Posts: 3,895
  • Joined: 17-July 04
  • Gender:Female
  • Location:Sealand

Posted 16 January 2013 - 11:58 PM

Curved trajectory: This will draw a white line of customblocks that follows an arc between the origin [x1,y1] and the target [x2,y2]. With little work it can be modified to be used by a projectile. Adjust 's' to modify how high it arcs. It doesn't work very well if you're trying to throw it straight up :(/>/>/>/>/>
. "how many times we're going to subdivide the arc"
set "steps" to 100

set "x1" to 20
set "y1" to 20
set "x2" to 20
set "y2" to 1

. "the destination relative to the origin"
set "x" to "('x2'-'x1')"
set "y" to "('y2'-'y1')"

. "if x is 0, this doesn't work, so fudge it"
inc "x" by "('x'=0)"

. "reciprocal of the slope of the curve, since we can't have decimals"
set "s" to 40

. "solve for the root that will make the arc pass through the destination, and put it in terms of our subdivisions"
set "a" to "('s'*'y'/'x'-'x'*-'steps')"

loop start
. "the x coord of the current position relative to the origin and in terms of subdivisions"
set "!" to "('x'*'LOOPCOUNT')"
. "if we divide out the subdivisions and add the origin x, we get the current x"
set "!x" to "('!'/'steps'+'x1')"
. "solve the quadratic equation for the y coordinate, divide our slope in, divide out steps twice (since we squared '!'), add the origin y to get the current y"
set "!y" to "('!'-'a'*'!'/'s'/'steps'/'steps'+'y1')"
. "draw"
put cff CustomBlock p00 at "!x" "!y"
. "loop for the number of subdivisions"
loop for "steps"

end



EDIT: fixed a bug
EDIT 2: fixed another bug
EDIT 3: just redid it entirely
EDIT 4: comments

For drawing the laser sight line, I'd stongly suggest dotting it. I'll give that a look in a little bit.
"Let's just say I'm a GOOD hacker, AND virus maker. I'm sure you wouldn't like to pay for another PC would you?"

xx̊y (OST) - HELLQUEST (OST) - Zeux I: Labyrinth of Zeux (OST) (DOS OST)
w/ Lancer-X and/or asgromo: Pandora's Gate - Thanatos Insignia - no True(n) - For Elise OST
MegaZeux: Online Help File - Keycode Guide - Joystick Guide - Official GIT Repository
0

#4 User is offline   CJA 

  • «≡larch bucket≡»
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 3,262
  • Joined: 23-June 05
  • Gender:Male
  • Location:......@.c....

Posted 17 January 2013 - 02:07 AM

EDIT: Whoops, looks like you wanted something pixel-perfect, right? I don't mess with PP in MZX, but if you just want to draw a nice blocky line, this might help:

Spoiler

This post has been edited by CJA: 17 January 2013 - 02:09 AM

Need a dispenser here.
0

#5 User is offline   Dr Lancer-X 

  • 電波、届いた?
  • Group: DigiStaff
  • Posts: 8,936
  • Joined: 20-March 02
  • Location:ur mom nmiaow

Posted 17 January 2013 - 02:43 AM

With respect to the line, you're screwed unless you want to just have it work with specific angles, in which case it would be easier to just draw the line chars yourself.

Most lines will not be possible to draw with 4 repeating chars.
Posted Image
<Malwyn> Yes, yes. Don't worry I'd rather masturbate with broken glass than ask you for help again. :(
0

#6 User is offline   Exophase 

  • Laughing on the inside.
  • Group: DigiStaff
  • Posts: 7,155
  • Joined: 23-October 00
  • Gender:Male
  • Location:Cleveland, OH

Posted 17 January 2013 - 03:10 AM

Maybe he could pick 4 random chosen chars along the line and draw those, picking new ones every frame? That might be a neat effect or give someone a seizure.

You know, like what NES games to get around a small number of sprites that could appear on a line simultaneously.
~ ex0 has a kickass battle engine, without it you sux0rz! without it you sux0rz! ~

"The fact that I say I've one of the best, is called honesty." -Akwende
"Megazeux is not ment to be just ASCII, it is ANSI!" - T-bone6
"I hate it when you get all exo on me." - emalkay

Exophase can what Rubi-cant.
exoware is ware ur ware is exoware
ps. not loking 4 new membrs kthx
0

#7 User is offline   Graham 

  • . "@Master Procrastinator"
  • PipPipPipPip
  • Group: Members
  • Posts: 625
  • Joined: 28-December 12
  • Gender:Male
  • Location:Oregon

Posted 17 January 2013 - 03:13 AM

Cool thanks guys. I'll try and mess with this tonight.
Lachesis, I'll try this code tonight and see if I can make sense of it. :-) I think I can use it in my game, in which case ill credit you for the help.
CJA, that may help me with what I'm trying to do. At least it gives me some avenue to try. Thanks.
Lancer-X, I'm think I'll try and draw the line chars my self. Thanks.
Exophase, I had a similar thought. I'm not sure if I'll like the flicker, but I may give it a try. Thank you.

This post has been edited by Graham: 17 January 2013 - 03:17 AM

Currently working on Servo for MegaZeux, I hope to complete it by the middle of 2015? Who knows...

"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
0

#8 User is offline   Dr Lancer-X 

  • 電波、届いた?
  • Group: DigiStaff
  • Posts: 8,936
  • Joined: 20-March 02
  • Location:ur mom nmiaow

Posted 17 January 2013 - 04:05 AM

View PostExophase, on 17 January 2013 - 01:10 PM, said:

Maybe he could pick 4 random chosen chars along the line and draw those, picking new ones every frame? That might be a neat effect or give someone a seizure.

On speed 2 it could be bearable, although I think you'd still want more than 4 chars. 4 chars is really very few.
Posted Image
<Malwyn> Yes, yes. Don't worry I'd rather masturbate with broken glass than ask you for help again. :(
0

#9 User is offline   Risu2112 

  • I can't get the top off this bottle
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,864
  • Joined: 12-August 01
  • Gender:Male

Posted 17 January 2013 - 05:44 AM

Exo's idea might be reasonable for your requirements. SFmzx reserves 8-10 characters for it's laser weapons, and as you can see from the video in my sig, or from playing it your self, that doesn't result in very long lines at all.
Respond! Vibrate! Feed back! Resonate!
<Cybersilver> "All my sugestions are for FUTER VERSIONS. Say it with me Fu-ter futer. Yep..."
9-21-2009, SFMZX game play video: HERE
Risu2112
0

#10 User is offline   Graham 

  • . "@Master Procrastinator"
  • PipPipPipPip
  • Group: Members
  • Posts: 625
  • Joined: 28-December 12
  • Gender:Male
  • Location:Oregon

Posted 17 January 2013 - 03:20 PM

Risu, I'll check that out. Any other games that use laser weapons that you could think of?
Currently working on Servo for MegaZeux, I hope to complete it by the middle of 2015? Who knows...

"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
0

#11 User is offline   LogiCow 

  • Holiday cow
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,671
  • Joined: 18-July 02
  • Gender:Male
  • Location:Quebec

Posted 20 January 2013 - 06:38 AM

I made a line drawing algorithm forever ago, found the link to the thread but the file itself is gone

http://www.digitalmz...=1

it's from 2006, which is something like 7 years ago.

I might have it on my PC but it's not plugged in and I can't bother.

Anyhow... the trick is to optimize horizontal lines to draw multiple pixels at a time.

With 4 chars you can't draw within the characters.
The best you can do is have a char that is a single vertical line in the middle, use it for all vertical lines, and have three chars with horizontal lines that are at ~ 1/6, 3/6, 5/6th of the way down the character respectively.

This post has been edited by LogiCow: 20 January 2013 - 06:39 AM

0

#12 User is offline   Graham 

  • . "@Master Procrastinator"
  • PipPipPipPip
  • Group: Members
  • Posts: 625
  • Joined: 28-December 12
  • Gender:Male
  • Location:Oregon

Posted 21 January 2013 - 09:41 PM

Wow, from reading the posts in that thread, I really wish the the file was still there. It sounds like it would have been really cool to check it out. oh well. I haven't given up on the idea yet, i'm pretty sure I can figure something suitable out.
Currently working on Servo for MegaZeux, I hope to complete it by the middle of 2015? Who knows...

"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
0

#13 User is offline   Graham 

  • . "@Master Procrastinator"
  • PipPipPipPip
  • Group: Members
  • Posts: 625
  • Joined: 28-December 12
  • Gender:Male
  • Location:Oregon

Posted 23 January 2013 - 09:17 AM

Attached File  laser bomb test.zip (4.86K)
Number of downloads: 4

So this is pretty cool. Thanks very much Lachesis, CJA, Exophase, and all the rest of you for the input. I think this is going to work nicely.

It's basically Lachesis's program, for bombing it was as she made it. For shooting, I flattened the slope so it drew in a straight line and reduced the steps to make it appear as though it was going faster. Since I don't understand the math, I just fooled around a bit until I came up with this. I may have been able to do it more efficiently, I don't know. But this works. Hold space to shoot, press control to throw a bomb. In my game, you will be able to move a sight up and down and it will land on either customblocks or sprites. The laser beam follows the sight. Also, its 2d sidescrolling, hence the trajectory for the bomb.

Thanks again for the input. Night all.

P.S. You will be credited in the game too.

This post has been edited by Graham: 23 January 2013 - 09:19 AM

Currently working on Servo for MegaZeux, I hope to complete it by the middle of 2015? Who knows...

"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
0

#14 User is offline   Graham 

  • . "@Master Procrastinator"
  • PipPipPipPip
  • Group: Members
  • Posts: 625
  • Joined: 28-December 12
  • Gender:Male
  • Location:Oregon

Posted 21 September 2016 - 07:17 PM

View PostLachesis, on 16 January 2013 - 03:58 PM, said:

Curved trajectory: This will draw a white line of customblocks that follows an arc between the origin [x1,y1] and the target [x2,y2]. With little work it can be modified to be used by a projectile. Adjust 's' to modify how high it arcs. It doesn't work very well if you're trying to throw it straight up :(/>/>/>/>/>/>
. "how many times we're going to subdivide the arc"
set "steps" to 100

set "x1" to 20
set "y1" to 20
set "x2" to 20
set "y2" to 1

. "the destination relative to the origin"
set "x" to "('x2'-'x1')"
set "y" to "('y2'-'y1')"

. "if x is 0, this doesn't work, so fudge it"
inc "x" by "('x'=0)"

. "reciprocal of the slope of the curve, since we can't have decimals"
set "s" to 40

. "solve for the root that will make the arc pass through the destination, and put it in terms of our subdivisions"
set "a" to "('s'*'y'/'x'-'x'*-'steps')"

loop start
. "the x coord of the current position relative to the origin and in terms of subdivisions"
set "!" to "('x'*'LOOPCOUNT')"
. "if we divide out the subdivisions and add the origin x, we get the current x"
set "!x" to "('!'/'steps'+'x1')"
. "solve the quadratic equation for the y coordinate, divide our slope in, divide out steps twice (since we squared '!'), add the origin y to get the current y"
set "!y" to "('!'-'a'*'!'/'s'/'steps'/'steps'+'y1')"
. "draw"
put cff CustomBlock p00 at "!x" "!y"
. "loop for the number of subdivisions"
loop for "steps"

end



EDIT: fixed a bug
EDIT 2: fixed another bug
EDIT 3: just redid it entirely
EDIT 4: comments

For drawing the laser sight line, I'd stongly suggest dotting it. I'll give that a look in a little bit.


Lachesis-this code is very helpful and I've employed it in quite a number of different ways in my game. I'm wondering though if there is a way to draw the entire arc in one cycle? There arent any cycle ending commands in the loop so I don't really understand how it behaves as it takes several cycles to draw the arc across the screen.
Currently working on Servo for MegaZeux, I hope to complete it by the middle of 2015? Who knows...

"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
0

#15 User is offline   Dr Lancer-X 

  • 電波、届いた?
  • Group: DigiStaff
  • Posts: 8,936
  • Joined: 20-March 02
  • Location:ur mom nmiaow

Posted 21 September 2016 - 08:29 PM

maybe your commands counter is set too low
Posted Image
<Malwyn> Yes, yes. Don't worry I'd rather masturbate with broken glass than ask you for help again. :(
0

#16 User is offline   Graham 

  • . "@Master Procrastinator"
  • PipPipPipPip
  • Group: Members
  • Posts: 625
  • Joined: 28-December 12
  • Gender:Male
  • Location:Oregon

Posted 21 September 2016 - 09:13 PM

Oh snap! That was it, thanks
Currently working on Servo for MegaZeux, I hope to complete it by the middle of 2015? Who knows...

"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
0

#17 User is offline   Lachesis 

  • the pinnacle of human emotion
  • Group: DigiStaff
  • Posts: 3,895
  • Joined: 17-July 04
  • Gender:Female
  • Location:Sealand

Posted 21 September 2016 - 10:35 PM

funny enough, we're going over numerical methods for polynomial interpolation in a class at the moment and that code sort of makes me feel weird now : (
"Let's just say I'm a GOOD hacker, AND virus maker. I'm sure you wouldn't like to pay for another PC would you?"

xx̊y (OST) - HELLQUEST (OST) - Zeux I: Labyrinth of Zeux (OST) (DOS OST)
w/ Lancer-X and/or asgromo: Pandora's Gate - Thanatos Insignia - no True(n) - For Elise OST
MegaZeux: Online Help File - Keycode Guide - Joystick Guide - Official GIT Repository
0

#18 User is offline   Lachesis 

  • the pinnacle of human emotion
  • Group: DigiStaff
  • Posts: 3,895
  • Joined: 17-July 04
  • Gender:Female
  • Location:Sealand

Posted 22 September 2016 - 12:11 AM

here's a more efficient piece of sh$&*&!$

set "COMMANDS" to "(10000)"

. "x0,y0 - board position for the origin (i.e. player position)"
. "x1,y1 - board position RELATIVE to x0,y0 for the midpoint"
. "x2,y2 - board position RELATIVE to x0,y0 for the destination"

. "inputs"
set "x0" to 0
set "y0" to 24
. "x1 = (x0+x2)/2 is implicit"
set "y1" to -22
set "x2" to 79
set "y2" to -10

. "steps - the number of subdivisions to draw"
. "fp    - fixed y multiplier to help the curve look less nasty"
. "u1,u2 - adjusted y1,y2"

set "steps" to 100
set "fp" to 10
set "u1" to "('y1'*'fp')"
set "u2" to "('y2'*'fp')"

. "x = pretty straightforward"
. "y = look it just works trust me"

loop start
put cff 'A' overlay to "('x2'*'LOOPCOUNT'/'steps'+'x0')" "(-2*'u1'+'u2'*2*'LOOPCOUNT'/'steps'+'u1'+'u1'+'u1'+'u1'-'u2'*'LOOPCOUNT'/'steps'/'fp'+'y0')"
loop for "steps"


the idea is that instead of some vague "slope" value, you can just define a middle Y value in this version that is actually intuitive. how you determine that Y value is totally up to you (i.e. it could be y1 = y2 - (some constant))

like with last time, you should probably vary steps based on the distance too
"Let's just say I'm a GOOD hacker, AND virus maker. I'm sure you wouldn't like to pay for another PC would you?"

xx̊y (OST) - HELLQUEST (OST) - Zeux I: Labyrinth of Zeux (OST) (DOS OST)
w/ Lancer-X and/or asgromo: Pandora's Gate - Thanatos Insignia - no True(n) - For Elise OST
MegaZeux: Online Help File - Keycode Guide - Joystick Guide - Official GIT Repository
0

#19 User is offline   Graham 

  • . "@Master Procrastinator"
  • PipPipPipPip
  • Group: Members
  • Posts: 625
  • Joined: 28-December 12
  • Gender:Male
  • Location:Oregon

Posted 22 September 2016 - 02:15 AM

View PostLachesis, on 21 September 2016 - 04:11 PM, said:

here's a more efficient piece of sh$&*&!$

set "COMMANDS" to "(10000)"

. "x0,y0 - board position for the origin (i.e. player position)"
. "x1,y1 - board position RELATIVE to x0,y0 for the midpoint"
. "x2,y2 - board position RELATIVE to x0,y0 for the destination"

. "inputs"
set "x0" to 0
set "y0" to 24
. "x1 = (x0+x2)/2 is implicit"
set "y1" to -22
set "x2" to 79
set "y2" to -10

. "steps - the number of subdivisions to draw"
. "fp    - fixed y multiplier to help the curve look less nasty"
. "u1,u2 - adjusted y1,y2"

set "steps" to 100
set "fp" to 10
set "u1" to "('y1'*'fp')"
set "u2" to "('y2'*'fp')"

. "x = pretty straightforward"
. "y = look it just works trust me"

loop start
put cff 'A' overlay to "('x2'*'LOOPCOUNT'/'steps'+'x0')" "(-2*'u1'+'u2'*2*'LOOPCOUNT'/'steps'+'u1'+'u1'+'u1'+'u1'-'u2'*'LOOPCOUNT'/'steps'/'fp'+'y0')"
loop for "steps"


the idea is that instead of some vague "slope" value, you can just define a middle Y value in this version that is actually intuitive. how you determine that Y value is totally up to you (i.e. it could be y1 = y2 - (some constant))

like with last time, you should probably vary steps based on the distance too


Oh yeah, I can really see the value in that. Being able to define the height of the slope to keep it from being too high when aiming for something a distance away could be very useful. Thank you! I'll see if I can use it.
Currently working on Servo for MegaZeux, I hope to complete it by the middle of 2015? Who knows...

"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
0

#20 User is offline   Lachesis 

  • the pinnacle of human emotion
  • Group: DigiStaff
  • Posts: 3,895
  • Joined: 17-July 04
  • Gender:Female
  • Location:Sealand

Posted 22 September 2016 - 02:20 AM

y1 isn't necessarily the maximum value of the curve, but it's generally not too far off*

here's a graph of the example curve my code calculates with the points it uses marked


*in many of the situations I think you'd want to use it in, anyway. it's still better than "s", because you can at least make an educated guess and fine tune it to nearby values if your initial y1 doesn't work.
"Let's just say I'm a GOOD hacker, AND virus maker. I'm sure you wouldn't like to pay for another PC would you?"

xx̊y (OST) - HELLQUEST (OST) - Zeux I: Labyrinth of Zeux (OST) (DOS OST)
w/ Lancer-X and/or asgromo: Pandora's Gate - Thanatos Insignia - no True(n) - For Elise OST
MegaZeux: Online Help File - Keycode Guide - Joystick Guide - Official GIT Repository
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users