This is a rewrite of an old program I wrote inspired by the biomorphs to generate random patterns that could be evolved. The example in the animal kingdom is groups of apparently different animals really being made up of the same components modified. The skeleton being a good visual example. My patterns consists of 10 lines of random length which are connected end to end with different angles. So I guess you could say it has a gene for each segment specifying a length and a connection angle. Even with only two variables (animals have many more) a lot of visually pleasing patterns can be generated.

The program below generates a random pattern and then 8 variants. There appears to be something wrong with the code that generates the variants in that the bilateral pattern appears to be assymetrical. With a selecting agent one pattern can evolve into another pattern.

Sexual reproduction would require parents swapping genes allowing large but stable changes as oppposed to the incremental changes possible with mutations.

Code: Select all

`'some useful defines`

Const Pi = 4 * Atn(1)

Dim Shared As Double TwoPi = 8 * Atn(1)

Dim Shared As Double RtoD = 180 / Pi ' radians * RtoD = degrees

Dim Shared As Double DtoR = Pi / 180 ' degrees * DtoR = radians

screenres 960,480,32

type PATTERN

as double x(10)

as double x2(10)

as double y(10)

as double y2(10)

as double s(10)

as double s2(10)

as double a(10)

as double a2(10)

end type

dim as PATTERN p(8)

dim as PATTERN p1 'parent pattern

p1.x(0)=240

p1.y(0)=150

p1.x2(0)=240

p1.y2(0)=150

for j as integer = 0 to 7

p(j).x(0) = j*100+100

p(j).y(0) = 300

p(j).x2(0) = j*100+100

p(j).y2(0) = 300

next j

'start with parent pattern

for i as integer = 0 to 9

p1.s(i)=int(rnd(1)*10)+10 'length

p1.a(i)=int(rnd(1)*360)*DtoR 'angle

p1.a2(i)=(180-(p1.a(i)*RtoD))*DtoR 'horizontal flip degrees

p1.s2(i)=p1.s(i)

next i

dim as integer selection

do

cls

'generate variants of parent pattern

for j as integer = 0 to 7

for i as integer = 0 to 9

p(j).s(i)= p1.s(i) + int(rnd(1)*3)-1 'length

p(j).a(i)= (p1.a(i)*RtoD + (int(rnd(1)*3)-1))*DtoR 'angle

p(j).a2(i)= (180-(p1.a(i)*RtoD))*DtoR 'horizontal flip degrees

p(j).s2(i)= p1.s(i)

next i

next j

screenlock()

'draw parent pattern

circle (p1.x(0),p1.y(0)),3,rgb(255,255,0)

for i as integer = 1 to 9 'for each segement

p1.x(i) = p1.x(i-1) + cos(p1.a(i)) * p1.s(i)

p1.y(i) = p1.y(i-1) + sin(p1.a(i)) * p1.s(i)

line (p1.x(i-1),p1.y(i-1))-(p1.x(i),p1.y(i)),rgb(255,255,255)

p1.x2(i) = p1.x2(i-1) + cos(p1.a2(i)) * p1.s2(i)

p1.y2(i) = p1.y2(i-1) + sin(p1.a2(i)) * p1.s2(i)

line (p1.x2(i-1),p1.y2(i-1))-(p1.x2(i),p1.y2(i)),rgb(255,255,255)

next i

'draw variants

for j as integer = 0 to 7 'for each pattern

circle (p(j).x(0),p(j).y(0)),3,rgb(255,255,0)

for i as integer = 1 to 9 'for each segment

p(j).x(i) = p(j).x(i-1) + cos(p(j).a(i)) * p(j).s(i)

p(j).y(i) = p(j).y(i-1) + sin(p(j).a(i)) * p(j).s(i)

line (p(j).x(i-1),p(j).y(i-1)) - (p(j).x(i),p(j).y(i)),rgb(0,255,0)

p(j).x2(i) = p(j).x2(i-1) + cos(p(j).a2(i)) * p(j).s2(i)

p(j).y2(i) = p(j).y2(i-1) + sin(p(j).a2(i)) * p(j).s2(i)

line (p(j).x2(i-1),p(j).y2(i-1)) - (p(j).x2(i),p(j).y2(i)),rgb(0,0,255)

next i

next j

locate 2,2

print "Hit space bar to generate new variation"

locate 4,2

print "Hit ESC key to exit program"

locate 50,2

print " 1 2 3 4 5 6 7 8"

screenunlock()

locate 6,2

'input "select variation 1 to 8 or 0 to exit";selection

'dim as integer selection,choice

'selection = choice+1

'copy to new parent

'if selection >0 and selection < 9 then

' for i as integer = 0 to 9

' p1.s(i) = p(selection-1).s(i)

' p1.a(i) = p(selection-1).a(i)

' p1.s2(i)= p(selection-1).s2(i)

' p1.a2(i)= p(selection-1).a2(i)

' next i

'end if

'print "CHOICE = ";choice

for i as integer = 0 to 9

p1.s(i)=int(rnd(1)*10)+10 'length

p1.a(i)=int(rnd(1)*360)*DtoR 'angle

p1.a2(i)=(180-(p1.a(i)*RtoD))*DtoR 'horizontal flip degrees

p1.s2(i)=p1.s(i)

next i

sleep

loop until multikey(&H01)

end