...画一三叶玫瑰线,使一个小五角星在曲线上移动。 ρ=asin3θ...

发布网友 发布时间:2024-10-24 02:38

我来回答

2个回答

热心网友 时间:3分钟前

TurboC 红色五角星沿五彩三叶玫瑰线运动
左键逆时针,右键顺时针,回车键结束

#include <math.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>

void drawstar(int x, int y, int c, int r, int color);
void draw3(int x, int y, int r, int color);
void draw30(int color);

int count = 0;
int posx[3500], posy[3500];

int main()
{
int GraphDriver;
int GraphMode;
int arg = 0;
int a, b;
int step = 5;
GraphDriver = DETECT;
initgraph(&GraphDriver, &GraphMode, "");

draw3(300, 200, 300, 12);
drawstar(posx[0], posy[0], 0, 15, 12);

while(1)
{
while(kbhit())
{
a = getch();
if (a == 13)
{
closegraph();
return 0;
}
if (a == 0)
{
b = getch();
if (b == 75)/*Left*/
{
drawstar(posx[arg], posy[arg], 0, 15, 0);
arg -= step;
if (arg < 0)
arg = count - 1;
draw30(12);
drawstar(posx[arg], posy[arg], 0, 15, 12);
}
if (b == 77)/*Right*/
{
drawstar(posx[arg], posy[arg], 0, 15, 0);
arg += step;
if (arg > count - 1)
arg = 0;
draw30(12);
drawstar(posx[arg], posy[arg], 0, 15, 12);
}
}
}
}

}

void drawstar(int x, int y, int c, int r, int color)
{
float x1, y1;
float x2, y2;
float x3, y3;
float x4, y4;
float x5, y5;
const double pi = atan(1) * 4 / 180;
const double pic = pi * c;

setcolor(color);

x1 = x + r * cos(pi * 90 - pic);
y1 = y - r * sin(pi * 90 - pic);
x2 = x + r * cos(pi * 18 - pic);
y2 = y - r * sin(pi * 18 - pic);
x3 = x + r * cos(pi * 54 + pic);
y3 = y + r * sin(pi * 54 + pic);
x4 = x - r * cos(pi * 54 - pic);
y4 = y + r * sin(pi * 54 - pic);
x5 = x - r * cos(pi * 18 + pic);
y5 = y - r * sin(pi * 18 + pic);

moveto(x1, y1);
lineto(x3, y3);
lineto(x5, y5);
lineto(x2, y2);
lineto(x4, y4);
lineto(x1, y1);
}

void draw3(int x, int y, int r, int color)
{
const double p = 3.14159265;
float r0, t;
float px, py;
r /= 2;
r -= 20;
for(t = 0; t <= p; t += 0.003)
{
r0 = r * cos(3 * t);
px = r0 * cos(t) + x;
py = r0 * sin(t) + y;
putpixel(px, py, count % 15);
posx[count] = px;
posy[count] = py;
count++;
}
}

void draw30(int color)
{
int i;
for (i = 0; i < count; i++)
putpixel(posx[i], posy[i], i % 15);
}

热心网友 时间:8分钟前

http://zhidao.baidu.com/question/101463936.html
以后有问题可以先到网上搜索一下,若搜索不到或对搜索的结果有疑问再来提问,我认为会更好。
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com