Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Algorithmic Patterns and Recursion | Advanced Generative Techniques
Generative Art with JavaScript and P5.js

bookAlgorithmic Patterns and Recursion

index.html

index.html

copy

To create visually complex patterns in generative art, you often rely on algorithms and recursion. Recursion is a programming technique where a function calls itself to solve smaller instances of a problem. In generative art, recursion allows you to build intricate structuresβ€”like trees, fractals, or spiralsβ€”by repeatedly applying the same drawing logic at different scales and positions.

A recursive function always needs a base case: this is a condition that tells the function when to stop calling itself. Without a base case, the recursion would continue forever, eventually causing a stack overflow error. In the recursive tree example above, the base case is if (len < 8) { return; }, which halts further branching when the branch length becomes small enough. By carefully designing your recursive rules and base cases, you can control the density and complexity of your generative visuals.

Algorithmic thinking is at the heart of generative art. You break down a visual idea into a set of rules or steps that can be repeated or modified programmatically. This approach lets you create patterns that would be difficult or impossible to draw by hand, but are easy for a computer to generate through code. Recursive algorithms, in particular, unlock a world of self-similar, organic, and endlessly intricate designs.

question mark

What is a base case in a recursive function?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 1

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you give an example of a recursive function used in generative art?

How does changing the base case affect the resulting pattern?

What are some common mistakes to avoid when using recursion in generative art?

bookAlgorithmic Patterns and Recursion

Swipe to show menu

index.html

index.html

copy

To create visually complex patterns in generative art, you often rely on algorithms and recursion. Recursion is a programming technique where a function calls itself to solve smaller instances of a problem. In generative art, recursion allows you to build intricate structuresβ€”like trees, fractals, or spiralsβ€”by repeatedly applying the same drawing logic at different scales and positions.

A recursive function always needs a base case: this is a condition that tells the function when to stop calling itself. Without a base case, the recursion would continue forever, eventually causing a stack overflow error. In the recursive tree example above, the base case is if (len < 8) { return; }, which halts further branching when the branch length becomes small enough. By carefully designing your recursive rules and base cases, you can control the density and complexity of your generative visuals.

Algorithmic thinking is at the heart of generative art. You break down a visual idea into a set of rules or steps that can be repeated or modified programmatically. This approach lets you create patterns that would be difficult or impossible to draw by hand, but are easy for a computer to generate through code. Recursive algorithms, in particular, unlock a world of self-similar, organic, and endlessly intricate designs.

question mark

What is a base case in a recursive function?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 1
some-alt