Page 1 of 1
How do you make a line without the line command?
Posted: Sat Mar 03, 2012 11:01 am
by Bp103
I've been trying to figure out how to recreate the line command in Qbasic for a while now but I've been failing at it. I've also googled for this too but it turns up useless results that all use a line command of some sort.
how do you make a line from point(x,y) to point(x2,y2) with out the line command?
E.g. to draw a circle its
Code: Select all
x=50
y=50
r=10
for i=0 to 360 step .1
x2=x+(r*sin(i*3.141/180))
y2=y+(r*cos(i*3.141/180))
pset(x2,y2), _rgb(255,255,255)
next
This'll really help me out when I need to make a line in things that can't use the line command like text mode or a unsupported vesa mode. Thanks.
Posted: Sat Mar 03, 2012 2:57 pm
by burger2227
You cannot use graphics like PSET to draw a line in text mode.
You can only draw text lines using ASCII characters.
Your example needed an underscore before _RGB for QB64.
Posted: Sat Mar 03, 2012 9:16 pm
by Bp103
burger2227 wrote:You cannot use graphics like PSET to draw a line in text mode.
You can only draw text lines using ASCII characters.
Yes.
Code: Select all
x=5
y=5
r=4
for i=0 to 360
x2=x+(r*sin(i*3.141/180))
y2=y+(r*cos(i*3.141/180))
locate y2,x2
print"x"
next
Also It was a snip from my FreeBasic project and I let the rgb command slip by on accident. Help would be much appreciated.
edit: after messing with the circle snip I found this to be a solution. Its far from perfect but it is good enough.
Code: Select all
dim x,y,tilt as double
dim i as integer
randomize timer
screen 13
const Xres=320 'Setup the resolution for 13h
const Yres=200
x=Xres/2 'Set up the line so
y=Yres/2 ' it is in the center
tilt=rnd*6.2899 'random tilt (6.2899 is the max tilt it seems)
for i=0 to 100 'plot outward 100 steps
x=x+cos(tilt) 'The math for X
y=y+sin(tilt) 'The math for Y
pset(x,y),15 'dot
next
sleep -1
edit2: The algorithm I was looking for is known as Bresenham's line algorithm.
http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
Posted: Sun Mar 04, 2012 1:00 pm
by burger2227
It approaches the multiplier, but can never quite reach it.
RND can only return values from 0 to .9999999