Just BASIC Programming
Just BASIC Programming >> Novice >> Graphics window print left justified
http://justbasic.conforums.com/index.cgi?board=novice&action=display&num=1514136494

Graphics window print left justified
Post by Rob Somerville on Dec 24th, 2017, 11:28am

I am trying to write a small dice throwing program to use while playing a backgammon app.
My latest attempt is shown below and is ok. It simply rolls two dice, tells me the result and loops until I press Q to Quit.

If I do not have the line, 'print #1, "home"' then the pair of numbers moves down the window and disappears. I would really like it to print the result, say 5 and 2 vertically, not horizontally as it does at present. This is, no doubt, very easy, but I just can't figure it out. Any ideas anybody?
Code:
    nomainwin
    WindowWidth = 120
    WindowHeight = 120
    UpperLeftX = 1300
    UpperLeftY = 150
    open "Dice" for graphics as #1
    print #1, "when characterInput [keyPressed]"
    print #1, "trapclose [quit]"
    print #1, "font arial 30"
    print #1, "\This is Arial 30 point"

[loopHere]
    print #1, "setfocus"
    scan
    for n = 1 to 2
        c = int(rnd(1)*6) + 1
        if n = 1 then a = c else b = c
        if c=1 then playwave "voice\one.wav"
        if c=2 then playwave "voice\two.wav"
        if c=3 then playwave "voice\three.wav"
        if c=4 then playwave "voice\four.wav"
        if c=5 then playwave "voice\five.wav"
        if c=6 then playwave "voice\six.wav"
        if n=1 then playwave "voice\and.wav"
      next
      print #1, "home"
      print #1, "\";a;" ";b
      wait

[keyPressed]
    print#1, "cls"
    key$ = Inkey$
    if key$ = "q" or key$ = "Q" then goto [quit]
    goto [loopHere]


[quit]
    close #1
    end

 

Re: Graphics window print left justified
Post by tsh73 on Dec 24th, 2017, 3:05pm

err
Code:
      print #1, "home"
      'print #1, "\";a;" ";b
      print #1, "\";a
      print #1, "\";b 

?
Re: Graphics window print left justified
Post by Rob Somerville on Dec 25th, 2017, 2:27pm

Thank you. I can't believe that I didn't try this as my very first attempt and then several more times since this is the obvious answer. I have no explanation, but thanks embarassed

print #1, "home" This command centers the pen in the graphics window. Is there any way of placing the pen at the left of graphics window?

Re: Graphics window print left justified
Post by tsh73 on Dec 26th, 2017, 02:42am

top left
Code:
      print #1, "place 0 0" 'top left
      print #1, "\"         'skip one line or it'll be up (out of) screen
      print #1, "\";a
      print #1, "\";b
 

center left
Code:
      print #1, "home"
      print #1, "posxy cx cy"   'read center position in cx, cy
      print #1, "place 0 ";cy 'center left
      print #1, "\";a
      print #1, "\";b
 

Re: Graphics window print left justified
Post by Rob Somerville on Dec 26th, 2017, 04:10am

Thank you smiley
Re: Graphics window print left justified
Post by Rob Somerville on Jan 11th, 2018, 2:33pm

nomainwin
WindowWidth = 60
WindowHeight = 160
UpperLeftX = 1500
UpperLeftY = 150
open "Dice" for graphics as #1
print #1, "when characterInput [keyPressed]"
print #1, "trapclose [quit]"
print #1, "font arial 30"
print #1, "\This is Arial 30 point"

[loopHere]
print #1, "setfocus"
scan
for n = 1 to 2
c = int(rnd(1)*6) + 1
if n = 1 then a = c else b = c
next
print #1, "place 15 0"
print #1, "\"
print #1, "\";a
print #1, "\";b
timer 10 'Without this a and b do not show for a few seconds
if a=1 then playwave "voice\one.wav"
if a=2 then playwave "voice\two.wav"
if a=3 then playwave "voice\three.wav"
if a=4 then playwave "voice\four.wav"
if a=5 then playwave "voice\five.wav"
if a=6 then playwave "voice\six.wav"
playwave "voice\and.wav"
if b=1 then playwave "voice\one.wav"
if b=2 then playwave "voice\two.wav"
if b=3 then playwave "voice\three.wav"
if b=4 then playwave "voice\four.wav"
if b=5 then playwave "voice\five.wav"
if b=6 then playwave "voice\six.wav"
wait

[keyPressed]
print#1, "cls"
key$ = Inkey$
if key$ = "q" or key$ = "Q" then goto [quit]
goto [loopHere]

[quit]
close #1
end

This works well. Thank you smiley