April 24, 2024, 03:02:50 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Pretty Patterns

Started by GWS, February 26, 2013, 08:58:52 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

February 26, 2013, 08:58:52 AM Last Edit: March 01, 2013, 09:17:19 AM by GWS
Hi,

Here's an interesting little program which generates random patterns from almost no information ..  ::)

I love these simple little colour generators - you never know what you're going to see next ..  :)


' Creative Random Lines
' GWS - 2013 (from an idea by Davetea 2004)

def w:window
def wstyle,i,j,k,n,sW,sH:int
def r,g,b,bch:int

def dir[2]:int
def x[4],y[4],dx[4],dy[4]:int

declare Rn(low:int,high:int)

GetScreenSize sW,sH

' open a window ..
wstyle = @minbox
window w,-sW,0,sW,sH,wstyle,0,"Lines in Space",messages
setwindowcolor w,rgb(0,0,0)
centerwindow w

control w,"B,Exit,(sW-70)*0.8,sH*0.9,70,30,0,1"
control w,"B,Next,(sW-70)*0.2,sH*0.9,70,30,0,2"

d = 3 :' distance between the line endpoints (pixels)

dir[0] = d
dir[1] = -d
 
drawlines

run = 1

WAITUNTIL run = 0
CLOSEWINDOW w
END

sub messages
select @class
case @idclosewindow
run = 0
case @idcontrol
select @controlID
case 1
run = 0
case 2
setwindowcolor w,rgb(0,0,0)
drawlines
endselect
endselect
return

sub Rn(low,high)
' generates an integer random number between Low and High ..
n = int((high - low + 1) * rnd(1) + low)
return n

sub drawlines
' draw a screen of random lines to form a pattern ..
d = rnd(10) + 2 :' distance between the line endpoints (pixels)

for i = 0 to 2 step 2
x[i] = Rnd(sW)
x[i+1] = Rnd(sW) 
  y[i] = Rnd(sH)
  y[i+1] = Rnd(sH)

j = Rn(0,1): k = Rn(0,d-1): dx[i] = dir[j] - k
  j = Rn(0,1): k = Rn(0,d-1): dy[i] = dir[j] - k
  j = Rn(0,1): k = Rn(0,d-1): dx[i+1] = dir[j] - k
  j = Rn(0,1): k = Rn(0,d-1): dy[i+1] = dir[j] - k
next i

for n = 1 to (rnd(100) + 50)

if (n%20 = 0)
r = rnd(255)
g = rnd(255)
b = rnd(255)
endif

for i = 0 to 2 step 2
x[i] = x[i] + dx[i] :' Coordinates changed by dx/dy
y[i] = y[i] + dy[i]
x[i+1] = x[i+1] + dx[i+1]
    y[i+1] = y[i+1] + dy[i+1]

if (x[i] <= 50) | (x[i] >= sW-50) :' Change direction when nearing the screen edge
dx[i] = - dx[i]
    endIf
if (y[i] <= 50) | (y[i] >= sH-50)
dy[i] = - dy[i]
    endIf
    if (x[i+1] <= 50) | (x[i+1] >= sW-50)
      dx[i+1] = - dx[i+1]
    endIf
    if (y[i+1] <= 50) | (y[i+1] >= sH-50)
      dy[i+1] = - dy[i+1]
    endIf

line w,x[i],y[i],x[i+1],y[i+1],rgb(r,g,b)
line w,sW-x[i],sH-y[i],sW-x[i+1],sH-y[i+1],rgb(r,g,b)
line w,x[i],sH-y[i],x[i+1],sH-y[i+1],rgb(r,g,b)
line w,sW-x[i],y[i],sW-x[i+1],y[i+1],rgb(r,g,b)

next i

next n

return



You can play around with many of the parameters to get different effects.

best wishes, :)

Graham
Tomorrow may be too late ..