这个c程序的椭圆不能旋转请高手帮兄弟看一下吧!!!先谢谢了 !!
#include <math.h>#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
void drawb(int x, int y, float a, float b, float c, int color);
int main()
{
int GraphDriver;
int GraphMode;
float arg = 0;
int x, y;
float a, b;
int keya, keyb;
int step = 30;
printf("input x: ");
scanf("%d", &x);
printf("input y: ");
scanf("%d", &y);
printf("input a: ");
scanf("%f", &a);
printf("input b: ");
scanf("%f", &b);
GraphDriver = DETECT;
initgraph(&GraphDriver, &GraphMode, "");
drawb(x, y, a, b, arg, 12);
while(1)
{
while(kbhit())
{
keya = getch();
if (keya == 13)
closegraph();
return 0;
}
if (keya == 0)
{
keyb = getch();
if (keyb == 75)/*Left*/
{
drawb(x, y, a, b, arg, 0);
arg -= step;
if (arg < 0)
arg += 360;
drawb(x, y, a, b, arg, 12);
}
else if (keyb == 77)/*Right*/
{
drawb(x, y, a, b, arg, 0);
arg += step;
if (arg > 360)
arg -= 360;
drawb(x, y, a, b, arg, 12);
}
}
}
}
void drawb(int x, int y, float a, float b, float c, int color)
{
double tempx, tempy;
double x1, y1;
double t;
c = atan(1) / 45 * c;
for (t = -3.1415926535; t <= 3.1415926535; t += 0.003)
{
tempx = cos(t) * a;
tempy = sin(t) * b;
x1 = x + tempx * cos(c) - tempy * sin(c);
y1 = y + tempx * sin(c) + tempy * cos(c);
putpixel(x1, y1, color);
}
}