User:Thierry Dugnolle/Python/Mathematical painter

The canvas and the palette
A mathematical painter draws and paints on electronic screens.

A canvas is a matrix of pixels. Each pixel is identified by its position (i, j) on the canvas, where i is the column number, j the row number. By convention (0, 0) is the left top pixel, and (Width-1, Height-1) the right bottom pixel, where Width is the number of pixels in width and Height the number of pixels in height.

A mathematical image is defined by assigning a brightness and a color to each pixel.

The brightness of a pixel is defined by an integer between 0 and 255. In black and white, 0 is black, 255 is white, 254 shades of gray separate them. 256 = 2 exponent 8. This is the number of numbers that can be encoded on one byte = 8 bits.

The color of a pixel is defined by a triplet of integers between 0 and 255: (red, green, blue).

(0, 0, 0) is black, (255, 255, 255) white, (255, 0, 0) brightest red, (0, 255, 0) brightest green, (0, 0, 255) brightest blue, (255, 255, 0) brightest yellow, (0, 255, 255) brightest cyan, and (255, 0, 255) brightest purple.

The color palette has 256*256*256 = 16,777,216 shades of color and brightness. A mathematical painter works with a palette of 16M colors. For computers, 1K = 210 = 1024 and 1M = 220 = 1,048,576. M is for Mega.

The palette can be represented by a cube. Black and White are two opposite vertices of the cube. Red, Green, Blue, Yellow, Cyan and Purple are the other six vertices.





The palette can also be represented by a double cone:





The axis of the color double cone is the line of grey shades (like the diagonal of the color cube) from white to black. Each point inside the double cone represents a color, defined by three coordinates, brightness, grey deviation and rainbow color, instead of red, green and blue in the color cube.

The canvas is a discrete field, because each of its pixels is identified by a pair of integers: (column number, row number). It is a field with discrete values, because each pixel is assigned a triplet of integers: (red, green, blue).

The paintbrush
A paintbrush draws continuous and differentiable (or rectifiable, this means that lines always have a tangent) lines except at a finite number of points: a line can be broken and have peaks.

A mathematical canvas is a discrete field with discrete values. A paintbrush must draw a line, therefore a continuous reality, in a discrete space.

If a line is one pixel wide, it is always with crenelations. To draw a high definition line without crenelation, we have to draw it a few pixels wide (at least 3) and to surround it by a halo:



The above triangle has been drawn as a succession of three corners, like the following one:



Any line can be drawn as a broken line, therefore as a succession of corners. To make rounded corners, a broken line must be divided at the middle of each of its segments.

An example of a broken line with 98 corners (and 100 points):



When a line comes from the back to the front of another line, there is a kind of jump from "line 1 is behind line 2" to "line 1 is in front of line 2". Animations are better with continuous transitions, like the following one:



Transparent and opaque paint
The paint can be more or less transparent, less or more opaque:



The vector image
A line is defined by a succession of a finite number of points. A point of the vector image is defined by its two coordinates in a plane (two coordinates is a vector). The vector image is the key to high definition computer graphics, because it is like a very high definition image: the position of each point in the vector image is defined with twice 15 digits or more.

A point of a line in space is defined by three coordinates. It is first projected on the plane of the camera or of the eye of the drawer, considered as a vector image, and then again projected on the canvas.

In a plane, the x axis is usually the left right axis and the y axis, the down up one. In the space, the x axis is still the left right axis, but the z axis is the down up one, and with a right handed frame, the y axis is the near far axis. The more y is positive, the farther.

The perception of depth
A 3D painter perceives the depth of space. To each point of a 3D line is assigned its depth, that is, its distance to the optical center. All the corners of all the lines which project on the canvas are identified in a depth matrix. In such a matrix, to each pixel of the canvas is assigned an array of corners which project on this pixel. The array is ordered according to the depth of the corners. The depth matrix is like an ordered memory of the depth of all the parts of all lines (or other objects) which project on the canvas.

Examples of main.py files
And God said, Let there be light: and there was light. (Genesis 1,4)

In the beginning was the Word (John 1,1)

A main.py file is like a script. It gives all the instructions to the painter to draw and paint an image or a succession of images.

High definition triangle

Continuous line crossing transition

A Chua line:



Cubic Galaxy:



A very little grain of salt:



Diffusion in one dimension:



Linear palettes
A linear palette assigns a color to each real number, usually between 0 and 1 (or -1 and 1). A linear palette is like a line in the cube of colors, the fundamental palette. The simplest line is the straight line between two colors. It is a gradation from the first color to the second one.



Gradation from black to white

.

.

Gradation from gold to black

.

.

Heat colors

.

.

Depth colors

.

.

Psychedelic colors

.

.

More psychedelic colors

.

.

Periodic rainbow flag

.

.

Periodic bright rainbow

.

.

Periodic yellow green cyan

.

.

A periodic linear palette is like a loop in the cube of colors, a line without extremities.

Computer graphics is polycosmoscopy
Physics is monocosmic, mathematics is polycosmic.

Physics is a science of our universe, the Universe, the visible and tangible world in which we live. It is easy to prove that this universe is unique: two beings who act on each other are part of the same universe, by definition of a universe. A universe contains all beings that act on each other. But an observation always results from an action of an observed object on an observer. Everything that can be observed by a being from a universe is therefore also a being from this universe, which proves that our observable universe is unique. A being that is part of another universe cannot be observed from our universe.

Mathematics is a science of all theoretical beings. As soon as we can think of a being, it has a theoretical existence. That we can define it in words and reason about it is enough for it to exist. Theoretical beings are possibilities, their reality is only virtual. Their existence as a possibility is both more and less than existence in our universe, because theoretical existence is unaffected by the passage of time. Everything that exists today in our universe will eventually disappear, or almost everything, while a theoretically possible being is eternally possible.

Computers are universal machines. They can make all possible calculations on all beings that can be defined with a finite amount of information. Now all mathematical beings can be defined with a finite quantity of information, or be approached by an infinite series of steps which require a finite quantity of information. So computers can do all possible calculations on all mathematical beings. Computer graphics is polycosmoscopy, because it enables us to study all theoretically possible universes.

Reference: the cosmoscope is a theoretical invention of David Chalmers in Constructing The World (2012). Polycosmoscopy is a generalization.

ODE.py
References:

Differential equations, dynamical systems and an introduction to chaos, Hirsch, Morris William., Smale, Stephen, Devaney, Robert Luke (2004)

Chapitres supplémentaires de la théorie des équations différentielles ordinaires, V. Arnold (1980)