VA3520

Evolutionary Graphics
Class 03: Recursion
Thinking Recursively
Money example

If you want to collect $1,000 from your BU
classmates, and each of the student can only

afford to give you...
Method 1

The first method is a traditional thinking mode.
You can approach every student you meet and

ask him/her to don...
Iterative approach

We call this – iterative approach. It is similar to a
loop in computer programming. You continue to

a...
Iterative approach

while (money collected < $1,000) {
meet next student;
ask for $10 donation;

if (ok)
add to the money ...
Other approach

The iterative approach is straight forward and
effective. We can ask if there are any better

approaches t...
Recursive approach

It is not very efficient if I need to ask 100 students
to collect the $1,000.
Consider the case: I jus...
Recursive approach

Then the 10 students will concurrently go out to
ask 10 or more students to collect $10 each from

the...
Recursive approach

$1000

$100

$100

$10

$10

...

$100

$10

$100

...

$10
Divide and conquer

Divide and conquer
1. Decompose the original problem into simpler
instances of the same problem.
2. Th...
Piet Mondrian
Blank canvas
Problem statement

We want to divide a rectangle into a square and
a smaller rectangle. Continue to divide the

smaller re...
First division
The process

Note that, the second division will be the same
as the first one, except the rectangle rotates by

90 degrees...
Second division
Third division
Forth division
Fifth division
The process

Note that, the second division will be the same
as the first one, except the rectangle rotates by

90 degrees...
Fibonacci numbers

We go back to the study of the Fibonacci
numbers. Remember,
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, …

If we ...
Fibonacci numbers

It is not easy for us to write down a formula like,

f(n) = (n + ?) / ???
It is much more easy for us t...
Recursive definition

It is obviously we can write down,

f(n) = f(n-1) + f(n-2)
Initial conditions

In order to find out any f(n) by the following
formula,
f(n) = f(n-1) + f(n-2)

We must have two initi...
Golden section in practice
Golden section in CFA

There are multiple ways in Context Free Art to
draw the Golden Section. We compare the

iterative a...
Iterative golden section

startshape Golden
shape Golden {

drawRectangle []
}
shape drawRectangle {
SQUARE [s 1.61803399 ...
Iterative golden section
Iterative golden section

startshape Golden
shape Golden {

rectangle []
}
shape rectangle {
drawRectangle [a -0.8]
}
shap...
Iterative golden section
Iterative golden section

startshape Golden
shape Golden {

loop 2 [s 0.61803399 r -90 x 0.5] rectangle []
}
shape rectang...
Iterative golden section
Iterative golden section

startshape Golden
shape Golden {

loop 10 [s 0.61803399 r -90 x 0.5] rectangle []
}
shape rectan...
Iterative golden section
Recursive golden section

startshape Golden
shape Golden {

rectangle []
}
shape rectangle {
drawRectangle [a -0.8]
}
shap...
Recursive golden section
Recursive definition

shape rectangle {
drawRectangle [a -0.8]
rectangle [?]

}

Note that we enter into a difficult situa...
Recursive definition

shape rectangle {
drawRectangle [a -0.8]
rectangle [?]

}

In order to let the Context Free Art stop...
Recursive definition

shape rectangle {
drawRectangle [a -0.8]
rectangle [s 0.61803399 r -90 x 0.5]

}

Let’s try out this...
Recursive definition

startshape Golden
shape Golden {

rectangle []
}
shape rectangle {
drawRectangle [a -0.8]
rectangle ...
Recursive golden section
Recursive example

startshapeMyShape
shape MyShape {

Shape1 []
}
shape Shape1 {
CIRCLE [sat 1 b 1]
}
Recursive example
Recursive example

startshapeMyShape
shape MyShape {

Shape1 []
MyShape [x 1 s 0.99]
}
shape Shape1 {
CIRCLE [sat 1 b 1]
}
Recursive example
Recursive example

startshapeMyShape
rule MyShape {

Shape1 []
MyShape [x 1 r 51 s 0.99]
}
shape Shape1 {
CIRCLE [sat 1 b ...
Recursive example
Recursive example

startshapeMyShape
shape MyShape {

Shape1 []
MyShape [x 1 r 51 s 0.99 h 51]
}
shape Shape1 {
CIRCLE [sa...
Recursive example
Spiral example
Spiral example

startshapeMyShape
CF::Background = [b -1]
shape MyShape {
Shape1 []
}
shape Shape1 {
Shape1 [s .95 x 2 r 1...
Spiral example

startshapeMyShape
CF::Background = [b -1]
shape MyShape {
loop 4 [r 90] Shape1 []
}
shape Shape1 {
Shape1 ...
Spiral example
Spiral example

startshapeMyShape
CF::Background = [b -1]
shape MyShape {
loop 2 [r 180] Shape1 []
}
shape Shape1 {
Shape1...
Spiral example
Spiral example

startshapeMyShape
CF::Background = [b -1]
shape MyShape {
loop 2 [r 180] Shape1 [x -2 flip 45]
}
shape Sha...
Spiral example
More example
Upcoming SlideShare
Loading in...5
×

Evolutionary Graphics - Class 03 2014

378

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
378
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Evolutionary Graphics - Class 03 2014

  1. 1. VA3520 Evolutionary Graphics Class 03: Recursion
  2. 2. Thinking Recursively
  3. 3. Money example If you want to collect $1,000 from your BU classmates, and each of the student can only afford to give you $10, how would you do?
  4. 4. Method 1 The first method is a traditional thinking mode. You can approach every student you meet and ask him/her to donate $10.
  5. 5. Iterative approach We call this – iterative approach. It is similar to a loop in computer programming. You continue to ask students for $10 until you reach the target of $1,000.
  6. 6. Iterative approach while (money collected < $1,000) { meet next student; ask for $10 donation; if (ok) add to the money collected; }
  7. 7. Other approach The iterative approach is straight forward and effective. We can ask if there are any better approaches to this problem.
  8. 8. Recursive approach It is not very efficient if I need to ask 100 students to collect the $1,000. Consider the case: I just ask 10 students to collect money for me. Each of them has to collect $100 by whatever means.
  9. 9. Recursive approach Then the 10 students will concurrently go out to ask 10 or more students to collect $10 each from them.
  10. 10. Recursive approach $1000 $100 $100 $10 $10 ... $100 $10 $100 ... $10
  11. 11. Divide and conquer Divide and conquer 1. Decompose the original problem into simpler instances of the same problem. 2. The simpler problems must become so simple that they can be solved without further division. 3. Combine the smaller solutions to produce a solution to the original problem.
  12. 12. Piet Mondrian
  13. 13. Blank canvas
  14. 14. Problem statement We want to divide a rectangle into a square and a smaller rectangle. Continue to divide the smaller rectangle until it is too small to be visible on screen.
  15. 15. First division
  16. 16. The process Note that, the second division will be the same as the first one, except the rectangle rotates by 90 degrees counter-clockwise.
  17. 17. Second division
  18. 18. Third division
  19. 19. Forth division
  20. 20. Fifth division
  21. 21. The process Note that, the second division will be the same as the first one, except the rectangle rotates by 90 degrees counter-clockwise.
  22. 22. Fibonacci numbers We go back to the study of the Fibonacci numbers. Remember, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, … If we denote, f(1) = 1, f(2) = 1, f(3) = 2, f(4) = 3, f(5) = 5, …, how can we write down a general formula for f(n)?
  23. 23. Fibonacci numbers It is not easy for us to write down a formula like, f(n) = (n + ?) / ??? It is much more easy for us to write, however, with this format. What is the relation among: f(n), f(n-1), f(n-2)?
  24. 24. Recursive definition It is obviously we can write down, f(n) = f(n-1) + f(n-2)
  25. 25. Initial conditions In order to find out any f(n) by the following formula, f(n) = f(n-1) + f(n-2) We must have two initial conditions. That is f(1) = 1 f(2) = 1
  26. 26. Golden section in practice
  27. 27. Golden section in CFA There are multiple ways in Context Free Art to draw the Golden Section. We compare the iterative and the recursive ways.
  28. 28. Iterative golden section startshape Golden shape Golden { drawRectangle [] } shape drawRectangle { SQUARE [s 1.61803399 1] }
  29. 29. Iterative golden section
  30. 30. Iterative golden section startshape Golden shape Golden { rectangle [] } shape rectangle { drawRectangle [a -0.8] } shape drawRectangle { SQUARE [s 1.61803399 1] }
  31. 31. Iterative golden section
  32. 32. Iterative golden section startshape Golden shape Golden { loop 2 [s 0.61803399 r -90 x 0.5] rectangle [] } shape rectangle { drawRectangle [a -0.8] } shape drawRectangle { SQUARE [s 1.61803399 1] }
  33. 33. Iterative golden section
  34. 34. Iterative golden section startshape Golden shape Golden { loop 10 [s 0.61803399 r -90 x 0.5] rectangle [] } shape rectangle { drawRectangle [a -0.8] } shape drawRectangle { SQUARE [s 1.61803399 1] }
  35. 35. Iterative golden section
  36. 36. Recursive golden section startshape Golden shape Golden { rectangle [] } shape rectangle { drawRectangle [a -0.8] } shape drawRectangle { SQUARE [s 1.61803399 1] }
  37. 37. Recursive golden section
  38. 38. Recursive definition shape rectangle { drawRectangle [a -0.8] rectangle [?] } Note that we enter into a difficult situation. The rule rectangle refers back to itself. It seems to go into an infinite loop again and again when we have to execute the rectangle definition.
  39. 39. Recursive definition shape rectangle { drawRectangle [a -0.8] rectangle [?] } In order to let the Context Free Art stop, we have to make sure that each time the rectangle is drawn, it has to be smaller and smaller until it is invisible on screen. Alternately, we have to add another definition for rectangle to stop referring itself.
  40. 40. Recursive definition shape rectangle { drawRectangle [a -0.8] rectangle [s 0.61803399 r -90 x 0.5] } Let’s try out this.
  41. 41. Recursive definition startshape Golden shape Golden { rectangle [] } shape rectangle { drawRectangle [a -0.8] rectangle [s 0.61803399 r -90 x 0.5] } shape drawRectangle { SQUARE [s 1.61803399 1] }
  42. 42. Recursive golden section
  43. 43. Recursive example startshapeMyShape shape MyShape { Shape1 [] } shape Shape1 { CIRCLE [sat 1 b 1] }
  44. 44. Recursive example
  45. 45. Recursive example startshapeMyShape shape MyShape { Shape1 [] MyShape [x 1 s 0.99] } shape Shape1 { CIRCLE [sat 1 b 1] }
  46. 46. Recursive example
  47. 47. Recursive example startshapeMyShape rule MyShape { Shape1 [] MyShape [x 1 r 51 s 0.99] } shape Shape1 { CIRCLE [sat 1 b 1] }
  48. 48. Recursive example
  49. 49. Recursive example startshapeMyShape shape MyShape { Shape1 [] MyShape [x 1 r 51 s 0.99 h 51] } shape Shape1 { CIRCLE [sat 1 b 1] }
  50. 50. Recursive example
  51. 51. Spiral example
  52. 52. Spiral example startshapeMyShape CF::Background = [b -1] shape MyShape { Shape1 [] } shape Shape1 { Shape1 [s .95 x 2 r 12 b .5 hue 10 sat 1] Block [] } shape Block { CIRCLE [] }
  53. 53. Spiral example startshapeMyShape CF::Background = [b -1] shape MyShape { loop 4 [r 90] Shape1 [] } shape Shape1 { Shape1 [s .95 x 2 r 12 b .5 hue 10 sat 1] Block [] } shape Block { CIRCLE [] }
  54. 54. Spiral example
  55. 55. Spiral example startshapeMyShape CF::Background = [b -1] shape MyShape { loop 2 [r 180] Shape1 [] } shape Shape1 { Shape1 [s 0.95 x 2 r 12 b 0.5 hue 10 sat 1] Block [] } shape Block { CIRCLE [] MyShape [s 0.25] }
  56. 56. Spiral example
  57. 57. Spiral example startshapeMyShape CF::Background = [b -1] shape MyShape { loop 2 [r 180] Shape1 [x -2 flip 45] } shape Shape1 { Shape1 [s 0.95 x 2 r 12 b 0.5 hue 10 sat 1] Block [] } shape Block { CIRCLE [] MyShape [s 0.25 flip 45] }
  58. 58. Spiral example
  59. 59. More example

×