|
一条编程语句生成图片
[mw_shl_code=cpp,true]#include <graphics.h>
#include <math.h>
#define PI 3.1415926
void main()
{
int radius,x,y;
float i;
int GraphDriver=DETECT,GraphMode;
initgraph(&GraphDriver,&GraphMode,"");
cleardevice();
setcolor(WHITE);
/*以上语句为图形初始化及清屏语句*/
/*下面一句即是(呵呵,别说不是一条语句噢) ;) */
for (radius=30;radius<=150;radius+=20)
for (i=0;i<=PI*2;i+=PI/8)
circle(sin(i)*radius+300,cos(i)*radius+210,60);
/*下面是用户按任意键退出及关闭图形模式*/
getch();
closegraph();
}[/mw_shl_code]
-------------------------------------------------------------
以下为新版本.
[mw_shl_code=cpp,true]#include <graphics.h>
#include <math.h>
#include <stdlib.h>
#define PI 3.1415926
void main()
{
int radius,circles,colors,j;
float i;
char ch;
int GraphDriver=DETECT,GraphMode;
initgraph(&GraphDriver,&GraphMode,"");
randomize();
for (;;)
{
cleardevice();
colors=random(15)+1;
setcolor(colors);
/*以上语句为图形初始化及清屏语句*/
/*下面一句即是(呵呵,别说不是一条语句噢) ;) */
radius=random(100);
for (circles=30;circles<=150;circles+=20)
for (i=0;i<=PI*2;i+=PI/8)
circle(sin(i)*circles+300,cos(i)*circles+210,radius);
/*下面是用户按任意键退出及关闭图形模式*/
outtextxy(100,450,"Quit(Yes/No)?");
ch=getche();
if (ch=='y' || ch=='Y')
break;
}
closegraph();
}[/mw_shl_code] |
|