Carpet function
The sponsored guys master web programming, in particular, PHP.
One of the first tasks in mastering tables, they get the task of rendering a multiplication table in PHP, sort of 25x25.
Next, simple “bells and whistles” begin - for example, to paint cells with even numbers in the resulting table. As it turned out, you can enjoy bells and whistles for hours.
It is expected to see something like
the output will get something like
Funny coloring of the cells can be obtained by replacing 2 with another number.
Here - for% 4 (I will leave% to emphasize that the remainder of division is used)
Here - for% 5
For primes we get a “cell” with a size corresponding to the number, for composite numbers - a rather funny pattern.
For example, for% 21
For even numbers, the pattern is diligently trying to represent a circle from itself, and to be precise, concentric circles - for example, for% 24
The image is stretched horizontally - because still the numbers the farther, the greater.
It becomes clear that the multiplication table itself has already become less interesting, so we will draw an image in which 1 pixel will correspond to one cell of our table, and the color will correspond to the selected condition.
At the same time, you can significantly increase the size of the table:
But what if the condition is cut off not by the criterion of division entirely, but by the criterion of a remainder not exceeding a certain value?
Already looks like a carpet. But for greater similarity, you will have to perform the following operation:
((($ x * $ y)% K1)% K2) ...% Kn)
It is logical that the coefficients should decrease with increasing n, otherwise there will be no special use from the operation - the series will degenerate to shorter.
Of course, the carpet should be colored. The main thing here is not to overdo it with the number of colors.
As a result, something like this turned out:
One of the first tasks in mastering tables, they get the task of rendering a multiplication table in PHP, sort of 25x25.
Next, simple “bells and whistles” begin - for example, to paint cells with even numbers in the resulting table. As it turned out, you can enjoy bells and whistles for hours.
It is expected to see something like
...
if (($x * $y) % 2 == 0) $color = "red";
else $color = "white";
...
the output will get something like
Funny coloring of the cells can be obtained by replacing 2 with another number.
Here - for% 4 (I will leave% to emphasize that the remainder of division is used)
Here - for% 5
For primes we get a “cell” with a size corresponding to the number, for composite numbers - a rather funny pattern.
For example, for% 21
For even numbers, the pattern is diligently trying to represent a circle from itself, and to be precise, concentric circles - for example, for% 24
The image is stretched horizontally - because still the numbers the farther, the greater.
It becomes clear that the multiplication table itself has already become less interesting, so we will draw an image in which 1 pixel will correspond to one cell of our table, and the color will correspond to the selected condition.
At the same time, you can significantly increase the size of the table:
For example,% 720 (6! = 1 * 2 * 3 * 4 * 5 * 6)
But what if the condition is cut off not by the criterion of division entirely, but by the criterion of a remainder not exceeding a certain value?
it looks like ($ x * $ y)% 720 <72
Already looks like a carpet. But for greater similarity, you will have to perform the following operation:
((($ x * $ y)% K1)% K2) ...% Kn)
It is logical that the coefficients should decrease with increasing n, otherwise there will be no special use from the operation - the series will degenerate to shorter.
it looks like ($ x * $ y)% 677% 255% 71 <13
Of course, the carpet should be colored. The main thing here is not to overdo it with the number of colors.
As a result, something like this turned out:
Some PHP code
который рисует ковры:
Немного ковров
Особенно хорош ковер при Gaussian Blur примерно на 2.5 пикселя.