drb
New Member
Posts: 4
|
Post by drb on Sept 10, 2023 18:22:53 GMT
I am trying to create a Cricket Game type of program and am having a problem with a Text Window in placing variables and names in a particular position.
I have tried used "Locate" but it just puts it at the start of the next line.
Any advice and tips would be appreciated.
Program Code I have so far is below
open "SBoard" for text_fs as #sbd print #sbd, "!trapclose [quit]"
print #sbd, "!backcolor Black" print #sbd, "!forecolor Yellow"
print #sbd, "!font Arial"
print #sbd, "BATNAME1"
print #sbd, "!locate 40 40"; print #sbd, "Total"
print #sbd, "!locate 20 20" print #sbd, "wkts"
wait [quit] close #sbd end
|
|
|
Post by tsh73 on Sept 10, 2023 19:26:33 GMT
put a picture what you are trying to get (draw it with something, may be MS paint, upload it to say postimages.org, put a link here)
If you want to LOCATE to output text, that comes to mainwin, single default font, no size, no color If you switch to graphicbox, you can PLACE next graphic command, select COLOR/ BACKCOLOR, change font / size / bold / italic
If text layout is predefined (? I have no idea), you can just put lines into statictext/textbox and position them on a window.
|
|
drb
New Member
Posts: 4
|
Post by drb on Sept 10, 2023 19:56:09 GMT
I have pasted a copy of code which created it within the main window but without the ability to change font and colour which is why I was trying to create using text/graphics windows.
mainwin 80 30
CLS
tot = 0: wkt = 0: bat1 = 0: bat2 = 0: ext = 0: ovs = 0 lmn$ = "*********": hmtm$ = "HOME TEAM": awtm$ = "AWAY TEAM" DIM bwlr(11), ovrs(11), mdns(11), runs(11), wkts(11) DIM fow(10)
LOCATE 1, 1: PRINT "BATNAME1" LOCATE 25, 1: PRINT "Total "; tot LOCATE 35, 1: PRINT " for "; wkt LOCATE 1, 3: PRINT "BATTING1" LOCATE 15, 3: PRINT bat1 LOCATE 1, 5: PRINT "BATTING2" LOCATE 15, 5: PRINT bat2 LOCATE 32, 4: PRINT "extras "; ext LOCATE 32, 5: PRINT "overs "; ovs LOCATE 1, 7: PRINT "Ovs Rem" LOCATE 15, 7: PRINT ovr LOCATE 25, 7: PRINT "last man "; lmn$ LOCATE 45, 7: PRINT lmn LOCATE 1, 8: PRINT "Runs Req" LOCATE 15, 8: PRINT rnr LOCATE 1, 12: PRINT "bowler" LOCATE 1, 13: PRINT "overs" LOCATE 1, 14: PRINT "wickets" LOCATE 1, 15: PRINT "runs"
FOR xx = 1 TO 8
LOCATE ((xx * 5) + 5),12 PRINT bwlr(xx)
LOCATE ((xx * 5) + 5),13 PRINT ovrs(xx)
LOCATE ((xx * 5) + 5),14 PRINT wckt(xx)
LOCATE ((xx * 5) + 5),15 PRINT runs(xx)
NEXT xx
FOR xx = 1 TO 5
LOCATE (((xx - 1) * 12) + 5),18 ' COLOR 14 PRINT xx LOCATE (((xx - 1) * 12) + 9),18 ' COLOR 15 PRINT fow(xx)
NEXT xx
FOR xx = 6 TO 10
LOCATE (((xx - 6) * 12) + 3),19 ' COLOR 14 PRINT xx LOCATE (((xx - 6) * 12) + 7),19 ' COLOR 15 PRINT fow(xx)
NEXT xx
LOCATE 15,21: PRINT "1st Inns 2nd Inns" LOCATE 40,21: PRINT "HOW OUT PTS"
LOCATE 1,22: PRINT hmtm$ LOCATE 15,22: PRINT htl(1) LOCATE 26,22: PRINT htl(2)
LOCATE 1,23: PRINT awtm$ LOCATE 15,23: PRINT atl(1) LOCATE 26,23: PRINT atl(2)
LOCATE 50,22: PRINT bp(1) LOCATE 50,23: PRINT bp(2)
LOCATE 39,22: PRINT "C 10 B 11"
|
|
|
Post by plus on Sept 10, 2023 20:36:54 GMT
I should charge real money for this is work! 'JB Library.txt for Just Basic v1.01 [B+=MGA] 2016-11-11 'added Atan2 '2016-10-28 add extra pixel to end of aline, box, fbox for bug fix
' notes: template code for graphics window
global Xmax, Ymax, Pi, Deg, Rad Xmax = 660 Ymax = 660 Pi = acs(-1) Deg = 180 / Pi Rad = Pi / 180
nomainwin
WindowWidth = Xmax + 8 WindowHeight = Ymax + 32 UpperLeftX = (DisplayWidth - Xmax) / 2 'or delete if Xmax is 1200 or above UpperLeftY = (DisplayHeight - Ymax) / 2 'or delete if Ymax is 700 or above
open "Help drb with graphics" for graphics_nsb_nf as #gr '<======================= title #gr "setfocus" #gr "trapclose quit" #gr "when leftButtonUp lButtonUp" #gr "when characterInput charIn" #gr "down" #gr "fill black"
'============================== main code note: to text need min 10 in y value, text width(6-16) height 16 call back 0,0,0 call fore 255,255,0 tot = 0: wkt = 0: bat1 = 0: bat2 = 0: ext = 0: ovs = 0 lmn$ = "*********": hmtm$ = "HOME TEAM": awtm$ = "AWAY TEAM" DIM bwlr(11), ovrs(11), mdns(11), runs(11), wkts(11) DIM fow(10)
' LP stands for Locate and Print call LP 1, 1, "BATNAME1" call LP 25, 1, "Total "; tot 'LOCATE 1, 1: PRINT "BATNAME1" 'LOCATE 25, 1: PRINT "Total "; tot
call LP 35, 1, " for "; wkt call LP 1, 3, "BATTING1" call LP 15, 3, str$(bat1) call LP 1, 5, "BATTING2" call LP 15, 5, str$(bat2) call LP 32, 4, "extras "; ext call LP 32, 5, "overs "; ovs call LP 1, 7, "Ovs Rem" call LP 15, 7, str$(ovr) call LP 25, 7, "last man "; lmn$ call LP 45, 7, str$(lmn) call LP 1, 8, "Runs Req" call LP 15, 8, str$(rnr) call LP 1, 12, "bowler" call LP 1, 13, "overs" call LP 1, 14, "wickets" call LP 1, 15, "runs"
FOR xx = 1 TO 8
call LP ((xx * 5) + 5),12, str$(bwlr(xx)) 'PRINT
call LP ((xx * 5) + 5),13, str$(ovrs(xx)) PRINT
call LP ((xx * 5) + 5),14, str$(wckt(xx))
call LP ((xx * 5) + 5),15, str$(runs(xx))
NEXT xx
FOR xx = 1 TO 5
call LP (((xx - 1) * 12) + 5),18, str$(xx) ' COLOR 14 'PRINT xx call LP (((xx - 1) * 12) + 9),18, str$(fow(xx0)) ' COLOR 15 'PRINT fow(xx)
NEXT xx
FOR xx = 6 TO 10
call LP (((xx - 6) * 12) + 3),19, str$(xx) ' COLOR 14 'PRINT xx call LP (((xx - 6) * 12) + 7),19, str$(fow(xx)) ' COLOR 15 'PRINT fow(xx)
NEXT xx
call LP 15,21, "1st Inns 2nd Inns" call LP 40,21, "HOW OUT PTS"
call LP 1,22, hmtm$ call LP 15,22, str$(htl(1)) call LP 26,22, str$(htl(2))
call LP 1,23, awtm$ call LP 15,23, str$(atl(1)) call LP 26,23, str$(atl(2))
call LP 50,22, str$(bp(1)) call LP 50,23, str$(bp(2))
call LP 39,22, "C 10 B 11"
'============================== sets drawing #gr "flush" wait
'JB Library of procedures ====================================================== 'notes: arrays are global limited in dimensions, no constants, no imports, no declares... 'must "call" subs no ()! not even in definitions and must use () for parameterless functions
sub midpoint x1, y1, x2, y2, fraction, byref midx, byref midy midx = (x2 - x1) * fraction + x1 midy = (y2 - y1) * fraction + y1 end sub
function distance(x1, y1, x2, y2) distance = ( (x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5 end function
function rand(lo, hi) rand = int((hi - lo + 1) * rnd(0)) + lo end function
sub hue r, g, b 'fore and back #gr "color ";r;" ";g;" ";b #gr "backcolor ";r;" ";g;" ";b end sub
sub fore r, g, b #gr "color ";r;" ";g;" ";b end sub
sub back r, g, b 'backcolor is used for fills #gr "backcolor ";r;" ";g;" ";b end sub
sub QBcolr colrNum select case colrNum case 0 : #gr "color black" case 1 : #gr "color darkblue" case 2 : #gr "color brown" case 3 : #gr "color darkcyan" case 4 : #gr "color darkred" case 5 : #gr "color darkpink" case 6 : #gr "color darkgreen" case 7 : #gr "color lightgray" case 8 : #gr "color darkgray" case 9 : #gr "color blue" case 10 : #gr "color green" case 11 : #gr "color cyan" case 12 : #gr "color red" case 13 : #gr "color pink" case 14 : #gr "color yellow" case 15 : #gr "color white" end select end sub
sub pset x, y #gr "set ";x;" ";y end sub
sub aline x0, y0, x1, y1 #gr "line ";x0;" ";y0;" ";x1+1;" ";y1+1 'add 1 to end point end sub
sub box x0, y0, x1, y1 #gr "place ";x0;" ";y0 #gr "box ";x1+1;" ";y1+1 'add pixel at end end sub
sub fbox x0, y0, x1, y1 #gr "place ";x0;" ";y0 #gr "boxfilled ";x1+1;" ";y1+1 end sub
sub circ x, y, radius #gr "place ";x;" ";y;"; circle ";radius end sub
sub fcirc x, y, radius #gr "place ";x;" ";y;"; circlefilled ";radius end sub
sub ellips x, y, w, h '< no e on end! #gr "place ";x;" ";y;"; ellipse ";w;" ";h end sub
sub fellipse x, y, w, h #gr "place ";x;" ";y;"; ellipsefilled ";w;" ";h end sub
'ink the color that is percent between the first color and 2nd color
sub midInk r1, g1, b1, r2, g2, b2, frac dr = (r2 - r1) * frac : dg = (g2 - g1) * frac : db = (b2 - b1) * frac #H$ "color ";r1 + dr;" ";g1 + dg;" ";b1 + db #H$ "backcolor ";r1 + dr;" ";g1 + dg;" ";b1 + db end sub
'Fast Filled Triangle Sub by AndyAmaya Sub ftriangle x1, y1, x2, y2, x3, y3 'triangle coordinates must be ordered: where x1 < x2 < x3 If x2 < x1 Then x = x2 : y = y2 : x2 = x1 : y2 = y1 : x1 = x : y1 = y 'swap x1, y1, with x3, y3 If x3 < x1 Then x = x3 : y = y3 : x3 = x1 : y3 = y1 : x1 = x : y1 = y 'swap x2, y2 with x3, y3 If x3 < x2 Then x = x3 : y = y3 : x3 = x2 : y3 = y2 : x2 = x : y2 = y If x1 <> x3 Then slope1 = (y3 - y1) /(x3 - x1) 'draw the first half of the triangle length = x2 - x1 If length <> 0 Then slope2 = (y2 - y1)/(x2 - x1) For x = 0 To length #gr "Line ";int(x + x1);" ";int(x * slope1 + y1);" ";int(x + x1);" ";int(x * slope2 + y1) Next End If 'draw the second half of the triangle y = length * slope1 + y1 : length = x3 - x2 If length <> 0 Then slope3 = (y3 - y2) /(x3 - x2) For x = 0 To length #gr "Line ";int(x + x2);" ";int(x * slope1 + y);" ";int(x + x2);" ";int(x * slope3 + y2) Next End If call aline x1, y1, x2, y2 call aline x2, y2, x1, y1 call aline x2, y2, x3, y3 call aline x3, y3, x2, y2 call aline x1, y1, x3, y3 call aline x3, y3, x1, y1 End Sub
sub star x, y, rInner, rOuter, nPoints, angleOffset, TFfill ' x, y are same as for circle, ' rInner is center circle radius ' rOuter is the outer most point of star ' nPoints is the number of points, ' angleOffset = angle offset IN DEGREES, it will be converted to radians in sub ' this is to allow us to spin the polygon of n sides ' TFfill filled True or False (1 or 0)
pAngle = RAD * (360 / nPoints) : radAngleOffset = RAD * angleOffset x1 = x + rInner * cos(radAngleOffset) y1 = y + rInner * sin(radAngleOffset) for i = 0 to nPoints - 1 x2 = x + rOuter * cos(i * pAngle + radAngleOffset + .5 * pAngle) y2 = y + rOuter * sin(i * pAngle + radAngleOffset + .5 * pAngle) x3 = x + rInner * cos((i + 1) * pAngle + radAngleOffset) y3 = y + rInner * sin((i + 1) * pAngle + radAngleOffset) if TFfill then call ftriangle x1, y1, x2, y2, x3, y3 else call aline x1, y1, x2, y2 call aline x2, y2, x3, y3 end if x1 = x3 : y1 = y3 next if TFfill then call fcirc x, y, rInner end sub
sub stext x, y, message$ 'note: have to reset fore or back color after ink #gr "place ";x;" ";y;";|";message$ end sub
sub ctext y, message$ 'uses const Xmax and sub stext call stext (Xmax - len(message$) * 7) /2, y, message$ end sub
sub lButtonUp H$, mx, my 'must have handle and mouse x,y call quit H$ '<=== H$ global window handle end sub
sub charIn H$, c$ if asc(c$) = 32 then goON = 1 - goON else call quit H$ end if end sub
'Need line: #gr "trapclose quit" sub quit H$ close #gr '<=== this needs Global H$ = "gr" end 'Thanks Facundo, close graphic wo error end sub
sub pause mil 'tsh version has scan built-in t0 = time$("ms") while time$("ms") < t0 + mil : scan : wend end sub
Function Atan2(y, x) 'Atan2 is a function which determines the angle between points 'x1, y1 and x2, y2. The angle returned is in radians 'The angle returned is always in the range of '-PI to PI radians (-180 to 180 degrees) '============================================================== 'NOTE the position of Y and X arguments 'This keeps Atan2 function same as other language versions '============================================================== If x = 0 Then If y < 0 Then Atan2 = -1.5707963267948967 Else Atan2 = 1.5707963267948967 End If Else chk = atn(y/x) If x < 0 Then If y < 0 Then chk = chk - 3.1415926535897932 Else chk = chk + 3.1415926535897932 End If End If Atan2 = chk End If 'thanks Andy Amaya End Function
'draws an arc with center at xCenter, yCenter, radius from center is arcRadius sub arc xCenter, yCenter, arcRadius, dAStart, dAMeasure 'notes: 'you may want to adjust size and color for line drawing 'using angle measures in degrees to match Just Basic ways with pie and piefilled 'this sub assumes drawing in a CW direction if dAMeasure positive
'for Just Basic angle 0 degrees is due East and angle increases clockwise towards South
'dAStart is degrees to start Angle, due East is 0 degrees
'dAMeasure is degrees added (Clockwise) to dAstart for end of arc
rAngleStart = RAD * dAStart rAngleEnd = RAD * dAMeasure + rAngleStart Stepper = RAD / (.1 * arcRadius) 'fixed lastX = xCenter + arcRadius * cos(rAngleStart) lastY = yCenter + arcRadius * sin(rAngleStart) #gr "set ";int(lastX);" ";int(lastY) for rAngle = rAngleStart+Stepper to rAngleEnd step Stepper nextX = xCenter + arcRadius * cos(rAngle) nextY = yCenter + arcRadius * sin(rAngle) #gr "goto ";int(nextX);" ";int(nextY) 'int speeds things up next end sub
' To find the angle point(x2, y2) makes to (x1, y1) in Degrees Function P2AngleToP1 (x1, y1, x2, y2) ' The angle in degrees a 2nd point (x2, y2) makes to a first point (x1, y1)
' Delta means change between 1 measure and another for example x2 - x1 deltaX = x2 - x1 deltaY = y2 - y1
' Take DegreeAngle = DAtan2(y2 - y1, x2 - x1) rtn = Deg * (Atan2(deltaY, deltaX)) If rtn < 0 Then P2AngleToP1 = rtn + 360 Else P2AngleToP1 = rtn End Function
' use angles in degrees units instead of radians (converted inside sub) Sub ArrowTo BaseX, BaseY, dAngle, lngth, colr$ rAngle = Rad * dAngle x1 = BaseX + lngth * Cos(rAngle) -1 ' why are these arrows crooked!?!? try -.5 y1 = BaseY + lngth * Sin(rAngle) -1 x2 = BaseX + .8 * lngth * Cos(rAngle - Pi * .05) y2 = BaseY + .8 * lngth * Sin(rAngle - Pi * .05) x3 = BaseX + .8 * lngth * Cos(rAngle + Pi * .05) y3 = BaseY + .8 * lngth * Sin(rAngle + Pi * .05) #gr "color ";colr$ call aline BaseX, BaseY, x1, y1 call aline x1, y1, x2, y2 call aline x1, y1, x3, y3 End Sub
Sub LP x, y, message$ call stext x * 8, y * 16, message$ end sub
b = b + ...
|
|