Learn R Programming

geostats (version 1.6)

sierpinski: Sierpinski carpet

Description

Returns a matrix of 0s and 1s that form a Sierpinski carpet. This is a two dimensional fractal, which is generated using a recursive algorithm that is built on a grid of eight black squares surrounding a white square. Each level of recursion replaces each black square by the same pattern.

Usage

sierpinski(n = 5)

Value

a square matrix with 0s and 1s.

Arguments

n

an integer value controling the number of recursive levels.

Examples

Run this code
g <- sierpinski(n=5)
image(g,col=c('white','black'),axes=FALSE,asp=1)

Run the code above in your browser using DataLab