Here's a small program which draws patterns in a window whenever the 'Next' button is pressed.
I quite like these pretty pattern programs - you never know what will appear next ..

At line 120, is a the statement:
SetGadgetText(#B_Exit, "Exit")
If you comment out this line, you'll see that the lines drawn each time 'Next' is pressed, overwrite the 'Exit' button - but strangely, not the 'Next' button.
With line 120 active, all seems to work correctly.
Code: Select all
; Patterns
; GWS 2013 - (a modification of MovingLines by Davetea 2004)
EnableExplicit
Define.w Event,run
Global.w wW,wH,d,draw
Global Dim Dir.w(1)
Global Dim x.w(3) ; x-coordinate
Global Dim y.w(3) ; y-coordinate
Global Dim dx.w(3) ; x-displacement
Global Dim dy.w(3) ; y-displacement
Enumeration
#w
#B_Exit
#B_Next
EndEnumeration
draw = #w
Declare DrawLines(draw)
#Center = 1
#Fixed = $A0000 ; #SysMenu|#Min
wW = 1024
wH = 768
run = #True
OpenWindow(#w, 0, 0, wW, wH, "Lines in Space",#Fixed|#Center)
SetWindowColor(#w, RGB(0,0,30))
ButtonGadget(#B_Exit, (wW-70)*0.8, wH*0.88, 70, 25, "Exit",#BS_FLAT)
ButtonGadget(#B_Next, (wW-70)*0.2, wH*0.88, 70, 25, "Next",#BS_FLAT)
d = 3 ; initial distance between line endpoints (pixels)
dir(0) = d
dir(1) = -d
DrawLines(draw)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
run = #False
Case #PB_Event_Gadget
Select EventGadget()
Case #B_Exit
run = #False
Case #B_Next
StartDrawing(WindowOutput(draw))
Box(0,0,wW,wH,RGB(0,0,30))
StopDrawing()
DrawLines(draw)
EndSelect
EndSelect
Until run = #False
Procedure DrawLines(draw)
; routine to draw a new set of lines ..
Define.w i,j,k,n,r,g,b
d = Random(10) + 2 ; distance between the line endpoints (pixels)
For i = 0 To 2 Step 2
x(i) = Random(wW)
x(i+1) = Random(wW)
y(i) = Random(wH)
y(i+1) = Random(wH)
j = Random(1): k = Random(d-1): dx(i) = dir(j) - k
j = Random(1): k = Random(d-1): dy(i) = dir(j) - k
j = Random(1): k = Random(d-1): dx(i+1) = dir(j) - k
j = Random(1): k = Random(d-1): dy(i+1) = dir(j) - k
Next i
For n = 1 To (Random(500) + 100)
If (n%10 = 0)
r = Random(255)
g = Random(255)
b = Random(255)
EndIf
For i = 0 To 2 Step 2
x(i) + dx(i) ; Coordinates changed by dx/dy
y(i) + dy(i)
x(i+1) + dx(i+1)
y(i+1) + dy(i+1)
If (x(i) <= 50) Or (x(i) >= wW-50) ; Change direction when nearing the screen edge
dx(i) = - dx(i)
EndIf
If (y(i) <= 50) Or (y(i) >= wH-50)
dy(i) = - dy(i)
EndIf
If (x(i+1) <= 50) Or (x(i+1) >= wW-50)
dx(i+1) = - dx(i+1)
EndIf
If (y(i+1) <= 50) Or (y(i+1) >= wH-50)
dy(i+1) = - dy(i+1)
EndIf
StartDrawing(WindowOutput(draw))
LineXY (x(i),y(i),x(i+1),y(i+1),RGB(r,g,b))
LineXY (wW-x(i),wH-y(i),wW-x(i+1),wH-y(i+1),RGB(r,g,b))
LineXY (x(i),wH-y(i),x(i+1),wH-y(i+1),RGB(r,g,b))
LineXY (wW-x(i),y(i),wW-x(i+1),y(i+1),RGB(r,g,b))
StopDrawing()
; Note: without the following statement, lines will be drawn over the Exit button ..
; Why this happens I've no idea ..
SetGadgetText(#B_Exit, "Exit")
Next i
Next n
EndProcedure
End
Best wishes,

Graham