Use a program to draw a kaleidoscope pattern

Effect demo

This article simulates the process of manually drawing a kaleidoscope pattern through sketchpad drawing. By adjusting the drawing parameters, you can adjust the number of petals, the degree of curvature and other characteristics.

In order to prevent being reprinted and sold by villains everywhere, this article only describes the drawing method without any code. At the same time, don't ask bloggers for codes in private messages. If you are really interested, you can do it yourself through the method explained in this article.

This article belongs to original content, reprinting is prohibited, and infringement must be investigated!

The final result of the kaleidoscope pattern is shown in the image above.

drawing steps

1. Write a function that can automatically generate polygon vertex coordinates

A polygon vertex is essentially a point taken at a certain angle on the circumference, so a loop can be used to calculate the coordinates of all vertices of a polygon with a specified number of sides.

When calling this function, pass the edge number parameter to get the polygon vertex position information corresponding to the edge number.

2. Calculate the trajectory of the center of the circle

The kaleidoscope pattern can be obtained by rotating the specified point on the small circle around the large circle, so the trajectory of the center of the small circle needs to be calculated.

In the figure above, the large circle is called polygon A, the center track of the small circle is called polygon B, and the small circle is called polygon C.

 

In order to facilitate debugging, you can draw the center track of the big circle and the small circle, and the small circle, and then proceed to the follow-up operation after confirming that it is correct.

If there are no problems, it should look like this:

Other parts should look similar to the picture above, except there is no final pattern. 

3. Use loops to draw rotating patterns

Set the initial angle to 0, and use a cycle to rotate the angle from the initial angle to the end angle.

For example, the pattern from 0 to 90 degrees is as follows:

For another example, the pattern from 0 to 180 degrees is as follows:

During this cycle, the available variable is the current cycle angle.

According to the current cycle angle, calculate the center track of the small circle, that is, polygon B.

Then use the position of polygon B to obtain the position of the small circle, and then rotate the small circle to obtain the position of the drawing point, that is, polygon C.

In the sample code above, the generated polygon is actually a circle, and the number of sides of the small circle can be set more, for example, 100. It doesn't matter how many sides the point draws, because there is only one point, and you can set values ​​such as 1, 2, and 3.

There is one thing to note here, the rotation direction of the center track of the small circle is opposite to the rotation direction of the drawing point.

For example, if the trajectory of the center of the small circle rotates clockwise, then the points on the small circle will rotate counterclockwise when the small circle rotates.

This program performs graphics drawing operations by simulating physical states. For example, in the case of a large circle with a circumference of 144 and a small circle with a circumference of 60, after one rotation, the landing point will not return to the initial position, but will go to the lower left corner.

If you don't encounter problems here, then a few more turns will give you the final pattern.

Guess you like

Origin blog.csdn.net/x1051496412/article/details/129886614