Post by GWS on Apr 24, 2018 6:52:17 GMT -5
Hi folks,
Here's a program to create colorful patterns ..
All the best.
Graham
Here's a program to create colorful patterns ..
' GWS April 2018
nomainwin
x = int(0.75*DisplayWidth-70/2): y = int(0.85*DisplayHeight)
button #w.exit, "Exit", [quit], UL, x, y, 70, 35
x = int(0.25*DisplayWidth-70/2)
button #w.pause, "Next", [nextone], UL, x, y, 70, 35
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
UpperLeftX = 0: UpperLeftY = 0
stylebits #w, 0, _WS_MAXIMIZEBOX or _WS_MINIMIZEBOX, 0, 0
open " Patterns" for graphics_nsb as #w
#w, "trapclose [quit]"
#w, "down"
call Draw
#w, "flush"
wait
[nextone]
call Draw
wait
[quit]
close #w
end'
sub Draw
cls
#w, "fill 0 0 30"
x1 = 0
x2 = DisplayWidth
y1 = 0
y2 = DisplayHeight - 30
red = int(rnd(1) * 256)
grn = int(rnd(1) * 256)
blu = int(rnd(1) * 256)
' algorithm from a VB program by Bernt Figaro
' starting coordinates ..
a1 = rnd(1)*800
b1 = rnd(1)*600
a2 = rnd(1)*800
b2 = rnd(1)*600
'-------------
v1 = 1
v2 = 1
v3 = 1
v4 = 1
'-------------
c1 = a1
d1 = b1
c2 = a2
d2 = b2
'-------------
v1b = 1
v2b = 1
v3b = 1
v4b = 1
n = int(rnd(1)*500) + 100
for repeat = 1 to n
' mirror coordinates
a3 = x2 - a1
a4 = x2 - a2
b3 = y2 - b1
b4 = y2 - b2
'---------------
c3 = x2 - c1
c4 = x2 - c2
d3 = y2 - d1
d4 = y2 - d2
'---------------
' draw lines ..
#w, "color ";red;" ";grn;" ";blu
#w, "line ";a1;" ";b1;" ";a2;" ";b2
#w, "line ";a3;" ";b1;" ";a4;" ";b2
#w, "line ";a1;" ";b3;" ";a2;" ";b4
#w, "line ";a3;" ";b3;" ";a4;" ";b4
'------------------------
a1 = a1 - v1
a2 = a2 + v2
b1 = b1 + v3
b2 = b2 - v4
'------bounce effect------
if (a1 > x2) then v1 = rnd(1)*5
if (a1 < x1) then v1 = -1*rnd(1)*5
if (a2 > x2) then v2 = -1*rnd(1)*5
if (a2 < x1) then v2 = rnd(1)*5
if (b1 > y2) then v3 = -1*rnd(1)*5
if (b1 < y1) then v3 = rnd(1)*5
if (b2 > y2) then v4 = rnd(1)*5
if (b2 < y1) then v4 = -1*rnd(1)*5
if (repeat > rnd(1)*100) then
z = z + 1
if (z > rnd(1)*20 + 10) then
red = int(rnd(1) * 255)
grn = int(rnd(1) * 255)
blu = int(rnd(1) * 255)
#w, "color ";red;" ";grn;" ";blu
#w, "line ";c1;" ";d1;" ";c2;" ";d2
#w, "line ";c3;" ";d1;" ";c4;" ";d2
#w, "line ";c1;" ";d3;" ";c2;" ";d4
#w, "line ";c3;" ";d3;" ";c4;" ";d4
'-----------------
c1 = c1 - v1b
c2 = c2 + v2b
d1 = d1 + v3b
d2 = d2 - v4b
'-----------------
if (c1 > x2) then v1b = rnd(1)*5
if (c1 < x1) then v1b = -1*rnd(1)*5
if (c2 > x2) then v2b = -1*rnd(1)*5
if (c2 < x1) then v2b = rnd(1)*5
if (d1 > y2) then v3b = -1*rnd(1)*5
if (d1 < y1) then v3b = rnd(1)*5
if (d2 > y2) then v4b = rnd(1)*5
if (d2 < y1) then v4b = -1*rnd(1)*5
z = 0
end if
end if
next repeat
#w, "flush"
end sub
All the best.
Graham