-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_Bezier.cpp
More file actions
90 lines (75 loc) · 2.12 KB
/
Copy path10_Bezier.cpp
File metadata and controls
90 lines (75 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// Created by piyush on 4/2/19.
//
#include <graphics.h>
#include<bits/stdc++.h>
using namespace std;
#define callInitgraph int gd=DETECT,gm; initgraph(&gd,&gm,NULL);
void bezier(int x[],int y[])
{
double t;
callInitgraph;
//bezier curve for flower
for(t=0.0;t<1.0;t=t+0.005)
{
double xt = pow(1-t,3)*x[0]+3*t*pow((1-t),2)*x[1]+3*pow(t,2)*(1-t)*x[2]+pow(t,3)*x[3];
double yt = pow(1-t,3)*y[0]+3*t*pow((1-t),2)*y[1]+3*pow(t,2)*(1-t)*y[2]+pow(t,3)*y[3];
putpixel(xt,yt,5);
}
delay(50);
}
void bezier1(int x[],int y[])
{
//simple bezier curve
double t;
callInitgraph;
for(t=0.0;t<1.0;t=t+0.005)
{
double xt = pow(1-t,2)*x[0]+2*t*pow((1-t),1)*x[1]+1*pow(t,2)*x[2];
double yt = pow(1-t,2)*y[0]+2*t*pow((1-t),1)*y[1]+1*pow(t,2)*y[2];
putpixel(xt,yt,5);
delay(50);
}
getch();
closegraph();
}
int main()
{
int a;
cout<<"\nENTER \n1.BEZIER CURVE\n2.FLOWER\nENTER YOUR CHOICE::";
cin>>a;
switch(a)
{
case 1:
int x5[3],y5[3];
x5[0] = 190, x5[1] = 220, x5[2] = 250;
y5[0] = 50, y5[1] = 90, y5[2] = 50;
bezier1(x5,y5);
break;
case 2:
int x1[4],y1[4];
int x2[4],y2[4];
int x3[4],y3[4];
int x4[4],y4[4];
cout<<"Enter four coordinates";
x1[0]=200, x1[1]=160, x1[2]=240, x1[3]=200;
y1[0]=200, y1[1]=160, y1[2]=160, y1[3]=200;
x2[0]=200, x2[1]=240, x2[2]=240, x2[3]=200;
y2[0]=200, y2[1]=160, y2[2]=240, y2[3]=200;
x3[0]=200, x3[1]=240, x3[2]=160, x3[3]=200;
y3[0]=200, y3[1]=240, y3[2]=240, y3[3]=200;
x4[0]=200, x4[1]=160, x4[2]=160, x4[3]=200;
y4[0]=200, y4[1]=240, y4[2]=160, y4[3]=200;
//call for four petals
bezier(x1,y1);
bezier(x2,y2);
bezier(x3,y3);
bezier(x4,y4);
//line for as a stem
line(200,230,200,300);
delay(10000);
getch();
closegraph();
break;
}
}