## Barnsley fern

For finished programs
kibernetik
Posts: 133
Joined: Tue Aug 06, 2019 3:03 pm

### Barnsley fern

This is my version of this fractal:

Code: Select all

``````w h = scrsize|2
draw clear 1, 1, 1
draw color 0, 0.5, 0
do
r = rndi 100
if r<85 : x y = 0.85*x+0.04*y, -0.04*x+0.85*y+1.6
elseif r<92 : x y = 0.2*x-0.26*y, 0.23*x+0.22*y+1.6
elseif r<99 : x y = -0.15*x+0.28*y, 0.26*x+0.24*y+0.44
else : x y = 0, 0.16*y
endif
draw point x/10*w+w/2, h-y/10*h
redo
``````
Снимок экрана 2019-09-09 в 14.05.30.jpg (208.07 KiB) Viewed 280 times

udo
Posts: 6
Joined: Mon Sep 30, 2019 8:55 am

### Re: Barnsley fern

This is a version after that published by Martin Reiser and Niklaus Wirth in their book "Programmieren in Oberon: Das neue Pascal", published 1994. The English original "Programming in Oberon: Steps beyond Pascal and Module" was published in 1992.
See: https://en.wikipedia.org/wiki/Oberon_(p ... _language)
The program will print the famous fern and a maple leaf!

Code: Select all

``````' IFS
' version 1.0
' U. Rabe, 2020
' Done with BestBasic
' It's public domain
' Based on a sample in:
' Martin Reise & Niklaus Wirth
' Programmieren in Oberon: Das neue Pascal
' ISBN 3-89319-675-9

Farn
data 300, 750, 64
data 0, 0.85, 0.2, -0.15, 0, 0.04, -0.26, 0.28
data 0, -0.04, 0.23, 0.26, 0.16, 0.85, 0.22, 0.24
data 0, 0, 0, 0, 0, 1.6, 1.6, 0.44
data 0.01, 0.85, 0.07, 0.07

Ahorn
data 100, 600, 450
data 0.65, 0.65, 0.32, -0.32, -0.013, -0.026, -0.32, 0.32
data 0.013, 0.026, 0.32, 0.32, 0.65, 0.65, 0.32, 0.32
data 0.175, 0.175, 0.2, 0.8, 0, 0.35, 0, 0
data 0.3, 0.3, 0.2, 0.2

inbutt set 1 "Fern", 10, 10, 100, 25
inbutt set 2 "Maple leaf", 10, 45, 100, 25
inbutt set 3 "Bye", 10, 80, 100, 25

do
if inbutt hit 1 then
o=1
break
else if inbutt hit 2 then
o=2
break
else if inbutt hit 3 then
o=3
break
end if
redo

draw clear 1, 1, 1

if o=3 then
end
else if o=1 then
restore to Farn
else if o=2 then
restore to Ahorn
end if

x=0
y=0
scr size 600, 900
randomize

for i=1 to 100000
rn=rnd
if rn<p1 then
xp=a1*x+b1*y+e1
yp=c1*x+d1*y+f1
else if rn<(p1+p2) then
xp=a2*x+b2*y+e2
yp=c2*x+d2*y+f2
else if rn<(p1+p2+p3) then
xp=a3*x+b3*y+e3
yp=c3*x+d3*y+f3
else
xp=a4*x+b4*y+e4
yp=c4*x+d4*y+f4
end if
x=xp
xi=x0+(x*e)
y=yp
eta=y0-(y*e)
draw point xi, eta
next i

``````
Attachments
maple.png (200.71 KiB) Viewed 159 times
fern.png (171.36 KiB) Viewed 159 times

kibernetik
Posts: 133
Joined: Tue Aug 06, 2019 3:03 pm

### Re: Barnsley fern

Maple leaf is fantastic!