In mathematics, a self-similar object is exactly or approximately similar to a part of itself (i.e. the whole has the same shape as one or more of the parts). Self-similarity is a typical property of fractals. The Sierpiński Triangle, also called the Sierpiński Gasket or the Sierpiński Sieve, is a fractal named after the Polish mathematician Wacław Sierpiński who described it in 1915. Originally constructed as a curve, this is one of the basic examples of self-similar sets, i.e. it is a mathematically generated pattern that can be reproducible at any magnification or reduction. The Sierpiński Carpet and Box Fractal use squares, rather than a triangle, but the self-similar behavior is identical.Using viral object-oriented programming (objects that create copies of themselves), self-similar objects are trivial to produce.
The following code creates an object, a square region, that then fills the top left quadrant, 1/2 its height and width, and then creates self-similar objects in the other 3 quadrants in order to duplicate the Sierpiński Triangle. Having the same logic, or viral programming, they do the same... and so on. I've slowed the output so the process can be seen...