Hi,
I'm writing a small program using QBasic which involves drawing small
right-angled triangles in Screen Mode 12.
I need to label the corners of these triangles with letters such as 'A,B,C'
but cant seem to find an command that allows me to 'plot' text characters to
a particular point on the graphics screen.
Any way of doing this?
Thanks
Jeremy ???
Plotting text to a graphics screen
Moderators:Administrator, Global Moderator
Re: Plotting text to a graphics screen
Hi!
In screen mode 12, or any other screen mode for that matter, to plot text to any posisition on the screen (such as X 123,Y 432), you must have the chars stored as an image and then write that image to the screen. :-/ The basic PRINT statment is stuck to the 'grid' on the screen.
' This is not tested, you it gives you the idea
' C2003 LabTop Admin (Chris Burchett)
' http:// clubweb.interbaun.com/labtop/
dim shared text&(5 *7 *2) 'create some array space
for y% = 0 to 6 ' y = 7
for x% = 0 to 4 ' x = 5
read charbit%
text&(x%*y*+y%) = charbit%
next x%
next y%
screen 12 ' Change Modes
plotchar(123,432)
SLEEP 'Sleep
end
'DATA for the letter E
data 1,1,1,1,0
data 1,0,0,0,0
data 1,0,0,0,0
data 1,1,1,0,0
data 1,0,0,0,0
data 1,0,0,0,0
data 1,1,1,1,0
sub plotchar(xx% , yy%)
for y% = 0 to 6 ' y = 7
for x% = 0 to 4 ' x = 5
charbit%=text&(x%*y*+y%)
pset(x%+xx%,y%+yy%),charbit%
next x%
next y%
end sub
In screen mode 12, or any other screen mode for that matter, to plot text to any posisition on the screen (such as X 123,Y 432), you must have the chars stored as an image and then write that image to the screen. :-/ The basic PRINT statment is stuck to the 'grid' on the screen.
' This is not tested, you it gives you the idea
' C2003 LabTop Admin (Chris Burchett)
' http:// clubweb.interbaun.com/labtop/
dim shared text&(5 *7 *2) 'create some array space
for y% = 0 to 6 ' y = 7
for x% = 0 to 4 ' x = 5
read charbit%
text&(x%*y*+y%) = charbit%
next x%
next y%
screen 12 ' Change Modes
plotchar(123,432)
SLEEP 'Sleep
end
'DATA for the letter E
data 1,1,1,1,0
data 1,0,0,0,0
data 1,0,0,0,0
data 1,1,1,0,0
data 1,0,0,0,0
data 1,0,0,0,0
data 1,1,1,1,0
sub plotchar(xx% , yy%)
for y% = 0 to 6 ' y = 7
for x% = 0 to 4 ' x = 5
charbit%=text&(x%*y*+y%)
pset(x%+xx%,y%+yy%),charbit%
next x%
next y%
end sub
- frankiebaby
- Global Moderator
- Posts:95
- Joined:Tue Apr 30, 2002 1:38 am
- Location:Pennsylvania
- Contact:
Re: Plotting text to a graphics screen
This Should do it:
DECLARE SUB FPRINT (X%, Y%, TEXT$, col%)
DECLARE FUNCTION numstr$ (numin%)
DIM SHARED SMFONT$(48 TO 90)
'This Stuff Loads All the characters
SMFONT$(48) = "D4 R4 U4 L4 R4 G4 E4 BR3" '0
SMFONT$(49) = "BD1 R1 D3 L1 R3 L1 U4 BR4" '1
SMFONT$(50) = "BD4 R3 L3 E3 H1 L1 G1 BU1 BR6" '2
SMFONT$(51) = "R4 D4 L4 BU2 R4 BU2 BR2" '3
SMFONT$(52) = "D2 R4 D2 U4 BR2" '4
SMFONT$(53) = "D2 R3 F1 G1 L3 BU4 R4 BR2" '5
SMFONT$(54) = "D4 R4 U2 L4 U2 R4 BR2" '6
SMFONT$(55) = "R4 D4 U4 BR2" '7
SMFONT$(56) = "BR1 R2 F1 G1 L2 G1 F1 R2 E1 H1 L2 H1 E1 BR5" '8
SMFONT$(57) = "R4 D4 L4 BU2 U2 D2 R4 U2 BR2" '9
SMFONT$(58) = "BR2 D1 BD2 D1 BU4 BR4" ':
SMFONT$(65) = "R4 D4 U2 L4 D2 U4 BR6" 'A
SMFONT$(66) = "D4 R4 U1 H1 L3 R3 E1 H1 L3 BR6" 'B
SMFONT$(67) = "D4 R4 BU4 L4 R4 BR2" 'C
SMFONT$(68) = "D4 R3 E1 U2 H1 L3 BR6" 'D
SMFONT$(69) = "D4 R4 BU2 L4 U2 R4 BR2" 'E
SMFONT$(70) = "R4 BD2 BL1 L3 D2 U4 BR6" 'F
SMFONT$(71) = "D4 R4 U2 L1 BL3 U2 R4 BR2" 'G
SMFONT$(72) = "D4 U2 R4 D2 U4 BR2" 'H
SMFONT$(73) = "R4 L2 D4 L2 R4 BU4 BR2" 'I
SMFONT$(74) = "R4 L2 D4 L1 H1 BU3 BR6" 'J
SMFONT$(75) = "D4 U2 R1 F2 BU4 G2 BU2 BR5" 'K
SMFONT$(76) = "D4 R4 BU4 BR2" 'L
SMFONT$(77) = "D4 U4 R1 F1 D1 U1 E1 R1 D4 U4 BR2" 'M
SMFONT$(78) = "D4 U4 F4 U4 BR2" 'N
SMFONT$(79) = "D4 R4 U4 L4 BR6" 'O
SMFONT$(80) = "D4 U2 R3 E1 H1 L3 BR6" 'P
SMFONT$(81) = "D4 R4 U4 L4 D4 R2 U1 BU3 BR5" 'Q
SMFONT$(82) = "D4 U2 R4 L2 D1 F1 BU2 R1 U2 L4 BR6" 'R
SMFONT$(83) = "D2 R4 D2 L4 BU4 R4 BR2" 'S
SMFONT$(84) = "R2 D4 U4 R2 BR2" 'T
SMFONT$(85) = "D4 R4 U4 BR2" 'U
SMFONT$(86) = "D2 F2 E2 U2 BR2" 'V
SMFONT$(87) = "D3 F1 E1 F1 E1 U3 BR2" 'W
SMFONT$(88) = "F4 BL4 E4 BR2" 'X
SMFONT$(89) = "F2 D2 U2 E2 BR2" 'Y
SMFONT$(90) = "R4 G4 R4 BU4 BR2" 'Z
SMFONT$(59) = "C0 R4 D4 L1 U4 L1 D4 L1 U4 L1 D4 U4" 'CLEARS NEXT BLOCK
SUB FPRINT (X%, Y%, TEXT$, col%)
'this sub actually does the printing
X1$ = numstr$(X%): Y1$ = numstr$(Y%)
color1$ = numstr$(col%)
DRAW "BM" + X1$ + "," + Y1$
DRAW "C" + color1$
FOR spot% = 1 TO LEN(TEXT$)
num = ASC(MID$(TEXT$, spot%, 1))
DRAW SMFONT$(59)
DRAW "C" + color1$
IF num <> 32 THEN DRAW SMFONT$(num) ELSE DRAW "BR6"
NEXT spot%
END SUB
FUNCTION numstr$ (numin%)
'this stupid function converts numbers to string..
' there is a better way built into Qb, but u need to
'modify it slightly....
holdnum = numin%
IF numin% < 10 THEN numstr$ = CHR$(numin% + 48): EXIT FUNCTION
IF numin% > 999 THEN numstr$ = "0": EXIT FUNCTION
IF numin% > 9 AND numin% < 100 THEN numstr$ = CHR$((numin% \ 10) + 48) + CHR$((numin% - (numin% \ 10) * 10) + 48): EXIT FUNCTION
IF numin% > 99 THEN
hold$ = CHR$((numin% \ 100) + 48)
numin% = numin% - ((numin% \ 100) * 100)
IF numin% > 0 THEN
numstr$ = hold$ + CHR$((numin% \ 10) + 48) + CHR$((numin% - (numin% \ 10) * 10) + 48)
ELSE numstr$ = hold$ + "00"
END IF
numin% = holdnum
END IF
END FUNCTION
DECLARE SUB FPRINT (X%, Y%, TEXT$, col%)
DECLARE FUNCTION numstr$ (numin%)
DIM SHARED SMFONT$(48 TO 90)
'This Stuff Loads All the characters
SMFONT$(48) = "D4 R4 U4 L4 R4 G4 E4 BR3" '0
SMFONT$(49) = "BD1 R1 D3 L1 R3 L1 U4 BR4" '1
SMFONT$(50) = "BD4 R3 L3 E3 H1 L1 G1 BU1 BR6" '2
SMFONT$(51) = "R4 D4 L4 BU2 R4 BU2 BR2" '3
SMFONT$(52) = "D2 R4 D2 U4 BR2" '4
SMFONT$(53) = "D2 R3 F1 G1 L3 BU4 R4 BR2" '5
SMFONT$(54) = "D4 R4 U2 L4 U2 R4 BR2" '6
SMFONT$(55) = "R4 D4 U4 BR2" '7
SMFONT$(56) = "BR1 R2 F1 G1 L2 G1 F1 R2 E1 H1 L2 H1 E1 BR5" '8
SMFONT$(57) = "R4 D4 L4 BU2 U2 D2 R4 U2 BR2" '9
SMFONT$(58) = "BR2 D1 BD2 D1 BU4 BR4" ':
SMFONT$(65) = "R4 D4 U2 L4 D2 U4 BR6" 'A
SMFONT$(66) = "D4 R4 U1 H1 L3 R3 E1 H1 L3 BR6" 'B
SMFONT$(67) = "D4 R4 BU4 L4 R4 BR2" 'C
SMFONT$(68) = "D4 R3 E1 U2 H1 L3 BR6" 'D
SMFONT$(69) = "D4 R4 BU2 L4 U2 R4 BR2" 'E
SMFONT$(70) = "R4 BD2 BL1 L3 D2 U4 BR6" 'F
SMFONT$(71) = "D4 R4 U2 L1 BL3 U2 R4 BR2" 'G
SMFONT$(72) = "D4 U2 R4 D2 U4 BR2" 'H
SMFONT$(73) = "R4 L2 D4 L2 R4 BU4 BR2" 'I
SMFONT$(74) = "R4 L2 D4 L1 H1 BU3 BR6" 'J
SMFONT$(75) = "D4 U2 R1 F2 BU4 G2 BU2 BR5" 'K
SMFONT$(76) = "D4 R4 BU4 BR2" 'L
SMFONT$(77) = "D4 U4 R1 F1 D1 U1 E1 R1 D4 U4 BR2" 'M
SMFONT$(78) = "D4 U4 F4 U4 BR2" 'N
SMFONT$(79) = "D4 R4 U4 L4 BR6" 'O
SMFONT$(80) = "D4 U2 R3 E1 H1 L3 BR6" 'P
SMFONT$(81) = "D4 R4 U4 L4 D4 R2 U1 BU3 BR5" 'Q
SMFONT$(82) = "D4 U2 R4 L2 D1 F1 BU2 R1 U2 L4 BR6" 'R
SMFONT$(83) = "D2 R4 D2 L4 BU4 R4 BR2" 'S
SMFONT$(84) = "R2 D4 U4 R2 BR2" 'T
SMFONT$(85) = "D4 R4 U4 BR2" 'U
SMFONT$(86) = "D2 F2 E2 U2 BR2" 'V
SMFONT$(87) = "D3 F1 E1 F1 E1 U3 BR2" 'W
SMFONT$(88) = "F4 BL4 E4 BR2" 'X
SMFONT$(89) = "F2 D2 U2 E2 BR2" 'Y
SMFONT$(90) = "R4 G4 R4 BU4 BR2" 'Z
SMFONT$(59) = "C0 R4 D4 L1 U4 L1 D4 L1 U4 L1 D4 U4" 'CLEARS NEXT BLOCK
SUB FPRINT (X%, Y%, TEXT$, col%)
'this sub actually does the printing
X1$ = numstr$(X%): Y1$ = numstr$(Y%)
color1$ = numstr$(col%)
DRAW "BM" + X1$ + "," + Y1$
DRAW "C" + color1$
FOR spot% = 1 TO LEN(TEXT$)
num = ASC(MID$(TEXT$, spot%, 1))
DRAW SMFONT$(59)
DRAW "C" + color1$
IF num <> 32 THEN DRAW SMFONT$(num) ELSE DRAW "BR6"
NEXT spot%
END SUB
FUNCTION numstr$ (numin%)
'this stupid function converts numbers to string..
' there is a better way built into Qb, but u need to
'modify it slightly....
holdnum = numin%
IF numin% < 10 THEN numstr$ = CHR$(numin% + 48): EXIT FUNCTION
IF numin% > 999 THEN numstr$ = "0": EXIT FUNCTION
IF numin% > 9 AND numin% < 100 THEN numstr$ = CHR$((numin% \ 10) + 48) + CHR$((numin% - (numin% \ 10) * 10) + 48): EXIT FUNCTION
IF numin% > 99 THEN
hold$ = CHR$((numin% \ 100) + 48)
numin% = numin% - ((numin% \ 100) * 100)
IF numin% > 0 THEN
numstr$ = hold$ + CHR$((numin% \ 10) + 48) + CHR$((numin% - (numin% \ 10) * 10) + 48)
ELSE numstr$ = hold$ + "00"
END IF
numin% = holdnum
END IF
END FUNCTION
-
- Newbie
- Posts:2
- Joined:Mon Dec 30, 2002 11:44 pm
Re: Plotting text to a graphics screen
hi folks,
thanks for the replies - i eventually sorted it out using GET and PUT. I wrote all of the alphanumeric characters into a large array using GET and then wrote a subroutine which would allow me to 'plot' any of these characters to any position on the screen using the PUT command.
quite a bit of fiddling to get it to work - qbasic can be quite fussy - but got there in the end.
jeremy
thanks for the replies - i eventually sorted it out using GET and PUT. I wrote all of the alphanumeric characters into a large array using GET and then wrote a subroutine which would allow me to 'plot' any of these characters to any position on the screen using the PUT command.
quite a bit of fiddling to get it to work - qbasic can be quite fussy - but got there in the end.
jeremy