Post by plus on Aug 8, 2022 2:51:45 GMT
"In quick basic there was pset (x,y)
Is there such a command in justbasic?"
#gr "set ";x;" ";y
You can use size to change to radius of the dot.
In fact here is a whole library of useful things specially if your background is QB:
I use the top part as a template to get a new graphics proggie started in JB.
Ah shoot! I changed that case for Xmax and Ymax and forgot to change the rest, case sensitivity is real killer in LB ;-))
OK I think it's all fixed, the sample works again.
Is there such a command in justbasic?"
#gr "set ";x;" ";y
You can use size to change to radius of the dot.
In fact here is a whole library of useful things specially if your background is QB:
'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 "Graphic Title" 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 255,0,255
call fore 255,0,0
b$ = ""
for i=1 to 10
b$ = b$ + str$( rand(5,10) );" "
next
call stext 10,30, b$
b$ = ""
call ctext 240, "testing 1,2,3... wait for continue..."
call pause 3000
call ftriangle 250,250,0,500,500,500
call fore 255, 255, 255
call box 100, 100, Xmax-100, Ymax-100 'this draws a white box frame inside screen
'============================== 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
I use the top part as a template to get a new graphics proggie started in JB.
Ah shoot! I changed that case for Xmax and Ymax and forgot to change the rest, case sensitivity is real killer in LB ;-))
OK I think it's all fixed, the sample works again.