This post was last edited by sylar^z on 2020-4-11 18:17
I made a running polygon using the stm32f407 core board. The polygons include triangles, squares, pentagons and hexagons, which are randomly generated by pressing buttons. The size, moving direction, moving speed, and rotation angular velocity of the polygon are all randomly generated.
//------------------------------------------------ -------------------------------------------------- --------------------------
I saw the suggestion from @ led2015 below . I sorted it out and shared my production ideas, hoping it will be of some use to you.
This fun oscilloscope is realized by using the dual-channel XY mode of the oscilloscope and the visual aftereffect to achieve image/graphic output. As for how to set the XY mode of the oscilloscope, the methods vary for different models of oscilloscopes, so you can search it yourself.
The running polygon is drawn by determining the vertices of the polygon and drawing the points into lines. How to determine the vertices? It's very simple. A regular polygon has a circumscribed circle, and the coordinates of each vertex can be easily determined through the circumscribed circle. As shown below:
Among the polygons I have implemented, the five-pointed star is the most complex, so I will use the five-pointed star as an example here. Through the diameter R of the circumscribed circle, the angle between each vertex and the center of the circle and the horizontal line, the sine and cosine functions are used to calculate the [X, Y] coordinates of the vertex relative to the center of the circle. Vertex 1:
X = R * COS ( A );
Y = R * SIN ( A );
Vertex 2:
X = R * COS ( A + 72 );
Y = R * SIN ( A + 72 );
Among them, A = 18 degrees. The same applies to other vertices.
When drawing a line, start from vertex 1 à vertex 3 à vertex 5 à vertex 2 à vertex 4 à vertex 1;
At the same time, you can change the size of the five-pointed star by controlling R.
The next step is to make the five-pointed star move by setting a set of parameters, namely the speed (pixels) of the center of the circle, the direction of the center of the circle (the slope of the running line), and the angle of rotation.
When moving, you need to consider the boundary. When the pentagram reaches the boundary, you need to go back. The boundary coordinates and diameter R can be used to calculate when the pentagram and the boundary meet. After reaching the boundary, you can reverse the slope of the running track to switch the direction when returning. When you encounter the left and right boundaries, you also need to reverse the moving speed to switch the direction.
The rotation angle can be achieved by adding an angle to the starting angle A of vertex 1 in time.
Finally, a new polygon is created by key interruption. Each parameter gets a random number through RNG.
The software configuration is relatively simple, just enable the DAC and two timers. I set the timer to 100us for drawing points and 100ms for moving polygons. The logic implementation is not complicated.
|