Mid-Point Ellipse Generation Algorithm (C++)

Problem Definition: Write a program to implement Mid-Point Ellipse Generation Algorithm. #include <graphics.h> #include <iostream.h> #include <conio.h> void main(){ int xc,yc,x,y,d,r; int gdriver = DETECT, gmode; initgraph(&gdriver,&gmode,”C:\TC\BGI”); cout<<“Enter co-ordinates of centre: “; cin>>xc>>yc; cout<<“Enter radius of circle: “; cin>>r; x = 0; y = r; d = 3-2*r; do{ if(d<0){ d += 4*x +6; x++; } else{ d += 4*x – 4*y +10; x++; y–; } putpixel(xc+x,yc+y,WHITE); putpixel(xc+y,yc+x,WHITE); … Continue reading Mid-Point Ellipse Generation Algorithm (C++)

Mid-Point Circle Generation Algorithm (C++)

Problem Definition: Write a program to implement Mid-Point Circle Generation Algorithm. #include <graphics.h> #include <iostream.h> #include <conio.h> void main(){ int xc,yc,x,y,p,r; int gdriver = DETECT, gmode; initgraph(&gdriver,&gmode,”C:\TC\BGI”); cout<<“Enter co-ordinates of centre: “; cin>>xc>>yc; cout<<“Enter radius of circle: “; cin>>r; x = 0; y = r; p = 1-r; do{ if(p<0){ x++; p += 2*x +1; } else{ x++; y–; p += 2*x – 2*y +1; } putpixel(xc+x,yc+y,WHITE); putpixel(xc+y,yc+x,WHITE); … Continue reading Mid-Point Circle Generation Algorithm (C++)

Bresenham’s Line Drawing Algorithm (C++)

Problem Definition: Write a program to implement Bresenham’s Line drawing algorithm. #include <graphics.h> #include <conio.h> #include <math.h> #include <iostream.h> void main(){ int x1,x2,y1,y2,i,e,x,y,dx,dy; int gdriver = DETECT, gmode; initgraph(&gdriver,&gmode,”C:\TC\BGI”); cout<<“Enter co-ordinates of point 1: “; cin>>x1>>y1; cout<<“Enter co-ordinates of point 2: “; cin>>x2>>y2; dx = abs(x2-x1); dy = abs(y2-y1); x=x1; y=y1; e = 2*dy-dx; i=1; do{ putpixel(x,y,WHITE); while(e>=0){ y++; e = e – 2*dx; putpixel(x,y,WHITE); } x++; … Continue reading Bresenham’s Line Drawing Algorithm (C++)

Digital Differential Analyzer (DDA) Line Drawing Algorithm (C++)

Problem Definition: Write a program to implement Digital Differential Analyzer (DDA) Line drawing algorithm. #include <conio.h> #include <iostream.h> #include <graphics.h> #include <math.h> void main(){ float x,y,dx,dy; int x1,y1,x2,y2,i,length; int gdriver = DETECT, gmode; initgraph(&gdriver,&gmode,”C:\TC\BGI”); cout<<“Enter co-ordinates of point 1: “; cin>>x1>>y1; cout<<“Enter co-ordinates of point 2: “; cin>>x2>>y2; dx = abs(x2-x1); dy = abs(y2-y1); if(dx>=dy) length = dx; else length = dy; dx = dx/length; dy = … Continue reading Digital Differential Analyzer (DDA) Line Drawing Algorithm (C++)

Square root of a number (Assembly Language)

; Program to compute squareroot of a number DATA SEGMENT ;INITIALIZE DATA SEGMENT NUM1 DD 125.0 ;INTIALIZE NUM1 ANY DATA. ;WHEN DATA DOUBLE IS DEFINED, DEFINE THE NUMBER WITH DECIMAL RES DD ? ;INITIALIZE RES DATA ENDS ;END OF DATA SEGMENT CODE SEGMENT ;INITIALIZE CODE SEGMENT START: ;START THE CODE ASSUME CS:CODE,DS:DATA ;ASSUMPTION OF CODE AND DATA MOV AX,DATA ;MOVE DATA INTO ACCUMULATOR AX REGISTER … Continue reading Square root of a number (Assembly Language)