📄 imageimportant.c
字号:
/* WIN-TC BGI 图形编程模板 */
#include "Conio.h"
#include "graphics.h"
#include "stdio.h"
#include "math.h"
#define PI 3.14159265
#define closegr closegraph
double sin(),cos();
double xmax=639.0;
double ymax=479.0;
double f[3][3];
double xx,yy;
scx(xj)
double xj;
{
int x;
x=(int)(xj+xmax/2);
return(x);
}
scy(yj)
double yj;
{
int y;
y=ymax-(int)(yj+(ymax/2));
return(y);
}
parallel(dx,dy)
double dx,dy;
{
f[0][0]=1.0;f[0][1]=0.0;f[0][2]=0.0;
f[1][0]=0.0;f[1][1]=1.0;f[1][2]=0.0;
f[2][0]=dx;f[2][1]=dy;f[2][2]=1.0;
}
rotate(theta)
double theta;
{
double th;
th=theta/180*3.14159265;
f[0][0]=cos(th);f[0][1]=sin(th);f[0][2]=0.0;
f[1][0]=-sin(th);f[1][1]=cos(th);f[1][2]=0.0;
f[2][0]=0;f[2][1]=0;f[2][2]=1.0;
}
scale(s)
double s;
{
f[0][0]=s;f[0][1]=0.0;f[0][2]=0.0;
f[1][0]=0.0;f[1][1]=s;f[1][2]=0.0;
f[2][0]=0;f[2][1]=0;f[2][2]=1.0;
}
taisho_x()
{
f[0][0]=1.0;f[0][1]=0.0;f[0][2]=0.0;
f[1][0]=0.0;f[1][1]=-1.0;f[1][2]=0.0;
f[2][0]=0;f[2][1]=0;f[2][2]=1.0;
}
taisho_y()
{
f[0][0]=-1.0;f[0][1]=0.0;f[0][2]=0.0;
f[1][0]=0.0;f[1][1]=1.0;f[1][2]=0.0;
f[2][0]=0;f[2][1]=0;f[2][2]=1.0;
}
taisho_0()
{
f[0][0]=-1.0;f[0][1]=0.0;f[0][2]=0.0;
f[1][0]=0.0;f[1][1]=-1.0;f[1][2]=0.0;
f[2][0]=0;f[2][1]=0;f[2][2]=1.0;
}
taisho_xy()
{
f[0][0]=0.0;f[0][1]=1.0;f[0][2]=0.0;
f[1][0]=1.0;f[1][1]=0.0;f[1][2]=0.0;
f[2][0]=0;f[2][1]=0;f[2][2]=1.0;
}
taisho(aa,bb,cc)
float aa,bb,cc;
{
float r,p;
r=bb*bb-aa*aa;
p=aa*aa+bb*bb;
f[0][0]=-r/p;f[0][1]=-2*aa*bb/p;f[0][2]=0.0;
f[1][0]=-2*aa*bb/p;f[1][1]=-r/p;f[1][2]=0.0;
f[2][0]=-2*aa*cc/p;f[2][1]=-2*bb*cc/p;f[2][2]=1.0;
}
axis()
{
line(scx(0),scy(-ymax/2),scx(0),scy(ymax/2));
line(scx(-xmax/2),scy(0.0),scx(xmax/2),scy(0.0));
}
tuoq(a,b)
double a,b;
{
f[0][0]=1.0;f[0][1]=b;f[0][2]=1.0;
f[1][0]=a;f[1][1]=1.0;f[1][2]=0.0;
f[2][0]=0;f[2][1]=0;f[2][2]=1.0;
}
affinex(x,y,d)
double x,y,d;
{
xx=x*f[0][0]+y*f[1][0]+d*f[2][0];
return(xx);
}
affiney(x,y,d)
double x,y,d;
{
yy=x*f[0][1]+y*f[1][1]+d*f[2][1];
return(yy);
}
void initgr(void) /* BGI初始化 */
{int gd=DETECT,gm=0; /* 和gd=VGA,gm=VGAHI是同样效果 */
registerbgidriver(EGAVGA_driver);/* 注册BGI驱动后可以不需要.BGI文件的支持运行 */
initgraph(&gd,&gm,"");
}
circumrotate()
{
static double x1[]={0.0,10.0,100.0,110.0,0.0};
static double y1[]={0.0,50.0,40.0,10.0,0.0};
static double x2[5];
static double y2[5];
double yy;
int i;
initgr(); /* BGI初始化 */
axis();
for(i=0;i<=3;i++)
{
line(scx(x1[i]),scy(y1[i]),scx(x1[i+1]),scy(y1[i+1]));
}
rotate(120.0);
for(i=0;i<=4;i++)
{
x2[i]=affinex(x1[i],y1[i],1.0);
yy=affiney(x1[i],y1[i],1.0);
y2[i]=yy/2;
}
for(i=0;i<=3;i++)
{
line(scx(x2[i]),scy(y2[i]),scx(x2[i+1]),scy(y2[i+1]));
}
}
parallelmove()
{
static double x1[]={0.0,10.0,100.0,110.0,0.0};
static double y1[]={0.0,50.0,40.0,-10.0,0.0};
static double x2[5];
static double y2[5];
int i;
double x;
double xx,yy;
initgr();
setcolor(2);
axis();
for(x=-300;x<=200;x=x+10)
{
parallel(x,x/2);
for(i=0;i<=4;i++){
x2[i]=affinex(x1[i],y1[i],1.0);
y2[i]=affiney(x1[i],y1[i],1.0);
}
for(i=0;i<=3;i++){
line(scx(x2[i]),scy(y2[i]),scx(x2[i+1]),scy(y2[i+1]));
}
}
}
rotate360()
{
static double x1[]={0.0,10.0,100.0,110.0,0.0};
static double y1[]={0.0,50.0,50.0,0.0,0.0};
static double x2[5];
static double y2[5];
int i;
double r;
double xx,yy;
initgr();
setcolor(2);
axis();
for(r=0;r<=360;r=r+10)
{
rotate(r);
for(i=0;i<=4;i++){
x2[i]=affinex(x1[i],y1[i],1.0);
y2[i]=affiney(x1[i],y1[i],1.0);
}
for(i=0;i<=3;i++){
line(scx(x2[i]),scy(y2[i]),scx(x2[i+1]),scy(y2[i+1]));
}
}
}
scaleflex()
{
static double x1[]={-20.0,0.0,30.0,10.0,-20.0};
static double y1[]={0.0,17.0,-10.0,-20.0,0.0};
static double x2[5];
static double y2[5];
int i;
double s;
double xx,yy;
initgr();
setcolor(2);
axis();
for(s=0;s<=10;s=s+0.5)
{
scale(s);
for(i=0;i<=4;i++){
x2[i]=affinex(x1[i],y1[i],1.0);
y2[i]=affiney(x1[i],y1[i],1.0)/2;
}
for(i=0;i<=3;i++){
line(scx(x2[i]),scy(y2[i]),scx(x2[i+1]),scy(y2[i+1]));
}
}
}
flower()
{
double a1,t,a,x1,y1,x2,y2,px,py;
int x,y,color;
initgr();
setbkcolor(1);
setcolor(15);
t=sqrt(170*170*2.0);
for(px=-170;px<=170;px+=20)
{
a=sqrt(px*px+py*py/t*PI/2+PI/4);
for(a1=0;a1<=2*PI;a1+=PI/2)
{
x1=10*cos(a1);
y1=10*sin(a1);
x2=x1*cos(a)-y1*sin(a);
y2=x1*sin(a)+y1*cos(a);
x=px+320+x2;
y=py+200-y2;
if(a1==0)moveto(x,y);
else lineto(x,y);
}
}
}
flower6b()
{
int color=15,x,y;
float l,m,d,px,py,a,x0,y0,x2,aa;
}
main()
{
circumrotate();
if(getchar()=='\n') {cleardevice();
parallelmove() ; }
if(getchar()=='\n') {cleardevice();
rotate360() ; }
if(getchar()=='\n') {cleardevice();
scaleflex() ; }
if(getchar()=='\n') {cleardevice();
flower() ; }
getch(); /* 暂停一下,看看前面绘图代码的运行结果 */
closegr(); /* 恢复TEXT屏幕模式 */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -