Post by David Drake on Nov 12, 2021 11:05:25 GMT -5
I love doing stuff in the MAINWIN. Here is a little holiday demo using the MAINWIN to display a tree with "flashing" lights. Unnecessarily heavily commented, just because. Would love to see someone suggest ways to tidy up the code. Enjoy!
David
David
'Text tree
[setupVariables] 'Declare and define variables
dim light(1000,3) 'array that hold locations and states of lights
'lightCount(n,1) - x (column) position of a light
'lightCount(n,2) - y (row) position of a light
'lightCount(n,3) - light state: 2=off, 1=in-between, 0=on
a=0 'loop counter
x=0 'column number
y=0 'row number
lightCount=0 'total number of lights on tree
spcs=0 'number of spaces to the left of the tree on row y
z$="" 'string holding characters for each row of the initial tree creation
[maximizeMAINWIN] 'Maximize the MAINWIN, courtesy of the Liberty BASIC Newsletter #53 - October 1999 (Clif and Alyce)
open "user32" for dll as #user
calldll #user, "GetActiveWindow",_
mainwinhandle as short 'returns handle of mainwin
calldll #user, "MoveWindow", _
mainwinhandle as word, _ 'window handle
0 as short, _ 'upperleft x
0 as short, _ 'upperleft y
DisplayWidth as short, _ 'width
DisplayHeight as short, _ 'height
1 as word, _ 'repaint
result as void 'no return
close #user
[drawTree]
'Draw triangular tree shape
print
for y = 1 to 30
z$=""
print space$(70/2-y);
for x = 1 to y
z$=z$+"--"
next x
print z$
next y
'Draw trunk
for y = 1 to 4
z$=""
print space$(70/2-4);
for x = 1 to 4
z$=z$+"/\"
next x
print z$
next y
[makeLights] 'create random light locations on the tree
for y = 1 to 30'loop vertically down tree
spcs=int(70/2-y)'number of spaces to the left of the tree on that row
for x = 1 to y'loop through left half of a row
if rnd(1)<0.35 then'probability that a light will appear - increase value to get more lights
lightCount=lightCount+1'increment count of lights
light(lightCount,1)=spcs+x'record x position of this light in the array
light(lightCount,2)=y+1'record y position of this light in the array
light(lightCount,3) = int(rnd(1)*3)'record light off/on/in-between state in array
end if
next x
for x = 1 to y'loop through right half of a row
if rnd(1)<0.35 then'probability that a light will appear - increase value to get more lights
lightCount=lightCount+1'increment count of lights
light(lightCount,1)=y+spcs+x'record x position of this light in the array
light(lightCount,2)=y+1'record y position of this light in the array
light(lightCount,3) = int(rnd(1)*3)'record light off/on/in-between state in array
end if
next x
next y
[looping]'Flash lights loop
timer 1000, [flash] 'every 1000ms
wait
[flash]'Flash lights
for a = 1 to lightCount
locate light(a,1),light(a,2) 'position cursor at the light's x,y
select case light(a,3) 'for each light state in the array, do something
case 2 'don't flash
print "-";
light(a,3)=1
case 1 'don't flash
print ".";
light(a,3)=0
case 0 ' flash!
print "*";
light(a,3)=2
end select
next a
wait