C and C++ Computer Graphics

program for windmill rotation

program for windmill rotation
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <dos.h>

#define PI 3.1416

int main() {
int gd = DETECT, gm;
int xc = 320, yc = 240; // center of rotation (windmill hub)
int length = 100; // blade length
float angle = 0; // rotation angle

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

while (!kbhit()) { // loop until key pressed
cleardevice();

// Draw tower
setcolor(WHITE);
line(xc, yc, xc, getmaxy()); // vertical stick
line(xc-30, getmaxy(), xc+30, getmaxy()); // base

// Draw hub (center circle)
setfillstyle(SOLID_FILL, RED);
fillellipse(xc, yc, 10, 10);

// Draw 3 blades rotated by 120 degrees
for (int i = 0; i < 3; i++) {
float theta = angle + i * (2 * PI / 3); // 120° apart
int x2 = xc + length * cos(theta);
int y2 = yc + length * sin(theta);
line(xc, yc, x2, y2);
}

delay(80); // control speed
angle += 0.1; // increment angle for rotation
}

closegraph();
return 0;
}

Leave a comment

Your email address will not be published. Required fields are marked *