Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASCII Character Geometry

Status
Not open for further replies.

jkljkl

Programmer
Jan 2, 2003
1
US
How can i print ascii characters on the screen to resemble circles and lines quickly and efficiently. The lines code would need to be able to draw lines of different angles, basically i give a starting coordinate and ending coordinate that would print characters between the lines, just like the line command prints pixels between the starting and ending points. And the circle code should work just like the circle command.
Heres an example of the circle i want to make:
XX
XXXX
XXXXXX
XXXXXX
XXXX
XX
And an example of a line:
X
.
.
.
.
X
 
for the line you should make a sub that finds the slope and y-intercept between the two character locations and then just sorta graph it

sub asciiline (x1,y1,x2,y2,asciichar$,charcolor%)
slope=(y2-y1)/(x2-x1)
color charcolor%
for x=x1 to x2
if x1<x2 then y=slope*x+x1
if x2<x1 then y=slope*x+x2
if x2=x1 then y=slope*x+x1
locate x,y
print asciichar$
next x
end sub

note that this works with text mode x and y coordinates, not with the screen resolution coordinates.

to draw a cirle it should look somethin like this

sub asciicircle (x1,y1,radius%,asciichar$,charcolor%)
color charcolor%
for deg=1 to 360
x=x*cos(deg)+y*sin(deg)
y=y*cos(deg)-x*sin(deg)
locate x,y
print asciichar$
next deg
end sub

i hope that works for you
 
when using the circle code posted above, you will have to use the INT Function

sub asciicircle (x1,y1,radius%,asciichar$,charcolor%)
color charcolor%
for deg=1 to 360
x=INT(x*cos(deg)+y*sin(deg))
y=INT(y*cos(deg)-x*sin(deg))
locate x,y
print asciichar$
next deg
end sub
 
for a filled circle try this...

Use:
CircleFill CenterX, CenterY, Radius

Source:
80x50 mode:
Code:
Sub CircleFill(X as integer, Y as integer ,R as integer)
  For A = -R to R
    For B = -R to R
      if (A^2 + B^2)^.5 <= R then
        If X + A >= 1 and X + A <= 80 then
          If Y + B >= 1 and Y + B <= 50 then
            Locate Y + B, X + A: Print &quot;X&quot;
          End If
        End If
      End If
    Next
  Next
End Sub

to make it look a little more round in 80x25 mode...
Divide Y by 2

80x25 mode:
Code:
Sub CircleFill(X as integer, Y as integer ,R as integer)
  For A = -R to R
    For B = (-R/2) to (R/2)
      if (A^2 + (B*2)^2)^.5 <= R then
        If X + A >= 1 and X + A <= 80 then
          If Y + B >= 1 and Y + B <= 25 then
            Locate Y + B, X + A: Print &quot;X&quot;
          End If
        End If
      End If
    Next
  Next
End Sub
Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top