Posts

Functions of graphics

Image
 • First will discuss basic geometric shapes and base on that we will make a simple program where we will have a x and y axis and all the shapes in it. 1) Line Function => line function is used to draw a line by just giving 4 points. syntax:       void line(int x1, int y1, int x2, int y2); Where:          x1 : initial x-coordinate        y1 : intial  y-coordinate        x2 : end x-coordinate        y2 : end y-coordinate Example    : line(100, 100, 200, 200); Explanation : A line would be drawn from point(100, 100) to point(200,200). 2) Rectangle Function => Rectangle function is used to draw a rectangle.  => Rectangle function is same as bar function already discussed in last post, only difference is in bar function we get only 3 lines in output, but in rectangle we get all the four lines. =>Coordinates of left top and right bottom corner are required to draw the rectangle. left specifies the X-coordinate of top left corner, top specifies the Y-coordinate of top left corne

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

Sample programs

Image
 • We are going to discuss some simple programs in turbo C before going to graphics program that is terminal in graphic mode. • So simple programs in text mode. 1) Program to print Hello world on different line. #include<stdio.h> #include<conio.h> int main() {     int c= 5;      for(int i=0;i<12; i=i+2)     {     gotoxy(c,i);     printf("Hello world!");     c=c+2;     } getch(); return 0; } Explanation: • we have also discussed prior about text mode in Turbo C let's understand it in short. • So this is the image representation of text mode where: 1) screen is divided in Rows and Columns. 2) we have 80 rows and 25 columns 3) Here first coordinate is of column and another is row example: (80,25) • 80 is column and 25 is row only in turbo C text mode it's reverse as it is normally. 4)  program we did above is of Controlling the cursor with the help of function gotoxy( )  it's a function used to send the cursor to the specified coordinates in the activ

Basics of Graphics programming

Image
 • We are going to see the basic syntax which must be followed while programming the graphics in turbo C++  1) By default are output screen or the terminal (Black screen were we get the output of programs) is in text mode. 2) So to initialize the terminal in graphic mode(x-axis and y-axis) we use initgraph function in our program. 3) Here the screen resolution is in text mode. X-direction is horizontally across the screen and y-direction is vertically down the screen. The top left corner is (0, 0) and the bottom right corner is (80, 25). While executing the program, Turbo C opens the console in text mode only.                   Terminal in Graphics mode  4) In text mode the screen is divided into 80 columns and 25 rows. In case of graphic mode the total screen is divided into 640 pixels width and 480 pixels height. Latest displays are even rich in resolution. 5) This function is present in "graphics.h" header line in turbo C.  Sample graphics program:  #include<stdio.h>

Line Basic Concepts

Image
 • We are going to study about Line Basic Concepts on Raster Screen. • so we are going to discuss what are the different ways in which line can be represented on Raster Screen and some of there respective features. 1) Vertical and Horizontal Line  • They have same width. • Straight line.  • Effective spacing is less. • More brighter. 2) 45° Line  • Width is not a constraint.  • Straight line. • More effective spacing. • Less brighter. Explanation:  • Point to remember is when there is more spacing between the points of line less brighter it will be and vice versa.  • But more spacing leads to effectiness in orientation of line. 3) Line with other orientation • In both of the above image the lines are nethier straight nor of same width. • Here points of line that is Pixel is approximated because while drawing the single line at point we get two points one is above the line and another is below the line. • But here approximation doesn't make a wide difference because pixel are very c