北京历届高考状元名单:C语言问题!请进!

来源:百度文库 编辑:神马品牌网 时间:2024/05/03 10:04:46
用C语言画分形图 ·····

#include "graphics.h"
#include "stdlib.h"
#include "stdio.h"
#include "fcntl.h"
#include "dos.h"
union REGS r;

struct MOUSE{
int getit;
int x1;
int y1;
int x2;
int y2;
}ms;
void MSB(float,float,float,float,int,int,int,int,int);
void mouse_drop(struct MOUSE *in);
/*定义鼠标拖动的函数,通过鼠标的按下、放开来选定一个矩形区域*/
int data_processor(struct MOUSE m,float *x0,float *x1,float *y0,float *y1);
/*将鼠标选定的区域转化成MSB集的区域*/

void mouse_IQR(int *num,int *bx,int *cx,int *dx)
{/*调用鼠标的中断,在这里定义函数让下面一些函数调用,以减少编程的重复,
在这里,通过int86函数(在dos.h里)调用中断,鼠标的中断号为:33h */
r.x.ax=*num;
r.x.bx=*bx;
r.x.cx=*cx;
r.x.dx=*dx;
int86(0x33,&r,&r);
*bx=r.x.bx;
*cx=r.x.cx;
*dx=r.x.dx;
*num=r.x.ax;
}

int init_mouse()
{
/*初试化鼠标,查询鼠标驱动有没有安装,功能号为 0 */
int num=0;
mouse_IQR(&num,&num,&num,&num);
if(num!=-1)
return 1;
else return 0;
}

void mouse_show();
void mouse_position(int *x,int *y)
{/*鼠标在屏幕中所处的位置*/
int button=0,num=3;
mouse_show();
mouse_IQR(&num,&button,x,y);
}

void mouse_hide()
{/*隐藏鼠标光标*/
int num=2;
mouse_IQR(&num,&num,&num,&num);
}

void mouse_show()
{/*显示鼠标光标*/
int num=1;
mouse_IQR(&num,&num,&num,&num);
}

int mouse_click(int k)
{/*查询鼠标是使用左键(返回1)还是右键(返回2)*/
int bx=0,num=3;
mouse_IQR(&num,&bx,&num,&num);
return(bx&k);
}

void waiton(int buttom)
{/*等待鼠标动作*/
if(buttom==1)
while(mouse_click(1));
if(buttom==2)
while(mouse_click(2));
}

int mousexy(int x1,int y1,int x2,int y2)
{/*查询鼠标是否在区域内*/
int x,y;
mouse_position(&x,&y);
if(x>x1&&xy1&&yL||m<-1e10) break;
x=xx;
y=yy;
}
color=n%16;
putpixel(x1+i,y1+j,color);

}
}
}
void mouse_drop(struct MOUSE *in)
{
char out[20];
int x,y;
int oldx,oldy;
struct MOUSE r;
r=*in;
setwritemode(1);
setlinestyle(USERBIT_LINE,0x7777,1);
setcolor(15);
if(r.getit==1)
{
mouse_hide();
rectangle(r.x1,r.y1,r.x2,r.y2);
mouse_show();
}
mouse_position(&x,&y);
r.x1=x;
r.y1=y;
oldx=x;
oldy=y;
r.getit=1;
mouse_hide();
rectangle(x,y,x,y);
mouse_show();
while(mouse_click(1)) {mouse_position(&x,&y);
if(oldx!=x || oldy!=y){
mouse_hide();
rectangle(r.x1,r.y1,x,y);
rectangle(r.x1,r.y1,oldx,oldy);
mouse_show();
oldx=x;
oldy=y;
}
if(mouse_click(2)){
r.getit=0;
mouse_hide();
rectangle(r.x1,r.y1,oldx,oldy);
mouse_show();
waiton(2);
break;}
}
if(r.getit==1){
r.x2=x;
r.y2=y;
if(x==r.x1 && r.y1==y)
r.getit=0;
else
r.getit=1;
}
setlinestyle(SOLID_LINE,0,1);
*in=r;
waiton(1);
setwritemode(0);
setmouse(0,0,getmaxx(),getmaxy());
}

int data_processor(struct MOUSE m,float *x0,
float *x1,float *y0,float *y1)
{
float d1,l1,d2,l2,d,l;
float xx0,xx1,yy0,yy1,x,y;
d1=*x1-*x0;
l1=*y1-*y0;
d2=637;
l2=477;
xx0=m.x1;
xx1=m.x2;
yy0=m.y1;
yy1=m.y2;
if(xx0==xx1 || yy0==yy1) return(0);
if(xx0>xx1)
{x=xx0;
xx0=xx1;
xx1=x;
}
if(yy0>yy1)
{x=yy0;
yy0=yy1;
yy1=x;
}
d=1;
l=1;
x=*x0;
y=*y0;
*x0=x+(xx0-d)*d1/d2;
*x1=x+(xx1-d)*d1/d2;
*y0=y+(yy0-l)*l1/l2;
*y1=y+(yy1-l)*l1/l2;
if(*x0==*x1 || *y0==*y1)
return(0);
else
return(1);
}

不懂再问!

2!+4!+6!+..+16! 自己去想!呵呵