- #include<dos.h>
- #include<stdio.h>
- #include<iostream.h>
- #include<graphics.h>
- #include<conio.h>
- int a[150],b[150],m,n=0,j,d; float bx[5000],by[5000],u; union REGS i,o;
- initmouse()
- {
- i.x.ax=0; int86(0x33,&i,&o); return(o.x.ax);
- }
- void showmouseptr()
- {
- i.x.ax=1; int86(0x33,&i,&o);
- }
- void getmousepos(int *button,int *x,int *y)
- {
- i.x.ax=3; int86(0x33,&i,&o);
- *button=o.x.bx;
- *x=o.x.cx;
- *y=o.x.dx; i.h.ah=0x02; i.h.dh=0;
- i.h.dl=0; int86(0x10,&i,&o); cout<<"X: "<<*x<<" Y: "<<*y; i.h.ah=0x02; int86(0x10,&i,&o);
- }
- void hidemouseptr()
- {
- i.x.ax=2; int86(0x33,&i,&o);
- }
- int compco()
- {
- int k,coeff=1;
- for(k=d+1;k<=n;k++) coeff=coeff*k; for(k=2;k<=n-d;k++) coeff=coeff/k; return coeff;
- }
- float blenval()
- {
- int k;
- float blend; blend=compco();
- for(k=1;k<=d;k++) blend=blend*u; for(k=1;k<=n-d;k++) blend=blend*(1.0-u); return blend;
- }
- void bezier()
- {
- float blend1;
- bx[j]=0;by[j]=0; for(d=0;d<=n;d++)
- {
- blend1=blenval(); bx[j]+=a[d]*blend1; by[j]+=b[d]*blend1;
- }
- }
- void curve()
- {
- for(j=0;j<m;j++) putpixel(bx[j],by[j],GREEN);
- }
- void drawi()
- {
- for(j=0;j<=m;j++)
- {
- u=(float)j/m; bezier();
- }
- curve();
- }
- void main()
- {
- int gd=DETECT,gm; int button,tx,ty; clrscr(); m=4990;
- flushall(); initgraph(&gd,&gm,"c:\\tc\\bgi"); cleardevice();
- showmouseptr(); while(!kbhit())
- {
- getmousepos(&button,&tx,&ty); if((button & 1) == 1)
- {
- hidemouseptr(); setcolor(WHITE); a[n]=tx;
- b[n]=ty; putpixel(tx,ty,WHITE); circle(tx,ty,2);
- n++;
- delay(50); showmouseptr();
- }
- }
- n--;
- drawi();
- getch();
- }
Output:

No comments:
Post a Comment