How to resolve the algorithm Barnsley fern step by step in the Oberon-2 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Barnsley fern step by step in the Oberon-2 programming language

Table of Contents

Problem Statement

A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS).

Create this fractal fern, using the following transformations: Starting position: x = 0, y = 0

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Barnsley fern step by step in the Oberon-2 programming language

Source code in the oberon-2 programming language

MODULE BarnsleyFern;
(**
	Oxford Oberon-2
**)

	IMPORT Random, XYplane;

	VAR
		a1, b1, c1, d1, e1, f1, p1: REAL;
		a2, b2, c2, d2, e2, f2, p2: REAL;
		a3, b3, c3, d3, e3, f3, p3: REAL;
		a4, b4, c4, d4, e4, f4, p4: REAL;
		X, Y: REAL;
		x0, y0, e: INTEGER;

	PROCEDURE Draw;
		VAR x, y: REAL; xi, eta: INTEGER; rn: REAL;
	BEGIN
		REPEAT
			rn := Random.Uniform();
			IF rn < p1 THEN
				x := a1 * X + b1 * Y + e1; y := c1 * X + d1 * Y + f1
			ELSIF rn < (p1 + p2) THEN
				x := a2 *X + b2 * Y + e2; y := c2 * X + d2 * Y + f2
			ELSIF rn < (p1 + p2 + p3) THEN
				x := a3 * X + b3 * Y + e3; y := c3 * X + d3 * Y + f3
			ELSE
				x := a4 * X + b4 * Y + e4; y := c4 * X + d4 * Y + f4
			END;
			X := x; xi := x0 + SHORT(ENTIER(X * e));
			Y := y; eta := y0 + SHORT(ENTIER(Y * e));
			XYplane.Dot(xi, eta, XYplane.draw)
		UNTIL "s" = XYplane.Key()
	END Draw;

	PROCEDURE Init;
	BEGIN
		X := 0; Y := 0;
		x0 := 120; y0 := 0; e := 25;

		a1 := 0.00; a2 :=  0.85; a3 :=  0.20; a4 := -0.15;
		b1 := 0.00; b2 :=  0.04; b3 := -0.26; b4 :=  0.28;
		c1 := 0.00; c2 := -0.04; c3 :=	0.23; c4 :=  0.26;
		d1 := 0.16; d2 :=  0.85; d3 :=	0.22; d4 :=	 0.24;
		e1 := 0.00; e2 :=  0.00; e3 :=	0.00; e4 :=  0.00;
		f1 := 0.00; f2 :=  1.60; f3 :=	1.60; f4 :=  0.44;
		p1 := 0.01; p2 :=  0.85; p3 :=	0.07; p4 :=	 0.07;
		XYplane.Open;
	END Init;

BEGIN
	Init;Draw
END BarnsleyFern.

  

You may also check:How to resolve the algorithm Achilles numbers step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Smith numbers step by step in the Perl programming language
You may also check:How to resolve the algorithm Loops/Break step by step in the GAP programming language
You may also check:How to resolve the algorithm Guess the number step by step in the Pascal programming language
You may also check:How to resolve the algorithm Checkpoint synchronization step by step in the Clojure programming language