0% found this document useful (0 votes)
33 views3 pages

Repetition Fibonacci Number

Uploaded by

icehena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Repetition Fibonacci Number

Uploaded by

icehena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

48 Parametric patterns

Repetition
Repetition can be thought of as the simple act of copying
an element multiple times (fig. 38). In parametric systems,
repetition can become more interesting, because a repeated
element can maintain the basic topology of its predecessor
without having to be exactly identical to it. Using a rule-
based system, one can vary the repeated element according
to any number of parameters (e.g. distance, time, location,
etc.). In mathematical terms, a simple repetition could
be in the form of 2, 2, 2, 2, 2 ... and so on. However, a
repetition that uses the Fibonacci rule, which states that,
given the first two numbers 0 and 1, any subsequent
number is the sum of the two preceding numbers (0, 1,
1, 2, 3, 5, 8, 13, 21 ...), can become more interesting –
and potentially more useful from a design perspective.

fig. 38 Clay tiles.


Tutorial Fibonacci number generator

For this tutorial, we will use a piece of free open-source software Processing from Processing.org, and follow some of the basic
called Processing. The Processing software is an environment examples on the Processing.org website. For this first simple
for creating images, animations and interactive media. Before tutorial, we will not draw any shapes. We will simply create an
commencing this tutorial, you should download and install algorithm that prints out a Fibonacci sequence of numbers.

Step 1 Listing the Fibonacci series


Start a new Sketch in Processing (File New)
Type the following text exactly in the sketch window. Any errors, misspellings
or even a single missing semi-colon will make the script fail. So, be careful
that you type it exactly as it is listed below (without the line numbers):

1 int a = 0;
2 int b = 0;
3 int fibonacci = 0;
4 int total = 14;
5 int i = 0;
6 for (i=0; i < total; i++) {
7 if (i == 0) {
8 fibonacci = 0;
9 }
10 else if(i == 1) {
11 fibonacci = 1;
12 }
13 else {
14 a = b;
15 b = fibonacci;
16 fibonacci = a + b;
17 }
18 print (fibonacci+” “);
19 }

Press the Run button in the top left corner of the sketch window to run this
script. You should see, at the bottom of the window, the first 14 numbers
of the Fibonacci series (0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233).
Let’s examine this script in detail. At the top of the script, we
declare some variables that we will use in this script.
• a is an integer variable that will store the number prior to last
in the Fibonacci series. It has an initial value of 0.
• b is an integer variable that will store the number prior to the
current Fibonacci number. It has an initial value of 0.
• fibonacci is an integer variable that will store the current Fibonacci
number that we are trying to compute. The first two occurrences
of Fibonacci numbers are 0 and 1 respectively. After that we will
compute it using the following formula: fibonacci = a + b.
• total is an integer variable that will store how many
Fibonacci numbers we wish to compute.
FiboNaCCi NumbEr gENErator/CoNtiNuEd

• i is an integer variable that will store the current index of the Fibonacci
number we are computing. think of i as a counter that starts out as 0 and then
increments by 1 every time we repeat the loop until it reaches total. indices
are useful because they tell us how many times we have repeated a loop, so
we can customize the actions of the algorithm for that particular iteration.
next, we create the actual loop that will repeat as long as i is less
than total. in this loop i starts out at 0 and then is incremented by
1 at the start of each subsequent iteration through the loop.

Step 2 draWing a goLden rectangLe


if we apply the Fibonacci numbers to geometry, we can get complex shapes,
such as the Fibonacci golden rectangle and the golden spiral, which is
composed of circular arcs connecting the opposite corners of squares sized
according to the Fibonacci numbers. the above algorithm can be easily
modified to draw the golden rectangle and golden spiral. Let’s start by drawing
the golden rectangle. the changes are highlighted in bold below:

1 int a = 0;
2 int b = 0;
3 int fibonacci = 0;
4 int total = 14;
5 int i = 0;
6 size(600,400);
7 background(255,255,255);
8 fill(0,0,0,0);
9 smooth();
10 translate(384,148);
11 for (i=0; i < total; i++) {
12 if (i == 0) {
13 fibonacci = 0;
14 }
15 else if(i == 1) {
16 fibonacci = 1;
17 }
18 else {
19 a = b;
20 b = fibonacci;
21 fibonacci = a + b;
22 }
23 print (fibonacci+” “);
24 rotate(Pi/2);
25 translate(b,-b);
26 rect(0,0,fibonacci, fibonacci);
27 }

You might also like