Posts

Showing posts from April, 2021

Functions in Graphics

Image
 • There are many built-in functions in Turbo c (BGI) Borland Graphics Interface is a graphics library that supports graphics in Turbo C. • Note: This function is only supportable in Turbo c (BGI compliers is only available in turbo c. • There are total 50 built-in functions available for use, we will discuss it one by one. • Note: A short discription, Example and a program for each function. • So let's start with Basic one: 1) initgraph(&gd, &gm," path of bgi")   => This function is used to initialize terminal default mode i.e. text mode into graphic mode. => Parameter:  1) The address of gd. 2) address of gm. 3) path of BGI files. * gd is graphic driver(instruction) which is initialised to DETECT which is a macro define in "graphic.h" header file. * gm is graphic mode. * Path where your BGI files are present (you have to adjust this accordingly where you Turbo C compiler is installed). 🎨Program Link: 👇 https://github.com/Rinky6767/Computer-Grap

Bresenham's Line Drawing Algorithm

Image
 • Bresenham's line drawing algorithm came into existence because DDA line drawing algorithm use to give more of decimal (floating) point numbers.  • Which were round off to integer data type (int) because decimal number cannot be plotted on the screen. •Due to rounding off the coordinate the output of line would be more in zig-zag form. Explanation: 1) Consider      •dA= Above the line point.     •dB= Below the line point. 2) so point can be above or below the line. 3) In this algorithm we will make a precise decision regarding the point above or below  4) let decision variable be e      • e= dB - dA  5) Where  if:      e<0      when        :     dB<dA     Because: It will be below the point of line.          •  if:          e>0  When    :         dB>=dA.    Because: Above the point of line. Algorithm: 1) Start 2) Find slope of line i.e m,        m= y2-y1/x2-x1. 3) Find decisions variable e,            e0= 2dy - dx. 4) To Find dy and dx,             dy= y2-y1         

DDA - Digital Differential Analyzer

Image
  • DDA stands for Digital Differential Analyzer. • getpixel and putpixel are two functions which we will use everytime in our program. • Declarations: 1) int getpixel(int x, int y); 2) void putpixel(int x, int y, int color); • Function getpixel returns the integer value  of the pixel color present at point(x, y). • Function putpixel plots a pixel at a point(x, y) of the specified color. • Steps :  1) slope of line(m): y2-y1/x2-x1  ** m= dy/dx = y2-y1/x2-x1  2) dy= m*dx  3) dx= dy/m  • Above three formulas are very important in order to understand DDA Algorithm. • Algorithm : 1) Start  2) User Input: Coordinate x1, y1 and x2, y2 for line. 3) Find slope m  4) Find dx  5) Find dy  with the help of above formula. 6) Check: dx >=dy if yes,  dx = 1  x1= x1 + dx;  y1 = y1 + m1 * dx; 7) else:      dy1  = 1;  x1   = x1 +(dy1/m1); y1   = y1 + dy1; 8)putpixel(x1,y1,color_name); 9) We will continue the steps from 4 to 8 till x1==x2 and y1==y2 • Example:  If x1 and y1= (1,1)     X2 and y1= (4,3