Simple Fan Program in C Using Graphics (C Graphics की सहायता से Simple Fan प्रोग्राम)

This C graphics program creates a simple animated fan. The fan blades rotate continuously using graphics functions and mathematical calculations.

यह C Graphics प्रोग्राम एक साधारण घूमता हुआ पंखा बनाता है। Graphics Functions और Mathematical Calculations की सहायता से पंखे की Blades लगातार घूमती रहती हैं।

C Program

#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <dos.h>
#define PI 3.14159265
void fan(int p);
int main()
{
int gd = DETECT, gm = 0;
initgraph(&gd, &gm, "");
fan(100);
closegraph();
return 0;
}
void fan(int p)
{
int xf = 250, yf = 250;
int i;
float angle;
int x1, y1, x2, y2;
while (!kbhit())
{
cleardevice();
/* Fan center */
circle(xf, yf, 25);
circle(xf, yf, 3);
/* Fan stand */
line(xf, yf + 25, xf, yf + 100);
line(xf - 40, yf + 100, xf + 40, yf + 100);
/* Rotating blades */
for (i = 0; i < 3; i++)
{
angle = (i * 120) * PI / 180;
x1 = xf + 25 * cos(angle);
y1 = yf + 25 * sin(angle);
x2 = xf + 130 * cos(angle);
y2 = yf + 130 * sin(angle);
line(x1, y1, x2, y2);
}
delay(p);
}
}

Output (आउटपुट)

A fan with three blades appears on the graphics screen. The blades rotate continuously around the center.

Graphics Screen पर तीन Blades वाला पंखा दिखाई देता है। उसकी Blades केंद्र के चारों ओर लगातार घूमती रहती हैं।

Explanation (व्याख्या)

1. Graphics Initialization (Graphics शुरू करना)

initgraph(&gd, &gm, "");

This function initializes the graphics mode.

यह Function Graphics Mode को शुरू करता है।

2. Drawing the Fan (पंखा बनाना)

circle(xf, yf, 25);
line(xf, yf + 25, xf, yf + 100);

The circle represents the fan's center, and the line represents its stand.

Circle पंखे का केंद्र दर्शाता है और Line उसका Stand बनाती है।

3. Rotating the Blades (Blades को घुमाना)

angle = (i * 120) * PI / 180;
x2 = xf + 130 * cos(angle);
y2 = yf + 130 * sin(angle);

The sin() and cos() functions calculate the blade positions at different angles.

sin() और cos() Functions अलग-अलग Angles पर Blades की Position निकालते हैं।

4. Animation (Animation)

cleardevice();
delay(p);

The screen is cleared and redrawn repeatedly to create the rotating effect.

घूमने का Effect बनाने के लिए Screen को बार-बार Clear करके Fan को दोबारा Draw किया जाता है।

Press any key to stop the animation.

Animation रोकने के लिए कोई भी Key Press करें।

This program demonstrates basic computer graphics, mathematical functions, and animation in C.

यह प्रोग्राम C में Computer Graphics, Mathematical Functions और Animation की Basic जानकारी देता है।

Comments

Popular posts from this blog

C Language Topics in Hindi and English

Complete C Programming Syllabus | Advanced C Roadmap for Students

Top High-Paying Tech Skills to Learn in 2025