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.

Geek Culture / how to make a line using dot

Author
Message
Three Score
20
Years of Service
User Offline
Joined: 18th Jun 2004
Location: behind you
Posted: 6th Jun 2005 07:32
im actually making this in C but the concept is the same i need to make a line using x1,y1,x2,y2 coordinates using only the dot command
i just dont know how to do it really and i badly need the command


(i hate having to reinvent the wheel)

formerly shadows of emptiness
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 6th Jun 2005 07:56 Edited at: 6th Jun 2005 07:57
work out gradient of line using dy/dx:

grad# = (y2-y1)/(x2-x1)

Equation of a line is y = grad#*x + c

Work out c by rearranging:

c# = y1 - grad#*x1

now you have c# and grad# loop through the x positions and get the y position then plot the point:

for x = x1 to x2
y = grad#*x + c#
dot x,y
next

That's it. Just make sure that you round numbers to whole number where necessary (for pixel points etc). and make sure you arrange the numbers such that x1 is smaller than x2.



Edit: That's the basics sorry. That could potentially give you dotty unjoined lines for high gradients, so you'll need to add some more code to cope with that, but that should get you started.

Three Score
20
Years of Service
User Offline
Joined: 18th Jun 2004
Location: behind you
Posted: 6th Jun 2005 08:37
hmmm
intresting glad u posted the forumla for grad
but i really dont want to use decimals do u know if u use a int or some other non float number if it will automatically round

and thanks but im not sure what to add ive got something im still working on that SHOULD do lines perfect according to the way it is run but im afraid it may be slow but it wont work right now it wont display anything and i know my putdot function works cause i have tested it alone

here is my incomplete code and yes i know i should replace that while loop with a for


formerly shadows of emptiness
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 6th Jun 2005 09:03


You know the Programming talk section is a better place for programming stuff.

dbhelp - online dbpro help files with user comments
Three Score
20
Years of Service
User Offline
Joined: 18th Jun 2004
Location: behind you
Posted: 6th Jun 2005 09:13
yes i thought that it would be more simple and just needed a formula mainly but well...

formerly shadows of emptiness
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 6th Jun 2005 09:16
well there's a few ways.. easiest is just to drop FP

(int)fResult; // would do roughtly what your after.
just out of interest what is this for?

because I could explain how to access the Video Buffer directly to plot your points, without needing any ASM or such.

Three Score
20
Years of Service
User Offline
Joined: 18th Jun 2004
Location: behind you
Posted: 6th Jun 2005 11:21
uhh im just making a little os no big aim or anything just to have fun since i finally figured out how to make a kernel in C

how would u go about accessing video buffer anyway wouldnt i need to be in a graphical mode also(generic mode 0x13)
i got a putdot command built though so im not sure why i would want to and is (int)fresult; in some header file cause im nto allowed to use any

formerly shadows of emptiness
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 6th Jun 2005 13:49
no.. it's how you recast a value

(int)1.0f; would be the same as writing Int(1.0) in DB/P

obviously when you have to fit data into smaller areas that was originally intended you've go to do a recast function that works in the memory.. or data pointing is another one that needs recasting.

what are you making the OS in?
Because some versions of C++ like GCC have headers specifically for accessing Registers and such.

you want to really visit [http://www.osdever.net]OS-Dever.net[/url] cause they have a lot of info pretty good for starting out

Three Score
20
Years of Service
User Offline
Joined: 18th Jun 2004
Location: behind you
Posted: 6th Jun 2005 15:57
awesome
thanks
and no i was developing in gcc but i cant install linux on my pc and i dont want to boot up a virtual pc everytime i do anything but i have tried gcc i really like it in linux cause u can write to raw devices easy(very easy infact)
what do the headers contain cause ive got a pretty good start already of low level functions and then i got 3 midlevel(that use lowlevel functions instead of asm and usually have a bit of functionality to them) functions only 1 works though

at this point i probably wont switch

formerly shadows of emptiness

Login to post a reply

Server time is: 2024-11-15 06:05:43
Your offset time is: 2024-11-15 06:05:43