-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.cpp
More file actions
94 lines (90 loc) · 1.31 KB
/
Copy pathcode.cpp
File metadata and controls
94 lines (90 loc) · 1.31 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
89
90
91
92
93
94
# triangle
to rotate about the origin & a fixed point
#include "stdafx.h"
#include<stdio.h>
#include<math.h>
#include<GL/glut.h>
int xs,ys,xe,ye;
void myInit()
{
glClearColor(1.0,1.0,1.0,1.0);
gluOrtho2D(0,500,0,500);
}
void draw_pixel(int x,int y)
{
glColor3f(1.0,0.0,0.0);
glPointSize(2.0);
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
}
void bresenhams_line_draw(int x1,int y1,int x2,int y2)
{
int dx,dy,i,p;
int incx=1,incy=1;
int x,y;
dx=abs(x2-x1);
dy=abs(y2-y1);
if(x2<x1)
{
incx=-1;
}
if(y2<y1)
{
incy=-1;
}
x=x1;
y=y1;
if(dx>dy)
{
draw_pixel(x,y);
p=2*dy-dx;
for(i=0;i<dx;i++)
{
if(p>=0)
{
y+=incy;
p+=2*(dy-dx);
}
else
p+=2*dy;
x+=incx;
draw_pixel(x,y);
}
}
else{
draw_pixel(x,y);
p=2*dx-dy;
for(i=0;i<dy;i++)
{
if(p>=0)
{
x+=incx;
p+=2*(dx-dy);
}
else
p+=2*dx;
y+=incy;
draw_pixel(x,y);
}
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
bresenhams_line_draw(xs,ys,xe,ye);
glFlush();
}
void main()
{
printf("enter the start point(x1,y1)\n");
scanf("%d%d",&xs,&ys);
printf("enter the end points(x2,y2)\n");
scanf("%d%d",&xe,&ye);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(500,500);
glutCreateWindow("Bresenhams line drawing");
myInit();
glutDisplayFunc(display);
glutMainLoop();
}