GithubHelp home page GithubHelp logo

cgv's Introduction

cgv

bresenhams line drawing #include "stdafx.h" #include<GL/glut.h> #include<stdio.h> #include<math.h> int xs,ys,xe,ye;

void init() { 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 bresenham_draw_line(int x1,int x2,int y1,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=2dy-dx; for(i=0;i<dx;i++) { if(P>=0) { y+=incy; P+=2(dy-dx); } else P+=2dy; x+=incx; draw_pixel(x,y); } } else { draw_pixel(x,y); P=2dx-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); bresenham_draw_line(xs,xe,ys,ye); glFlush(); } void main() { printf("enter (x1,y1)\n"); scanf("%d%d",&xs,&ys); printf("enter (x2,y2)\n"); scanf("%d%d",&xe,&ye); glutInitDisplayMode(GLUT_RGB); glutInitWindowSize(500,500); glutCreateWindow("bresenhams line drawing"); init(); glutDisplayFunc(display); glutMainLoop(); }

cgv's People

Contributors

deekshithas avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.