Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / manual line

Author
Message
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 22nd May 2009 04:57
how would i go about recreating the line command?

if the line started at 0,0 then would I just take the slope of the line, m#, (y1-y2)/(x1-x2) and put it into these equations:

x=m#*(x1/maxx)
y=m#*(y1/maxy)

There are only 10 kinds of people in the world, those who understand binary and those who dont
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 22nd May 2009 05:45
The trouble with that is that calculating slope could return a /0 error.

What you could do is the vector form, where:

x=(startx)+t*(EndX-StartX)
Y=(startY)+t*(EndY-StartY)

And have t go from 0 to 1 in whatever increment you want.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 22nd May 2009 06:08
what is t?

i know u said it but im not getting it

There are only 10 kinds of people in the world, those who understand binary and those who dont
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 22nd May 2009 06:44 Edited at: 22nd May 2009 06:47
How did you find the slope in the first place? i know bn2 said not to use that for your thing but just wondering and i was thinking about it and i couldn't get it figured out.


Bn2:

Was the EndX - StartX part supposed to be the length of the line? if so that's not going to work. just making sure. i'm not sure what the "Vector Form" is so just wondering.

New Site! Check it out \/
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 22nd May 2009 07:36
if your line is from x1,y1 to x2,y2 then slope = (x1-x2)/(y1-y2) expressed as a simplified fraction

so a line from 0,0 to 2,3 has a slope of -3/-2 = 3/2 this means that for every 3 units the line goes UP it goes OVER 2 units

this is used in the formula y=m*x+b to make a line

y and x are constants, m is the slope (dont ask why slope is m), and b is the y-intercept, where the line crosses the y axis

that clear slope up for ya?

There are only 10 kinds of people in the world, those who understand binary and those who dont
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 22nd May 2009 09:06 Edited at: 22nd May 2009 09:13
If your line is x1,y1 to x2,y2 then StartX=x1 and EndX=x2

The "vector form" is a reference to a format for writing vectors in this model:

Vector=<x1,y1>+t*<xdiff,ydiff>

But xdiff=endx-startx and ydiff=endy-starty

So, broken down:

X=startx+t*(endx-startx)
Y=starty+t*(endy-starty)

Note that t is a variable that acts as a percent. So a value of 1 would be the full line.

Give me a few minutes to write up some example code.

[edit]
Observe. I apologize for the horribly written code, the important part is the For Next loop


The math break down is basically you start at a point, then you add a certain percentage of the difference from that point to the end point. So to find the middle, t would be .5

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 22nd May 2009 17:05 Edited at: 22nd May 2009 17:06
@BN2
Very clever!

@SmartGuy

Check out Bressenham's Algorithm:

Line Drawing

Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 22nd May 2009 18:29 Edited at: 22nd May 2009 18:34
nice failed link latch, u forgot to put /href at the end (hope that doesnt screw with this post)

There are only 10 kinds of people in the world, those who understand binary and those who dont
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 22nd May 2009 18:49
wouldn't work for whatever reason. That's why there's an edit in the post. I noticed it, tried to correct it, it just wouldn't take.

Let's try again:

Bressenham

Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 22nd May 2009 20:25
nope

There are only 10 kinds of people in the world, those who understand binary and those who dont
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 22nd May 2009 20:27
Should be able to just copy and paste the URL into the browser.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 22nd May 2009 22:17
that usually works

There are only 10 kinds of people in the world, those who understand binary and those who dont
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 22nd May 2009 22:59 Edited at: 22nd May 2009 23:49
Thanks! lol. i didn't think it would be X1-X2, i thought it would be X2-X1 to find the width thats odd. haha.

Quote: "m is the slope (dont ask why slope is m)"


I have always wondered the same thing! haha.


BN2:

that makes a very weird looking like. lots of spaces between dots. but i did find a way to make it all together. instead of using a int and a for/next loop i used a while loop and used a float, adding 0.1 every loop that makes a good line like this:

while NewT# < 100
NewT# = NewT# + 0.1
t#=NewT#
t#=t#/100
x#=x1+t#*(x2-x1)
y#=y1+t#*(y2-y1)
dot x#,y#
endwhile

New Site! Check it out \/
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 22nd May 2009 23:27
Hmmm, you could probably fix the spaces problem by using the LINE command rather than the DOT command.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 22nd May 2009 23:47 Edited at: 22nd May 2009 23:47
actually those spaces are the result of how your'e using the percent idea

it basicaly draws a dot every 1% of the line length, so every line has 100 dots in it, so a line 600 units long has a dot every 6 units

you could prolly correct this by changing your step value to 1% of the line length using a distance function, ill write up some code and post it

