On February 14, 2024, today is Valentine's Day!
I don't know if you have watched Li Xun's love on the TV series "Ignite Me, Warm You", so I will show you a little here.
How to make a heart beating heart program?
Find the high-numbered cardioid parametric equation:
x = sin^3(θ)When writing a cardioid shape, we simply multiply x, y by the radius r and zoom in on it.y = (13 * cos(θ)5 * cos(2θ) 3 * cos(3θ) cos(4θ))/ 16
From the above equation, a number of points on the curve can be obtained, which are denoted as the set s
Step 2: Generate points within the curve.
For the internal points, we diffuse s inward so that it conforms to the exponential distribution, and we get s'
Let e m, n] and e e( ).
Inward diffusion of p (x, y) s yields point p' ∈ s':
p' = (x, y) *e
The degree of diffusion depends on the parameters m, n,
For the outer points, we diffuse s outward so that it conforms to a uniform distribution, and we get s''
Let u u [1, 1 + b].
Spread outward to p (x, y) s to get the point p'' ∈ s'':
p'' = (x, y) *u
The degree of diffusion depends on parameter b
The above knowledge foreshadowing can only achieve a static pattern, and in order to achieve an animation effect, it is necessary to add a periodic beating to simulate the process of our heart beating.
Introduce the time parameter t and the periodic function t(t) = sin 2(t) (can be other periodic functions, depending on the effect).
For p s u s'
The degree of periodic scaling is inversely proportional to its distance d from the origin, which can be measured by r d (r is the radius of the cardioid curve).
Add order i to it to increase the effect of distance on the degree of scaling (r d) i
We can get the following function.
d' = d * 1 + a * t(t) *r/d)^i)The outer point reaches the maximum value when the inner point shrinks to the minimum value, so it is one phase different from the above equation.
Run the program, which runs the test in the Visual C++ 2022 operating environment.
Compiler the program, run.
You can see a heart-shaped beating animation pop up directly.
The program** interception is not complete, you can send a private message if you need it.
Valentine's Day