Skip to content

Commit ea8da71

Browse files
authoredMay 27, 2018
curve bezier
mouse pointer enabled curve drawing
1 parent e8853e7 commit ea8da71

File tree

1 file changed

+161
-0
lines changed

1 file changed

+161
-0
lines changed
 

‎CURVEC.C

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#include <stdio.h>
2+
#include<graphics.h>
3+
#include<conio.h>
4+
#include<dos.h>
5+
#include<math.h>
6+
#define RED 14
7+
union REGS in,out;
8+
9+
10+
void initmouse(){
11+
in.x.ax=1;
12+
int86(0x33,&in,&out);
13+
}
14+
int x,y,a[2],x1,y1,x2,y2;
15+
double xt,yt;
16+
17+
void location(){
18+
19+
a[0]=0;
20+
a[1]=0;
21+
while(!kbhit()) {
22+
in.x.ax=3;
23+
int86(0x33,&in,&out);
24+
25+
if(out.x.bx==1){
26+
27+
x=out.x.cx;
28+
y=out.x.dx;
29+
30+
31+
break;
32+
} }
33+
34+
while(!kbhit()){
35+
in.x.ax=3;
36+
int86(0x33,&in,&out);
37+
38+
if(out.x.bx==1){
39+
a[0]=out.x.cx;
40+
a[1]=out.x.dx;
41+
42+
cleardevice();
43+
44+
line(x,y,a[0],a[1]); }
45+
if(out.x.bx==2){
46+
break;
47+
}
48+
49+
} // return a;
50+
}
51+
52+
53+
54+
void blend(){
55+
56+
double t;
57+
while(!kbhit()){
58+
59+
in.x.ax=3;
60+
int86(0x33,&in,&out);
61+
62+
63+
if(out.x.bx==2){
64+
x1=out.x.cx;
65+
y1=out.x.dx;
66+
cleardevice();
67+
line(x1,y1,x2,y2);
68+
69+
70+
putpixel(x1+1,y1,RED);
71+
putpixel(x1,y1+1,RED);
72+
putpixel(x1-1,y1,RED);
73+
putpixel(x1,y1-1,RED);
74+
putpixel(x2+1,y2,RED);
75+
putpixel(x2,y2+1,RED);
76+
putpixel(x2-1,y2,RED);
77+
putpixel(x2,y2-1,RED);
78+
putpixel(x1+2,y1,RED);
79+
putpixel(x1,y1+2,RED);
80+
putpixel(x1-2,y1,RED);
81+
putpixel(x1,y1-2,RED);
82+
putpixel(x2+2,y2,RED);
83+
putpixel(x2,y2+2,RED);
84+
putpixel(x2-2,y2,RED);
85+
putpixel(x2,y2-2,RED);
86+
87+
88+
for( t=0.0;t<1.0;t=t+0.001){
89+
90+
xt=(pow(1-t,3)*x+3*t*pow(1-t,2)*x2+3*pow(1-t,1)*pow(t,2)*x1+pow(t,3)*a[0]);
91+
yt=(pow(1-t,3)*y+3*t*pow(1-t,2)*y2+3*pow(1-t,1)*pow(t,2)*y1+pow(t,3)*a[1]);
92+
93+
94+
putpixel(xt,yt,WHITE);
95+
96+
97+
98+
}
99+
100+
101+
102+
}
103+
if(out.x.bx==1){
104+
x2=out.x.cx;
105+
y2=out.x.dx;
106+
cleardevice();
107+
line(x1,y1,x2,y2);
108+
109+
110+
putpixel(x1+1,y1,RED);
111+
putpixel(x1,y1+1,RED);
112+
putpixel(x1-1,y1,RED);
113+
putpixel(x1,y1-1,RED);
114+
putpixel(x2+1,y2,RED);
115+
putpixel(x2,y2+1,RED);
116+
putpixel(x2-1,y2,RED);
117+
putpixel(x2,y2-1,RED);
118+
putpixel(x1+2,y1,RED);
119+
putpixel(x1,y1+2,RED);
120+
putpixel(x1-2,y1,RED);
121+
putpixel(x1,y1-2,RED);
122+
putpixel(x2+2,y2,RED);
123+
putpixel(x2,y2+2,RED);
124+
putpixel(x2-2,y2,RED);
125+
putpixel(x2,y2-2,RED);
126+
for( t=0.0;t<1.0;t=t+0.001){
127+
128+
xt=(pow(1-t,3)*x+3*t*pow(1-t,2)*x2+3*pow(1-t,1)*pow(t,2)*x1+pow(t,3)*a[0]);
129+
yt=(pow(1-t,3)*y+3*t*pow(1-t,2)*y2+3*pow(1-t,1)*pow(t,2)*y1+pow(t,3)*a[1]);
130+
131+
putpixel(xt,yt,WHITE);
132+
133+
}
134+
135+
}
136+
137+
138+
139+
140+
141+
}
142+
143+
}
144+
void main(){
145+
146+
147+
int gd=DETECT,gm;
148+
a[1]=0;
149+
a[0]=0;
150+
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
151+
// line(10,10,50,100);
152+
initmouse();
153+
location();
154+
// printf("%d , %d",a[0],a[1]);
155+
156+
blend();
157+
158+
159+
160+
getch();
161+
}

1 commit comments

Comments
 (1)

Pratap2018 commented on Jun 25, 2018

@Pratap2018
OwnerAuthor

This is an implementation of curve...that we see in Microsoft paint...

Please sign in to comment.