There are only 10 kinds of people in the world, those who understand binary and those who dont
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 22nd May 2009 23:51
I edited my first post and it has a easy way that works with any line size. and it takes about 2 milliseconds(isn't that what the timer is measured in?) with the largest line that can be drawn(Visible to the screen)

New Site! Check it out \/
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 22nd May 2009 23:54
caleb that works based on what I said above, so you could use that, but problem is it takes the EXACT same amount of time for 1 line 0,0 to 640,480 as on from 0,0 to 10,10, since it has to go through the loop 1000 time every line, im working on a version that will make shorter lines faster, will post it soon

There are only 10 kinds of people in the world, those who understand binary and those who dont
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 23rd May 2009 01:25
Oh Ok i see what your doing lol sweet! Good luck!

New Site! Check it out \/
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 23rd May 2009 01:37
actually this is step 1 of my 3 step plan

I was thinking about some of the differences between pro and DBC one day and I thought about how pro has a box gradient effect, you can specify a color for each corner of the box and pro would fill in the gradient

anyway, i got to thinking about how to recreate that in DBC and i decided to start small with a gradient line function, well from there I went to how to manually make a line so you could change the color of each dot of it

so step 1 - make a manual line (I have this done but I havent posted the function yet)

step 2 - make a gradient line (not hard I already have everything I need with my color percent function)

step 3 - turn that into a gradient box

like I said, I have the manual line almost done but I had to leave before I could post it, ill post it 2nite tho

There are only 10 kinds of people in the world, those who understand binary and those who dont
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 23rd May 2009 04:48
Why do you need a "Gradient Line" all you need is just use a regular line and change the rgb values. i did it in my windows GUI functions it's quite simple really.

New Site! Check it out \/
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 23rd May 2009 05:04
can you give me the code?

to make sure were on the same page, im defining gradient as having one end be one color, the other a second color and have it gradually change as you get closer to the other end

box is same way, but all four corners are different

There are only 10 kinds of people in the world, those who understand binary and those who dont
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 23rd May 2009 06:36 Edited at: 23rd May 2009 06:44
drum roll please, here is the function



[edit] forgot the other function, distance



[edit 2]

and with a few minor changes, heres the gradient line function, the distance function, and my color merge percent function



There are only 10 kinds of people in the world, those who understand binary and those who dont
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 23rd May 2009 16:45
NICE!

I thought you were just trying to make a gradient box. i didn't realize what you ment when yousaid you needed a "Gradient Line" thats pretty sweet!

New Site! Check it out \/
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 23rd May 2009 17:12
ya the gradient line worked out well, but I'm having some problems with the gradient box, ill try to get em worked out today though

There are only 10 kinds of people in the world, those who understand binary and those who dont
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 23rd May 2009 17:18 Edited at: 23rd May 2009 17:24
WOW THAT TURNED OUT AWESOME!!!!

EXACTLY LIKE PRO'S GRADIENT BOX EFFECT

heres all the functions, sorry there has to be 4 but it worked out amazing, try putting rgb(255,0,0), rgb(0,255,0), rgb(0,0,255), and rgb(255,255,255) (red, green, blue, white) into the function, its wicked!!



[edit]
nvm, false alarm, it worked awesome in pro, but not at all in DBC

also this is a great time to mention something I learned through this project, local variables (variables specific to functions) arent specific to EACH function, so if you have the same variable used in two functions and you call one in the other, then once the call is done and you return to the 1st function that variable will be equal to its value in the second, a big problem

There are only 10 kinds of people in the world, those who understand binary and those who dont
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 24th May 2009 03:19
Heres a gradient box function(Not using you gradient line)




Hope that helps. i have no idea why yours didn't work. it should have.... hmmm

New Site! Check it out \/
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 24th May 2009 03:24
kinda cool, but im tryin to get one where each corner can be different, ill try to adapt urs into that

There are only 10 kinds of people in the world, those who understand binary and those who dont
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 24th May 2009 15:54
Oh i see what you mean! that's why you had 4 colors.

New Site! Check it out \/
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 26th May 2009 09:45 Edited at: 26th May 2009 09:46
@That1SmartGuy
Quote: "also this is a great time to mention something I learned through this project, local variables (variables specific to functions) arent specific to EACH function, so if you have the same variable used in two functions and you call one in the other, then once the call is done and you return to the 1st function that variable will be equal to its value in the second, a big problem"

Do you have an example of this? I can't see the behavior you are describing. Here's a test:



Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 26th May 2009 16:34 Edited at: 26th May 2009 16:34
thats because after the sub function call you never used c and d again, add print c and print d after the function call and you will see



There are only 10 kinds of people in the world, those who understand binary and those who dont
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 26th May 2009 22:13
C and D print 1 + 2 when I run it.

Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 26th May 2009 22:20
ok, maybe I was wrong then, hmmmm that makes me think, o well so I guess I was wrong

There are only 10 kinds of people in the world, those who understand binary and those who dont
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 26th May 2009 22:35
You had me worried there for a minute , but if you come across what you saw happening again, please share. That could be a pretty big glitch with functions! Could you imagine, a whole 2d or 3d function library that uses x,y and z as variables that get changed any time any one function gets called? Yikes!

Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 26th May 2009 22:42
thats what worried me with this idea, I had 3 functions all using x1,y1,x2, and y2 as variables and they werent all the same so when it didnt work I edited the variable names and it worked so now im not sure what happened

There are only 10 kinds of people in the world, those who understand binary and those who dont
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 26th May 2009 22:51
If you have em, post the functions, we may be able to see what went wrong.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 26th May 2009 23:04 Edited at: 26th May 2009 23:04
heres the program, composed mainly of functions



There are only 10 kinds of people in the world, those who understand binary and those who dont

Login to post a reply

Server time is: 2025-06-08 11:18:43
Your offset time is: 2025-06-08 11:18:43