-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path12. bezier curve.txt
executable file
·66 lines (59 loc) · 1.23 KB
/
12. bezier curve.txt
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
#include <Windows.h>
#include <GL\glew.h>
#include <GL\freeglut.h>
#include <iostream>
#include<stdio.h>
int x1, x2, x3, y11, y2, y3;
void myInit()
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0, 500, 0, 500);
}
void draw_pixel(int x, int y)
{
glBegin(GL_POINTS);
glColor3f (1.0, 1.0, 1.0);
glVertex2i(x, y);
glEnd();
}
void draw_gray(int x, int y)
{
glBegin(GL_POINTS);
glColor3f (0.5, 0.5, 0.5);
glVertex2i(x, y);
glEnd();
}
void draw_curve()
{
double u,x,y;
draw_pixel(x1,y11);
draw_pixel(x3,y3);
for (u=0.01;u<1;u=u+0.01)
{
x=(1-u)*(1-u)*x1+2*(1-u)*u*x2+u*u*x3;
y=(1-u)*(1-u)*y11+2*(1-u)*u*y2+u*u*y3;
draw_pixel(x,y);
}
}
void myDisplay()
{
//draw_line(0,500,250,250);
//draw_line(250,250,0,500);
draw_curve();
glFlush();
}
void main(int argc, char **argv)
{
printf( "Enter (x1, y1, x2, y2, x3, y3)\n");
scanf(" %d %d %d %d %d %d", &x1, &y11, &x2, &y2, &x3, &y3);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("Bezier Curve Drawing");
myInit();
glutDisplayFunc(myDisplay);
glutMainLoop();
}