Posts

Showing posts with the label graphics program

C Graphics Program For Boundary Fill in C

Image
C Graphics Program For Boundary Fill in C Source Code:- 1:  //Program to implement Boundary Fill Algorithm   2:  #include <graphics.h>   3:  #include <stdlib.h>   4:  #include <stdio.h>   5:  #include <conio.h>   6:  #include "grplib.h"   7:  int bfill(int x,int y,int f,int b)   8:       {   9:       if(getpixel(x,y) !=b && getpixel(x,y)!=f)   10:            {   11:            putpixel(x,y,f);   12:            bfill(x+1,y,f,b);   13:            bfill(x-1,y,f,b);   14:            bfill(x,y+1,f,b);   15:            bfill(x,y-1,f,b);   16:            }   17:       r...

C Graphics Program For 3D Transformation

Image
C Graphics Program For 3D Transformation Source Code:- 1:  //Program to implement 3D Transformation   2:  #include<math.h> 3:  #include<stdio.h> 4:  #include<process.h> 5:  #include<iostream.h> 6:  #include<conio.h> 7:  #include<graphics.h> 8:  #include "grplib.h" 9:  #define X 0 10:  #define Y 1 11:  int getx(float mat[4][1]) 12:       { 13:       return ceil(mat[0][0]); 14:       } 15:  int gety(float mat[4][1]) 16:       { 17:       return ceil(mat[1][0]); 18:       } 19:  int getz(float mat[4][1]) 20:       { 21:       return ceil(mat[2][0]); 22:       } 23:  void create_mat_pnt(float mat[4][1],int x,int y,int z) 24:       { 25:       mat[0][0]=x; 26:      ...

C Graphics Program For 2 D Transformation

Image
C Graphics Program For 2 D Transformation Source Code:- 1:  //Program to implement 2D Transformation   2:  #include<math.h> 3:  #include<stdio.h> 4:  #include<process.h> 5:  #include<iostream.h> 6:  #include<conio.h> 7:  #include<graphics.h> 8:  #include "grplib.h" 9:  #define X 0 10:  #define Y 1 11:  int getx(float mat[3][1]) 12:       { 13:       return ceil(mat[0][0]); 14:       } 15:  int gety(float mat[3][1]) 16:       { 17:       return ceil(mat[1][0]); 18:       } 19:  void create_mat_pnt(float mat[3][1],int x,int y) 20:       { 21:       mat[0][0]=x; 22:       mat[1][0]=y; 23:       mat[2][0]=1; 24:       } 25:  void create_mat_tran(float mat[3][3],int tx,int ty) 26...

polygon program for graphics

#include #include #include #include #include void line(int xa,int ya,int xb,int yb) { int dx,dy,s,k; float xi,yi,x,y; int gd=DETECT,gm; initgraph(&gd,&gm, ""); dx=xb-xa; dy=yb-ya; if(abs(dx)>abs(dy)) s=abs(dx); else s=abs(dy); xi=dx/s; yi=dy/s; x=xa; y=ya; putpixel(ceil(x),ceil(y),1); for(k=0;k { x=x+xi; y=y+yi; putpixel(ceil(x),ceil(y),1); } } void main() { int v[10][2]; int x,y,n,i,x1,y1,x2,y2; printf("ENTER THE NO OF EDGES"); scanf("%d",&n); printf("ENTER THE VERTICES"); for(i=0;i { scanf("%d",&v[i][0]); scanf("%d",&v[i][1]); } for(i=0;i { if(i!=n-1) { x1=v[i][0]; y1=v[i][1]; x2=v[i+1][0]; y2=v[i+1][1]; } else { x1=v[i][0]; y1=v[i][1]; x2=v[0][0]; y2=v[0][1]; } line(x1,y1,x2,y2); } getch(); }

line clipping program

#include #include #include #include struct wind { int xmin,ymin; int xmax,ymax; }; struct point { int x,y; char code[5]; }; void gencode(struct wind w,struct point p) { if(p.x p.code[0]='1'; else p.code[0]='0'; if(p.x>w.xmax) p.code[1]='1'; else p.code[1]='0'; if(p.y p.code[2]='1'; else p.code[2]='0'; if(p.y>w.ymax) p.code[3]='1'; else p.code[3]='0'; } struct point clipline(struct wind w,struct point p,struct point pt) { int i,flag=0; float m=(p.y-pt.y)/(p.x-pt.x); gencode(w,p); while(!flag) { flag=1; if(p.code[0] == '1') { p.y+=(w.xmin-p.x)*m; p.x=w.xmin; gencode(w,p); flag=0; } else if(p.code[1] == '1') { p.y+=(w.xmax-p.x)*m; p.x=w.xmax; gencode(w,p); flag=0; } else if(p.code[2] == '1') { p.x+=(w.ymin-p.y)/m; p.y=w.ymin; gencode(w,p); flag=0; } else if(p.code[3] == '1') { p.x+=(w.ymax-p.y)...