The most beautiful C language code

Everyone, when you see the title, you will definitely think about it a lot. What is the most beautiful code? Without further ado, the code first:

#include<stdio.h>#include

 <graphics.h>#include <math.h>#include <conio.h>#define PI 3.1415926 //Function to draw a heart-shaped line void cardioid(int x, int y, int a)//x: x square

Upward offset //y: y-direction offset //a: zoom factor

{ int x1, y1, x2, y2; double angle = 0; while (angle <= 2 * 

PI) {    x1 = a * (2 * sin(angle) + sin(2 * angle)) + x;    y1 = 

a * (2 * cos (angle) + cos (2 * angle)) + y; angle + = (PI / 180);   

 x2 = a * (2 * sin(angle) + sin(2 * angle)) + x;   

 y2 = a * (2 * cos (angle) + cos (2 * angle)) + y;

 line(x1, y1, x2, y2); Sleep(5); }} int main(void)

{ initgraph(960, 540); setlinecolor(RGB(255, 0, 0)); 

 cardioid(480, 270, 50);  int ret = getch(); closegraph(); return 0;}

 

Some people may question, how is this the most beautiful code? In fact, the reason for writing this article today is to start from the following, and we will talk about it slowly.

It tells the story of the famous mathematician Descartes we know well. On the streets of Stockholm in 1650, 52-year-old Descartes met the 18-year-old Swedish princess Christine.

 

One day, Christine’s carriage was passing by and found that Descartes was studying mathematics. The princess got out of the car and asked. In the end, Descartes discovered that the princess was talented in mathematics. A few days after the farewell, Descartes received a notice that the king asked him to be Princess Christine’s math teacher.

In the following years, Descartes, who was 34 years old, fell in love with Christine, and the king discovered and executed Descartes. In the last love letter written by Descartes to Christine, the mathematical coordinate equation of r=a(1-sinθ) appeared,

The solution is a heart-shaped pattern, which is the famous "heart-shaped line". Those who have learned a lot should understand this. This love letter was finally included in the European Descartes Museum. The story is romantic and tragic, which is amazing.

If you encounter problems in the process of learning C/C++, you can join the editor’s penguin circle and ask the editor~ I am very enthusiastic (●'◡'●)

 

And what we are talking about is this famous "heart-shaped line":

A heart-shaped line is a track formed by a fixed point on a circle when it rolls around another circle that is tangent to it and has the same radius. It is named after its shape like a heart. The following is an animated drawing of the heart-shaped line:

By now everyone should understand that the above C code is used to draw the "heart-shaped line" of r=a(1-sinθ), which is different from the love patterns obtained by many printf on the Internet.

Those shapes are more random, and the "heart-shaped line" has strict geometric requirements, so it is relatively complicated. Graphical programming and mathematical library functions are used. This is the origin of the C code at the beginning .

Of course, the beauty we are talking about here is the story behind the code, not the code itself, because we have always said that deep-level beauty is true beauty, and we have always believed that true beauty must come from the inner life of life, just like Like Descartes’ romantic and tragic love story, what do you think?

Guess you like

Origin blog.csdn.net/weixin_45713725/article/details/112757118