jon93
New Member
Posts: 15
|
Post by jon93 on Oct 8, 2022 16:03:17 GMT
I am writing a trivial program with balls bouncing etc.
I write a few lines then run it to find errors. Now I get the box "these handles just closed by Just Basic. Please add appropriate close commands."
I do not understand very well the graphics aspect of just basic: I get by with only half understanding it. But this has me beaten. I cannot find any info online about what this is about.
Can anyone explain (at novice level) what this is about and what to do?
Jon
|
|
|
Post by plus on Oct 8, 2022 17:05:31 GMT
If you open a Window (text or graphic) you need to setup a trapclose event, see help for details.
|
|
|
Post by plus on Oct 8, 2022 17:14:09 GMT
Here is too much information example with trapclose handler called "quit" this one uses an actual subroutine, most beginners use line [labels], sorry.
' Title "Graphic Challenge LB 2022-07-30" 'b+2022-07-30 ' 2022-07-30 started from Shell of Another Color added ArcOfTheChord ' 2022-07-31 final touch ups and post 2 version color scheme
global Xmax, Ymax, Pi Xmax = 660 Ymax = 660 Pi = acs(-1)
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
toner$ = 100;" ";220;" ";50 ' Attempt to tone down big contrast between yellow and black
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!! Switch for 2 Coloring Versions !!!!!!!!!!!!!!!!!!!!!!!!!!! ToneDown = 0 ' switch for 2 versions of coloring
open "Grpahic Challenge Ying Yang Variation" for graphics_nsb_nf as #gr ' open window #gr "setfocus" #gr "trapclose quit" ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< trapclose event handler #gr "size 1" #gr "down" if ToneDown then #gr "fill ";toner$ ' loaded with allot of yellow to reduce contrast with background else #gr "fill black" end if
Dim x(2200), y(2200) ' oversized cx = 330: cy = 330: rLimit = 300: stepper = Pi/200 For a = 0 To Pi*11 Step stepper ' load x, y arrays scan x(i) = cx + ra * Cos(a): y(i) = cy + ra * Sin(a) If Sqr((x(i) - cx) ^ 2 + (y(i) - cy) ^ 2) > rLimit Then x(i) = cx + 300 * Cos(a): y(i) = cy + 300 * Sin(a) End If dr = dr + 1 / 1700: ra = ra + dr ^ 2: i = i + 1 Next top = i-1
#gr "color yellow" 'for shell color #gr "backcolor yellow" For i = 0 To top - 200 Step 4 scan #gr "size 1" call ArcOfTheChord x(i), y(i), x(i + 200), y(i + 200) ' 400 'select case 'case i < 400 ' #gr "size 4" 'case i < 600 ' #gr "size 5" 'case i < 700 ' #gr "size 6" 'case i < 800 ' #gr "size 8" 'case i < 900 ' #gr "size 10" 'case i < 975 ' #gr "size 11" 'case i < 1050 ' #gr "size 12" 'case i < 1100 ' #gr "size 13" 'case i < 1150 ' #gr "size 14" 'case i < 1600 ' #gr "size 15" 'end select '#gr "set ";x(i + 400);" ";y(i + 400) Next
'#gr "size 1" 'if ToneDown then ' center "hole" ' #gr "color ";toner$ ' for shell background closer to yellow ' #gr "backcolor ";toner$ 'else ' #gr "color black" ' for shell background to match magazine cover ' #gr "backcolor black" 'end if '#gr "place ";310;" ";310 '#gr "boxfilled ";350;" ";350
'#gr "color yellow" 'for shell color '#gr "backcolor yellow" '#gr "line ";330;" ";300;" ";330;" ";360 ' 2 center crosses crissed '#gr "line ";300;" ";330;" ";360;" ";330 '#gr "line ";300;" ";300;" ";360;" ";360 '#gr "line ";300;" ";360;" ";360;" ";300
'dx = 15: dx1 = 13 'While accum < 30 ' more lines blending to solid yellow ' accum = accum + dx ' accum1 = accum1 + dx1 ' #gr "line ";330 - accum1;" ";330 - accum1;" ";330 - accum1;" ";330 + accum1 ' #gr "line ";330 + accum1;" ";330 - accum1;" ";330 + accum1;" ";330 + accum1 ' #gr "line ";330 - accum1;" ";330 - accum1;" ";330 + accum1;" ";330 - accum1 ' #gr "line ";330 - accum1;" ";330 + accum1;" ";330 + accum1;" ";330 + accum1
' #gr "line ";330;" ";330-accum;" ";330+accum;" ";330 ' #gr "line ";330;" ";330+accum;" ";330+accum;" ";330 ' #gr "line ";330;" ";330+accum;" ";330-accum;" ";330 ' #gr "line ";330;" ";330-accum;" ";330-accum;" ";330
' dx = dx * .5 ' if dx < 1 then dx = 1 ' dx1 = dx1 * .5 ' if dx1 < 1 then dx1 = 1 'Wend 'for r = 20 to 30 ' #gr "place ";330;" ";330;"; circle ";r 'next #gr "Flush" wait
sub quit H$ ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< this gets called for closing event close #gr end end sub
sub pause mil 'tsh version has scan built-in t0 = time$("ms") while time$("ms") < t0 + mil : scan : wend end sub
' modified and simplified for flatter arcs attempting to match magazine cover Sub ArcOfTheChord Ax, Ay, Bx, By ' well one of them anyway ;-)) 2022-07-30 for LB Challenge pd2 = Pi/2 ' constant for 90 degrees dd2 = .5 * Sqr((Ax - Bx) ^ 2 + (Ay - By) ^ 2) ' dist between A and B want mid point mx = (Ax + Bx) / 2: my = (Ay + By) / 2 a = Atan2(By - Ay, Bx - Ax) ' angle of B to A r = 100 ' just make up a radius that gets close to flatness in magazine cover ox = mx + r * Cos(a + pd2): oy = my + r * Sin(a + pd2) r1 = Sqr((ox - Ax) ^ 2 + (oy - Ay) ^ 2) ' Now find distance of O to A !!! that radius oa = Atan2(Ay - oy, Ax - ox) ob = Atan2(By - oy, Bx - ox) call arc ox, oy, r1, oa, ob End Sub
'use radians Sub arc x, y, r, raBegin, raEnd ' updated 2021-09-09 ' raStart is first angle clockwise from due East = 0 degrees ' arc will start drawing there and clockwise until raStop angle reached 'x, y origin, r = radius, c = color p = Pi: p2 = p * 2
' Last time I tried to use this SUB it hung the program, possible causes: ' Make sure raStart and raStop are between 0 and 2pi. ' This sub does not have to be recursive, use GOSUB to do drawing to execute arc in one call.
'make copies before changing raStart = raBegin: raStop = raEnd While raStart < 0: raStart = raStart + p2: Wend While raStart >= p2: raStart = raStart - p2: Wend While raStop < 0: raStop = raStop + p2: Wend While raStop >= p2: raStop = raStop - p2: Wend
If raStop < raStart Then dStart = raStart: dStop = p2 - .00001 GoSub [drawArc] dStart = 0: dStop = raStop GoSub [drawArc] Else dStart = raStart: dStop = raStop GoSub [drawArc] End If Exit Sub [drawArc] al = p * r * r * (dStop - dStart) / p2 For a = dStart To dStop Step 10 / al ' orig 1/al #gr "set ";x + r * Cos(a);" ";y + r * Sin(a) Next Return 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
|
|
|
Post by xxgeek on Oct 8, 2022 18:39:28 GMT
Whether you open a window, a file a device etc you MUST close it before end ing the program. trapclose is used when a window is opened to goto a subroutine when the X button is pressed.
There may be other things to do before closing a window and you would add those things in the sub [quit] eg: You may have another "sub window" opened as well and need to close that too, so code for that would be added to the [quit] sub
open "My Program" for graphics_nsb_nf as #graphic ' open window #graphic "trapclose [quit]" ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< trapclose event handler wait 'your program code can go here
[quit] close #graphic end
|
|
|
Post by Rod on Oct 9, 2022 7:24:17 GMT
Most likely you have a runtime error that is crashing the program. Because you never reach the normal close command Just BASIC complains that you have not closed the window. Be sure you can see the whole of the IDE, there is a line at the foot that tells you what error has occurred. Also click on the ladybug and then the three arrows to animate your program and watch the error occur in slow motion.
For better help post your code.
|
|