How do you make a line without the line command?

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Bp103
Newbie
Posts: 2
Joined: Thu Aug 05, 2010 5:05 pm
Location: low orbit

How do you make a line without the line command?

Post 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.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post 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.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Bp103
Newbie
Posts: 2
Joined: Thu Aug 05, 2010 5:05 pm
Location: low orbit

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

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
Last edited by Bp103 on Sat Nov 24, 2012 5:29 pm, edited 4 times in total.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

It approaches the multiplier, but can never quite reach it.

RND can only return values from 0 to .9999999
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Post Reply