Program for Bresenham's Line Drawing Algorithm in C++
- Get link
- X
- Other Apps
#include <iostream>
#include <graphics.h>
#include <conio.h>
using namespace std;
int main()
{
int x,y,x1,y1,x2,y2,dx,dy,step,P;
int i=1,gd=DETECT,gm;
float m;
cout<<"Enter the first point(x1,y1)";
cin>>x1>>y1;
cout<<"Enter the second point(x2,y2)";
cin>>x2>>y2;
char path[]="";
initgraph(&gd,&gm,path);
dx= abs(x2-x1);
dy = abs(y2-y1);
m = dy/dx;
x=x1;
y=y1;
putpixel(x,y,WHITE);
if(dx>=dy)
{
step =dx;
}
else
{
step =dy;
}
if(m<1)
{
P = 2*dy - dx;
while(i<=step)
{
if(P>0)
{
x=x+1;
y=y+1;
putpixel(x,y,WHITE);
P = P+ 2*dy-2*dx;
}
else
{
x=x+1;
y=y;
putpixel(x,y,WHITE);
P = P+ 2*dy;
}
i++;
}
}
else if(m>1)
{
P = 2*dx - dy;
while(i<=step)
{
if(P>0)
{
x=x+1;
y=y+1;
putpixel(x,y,WHITE);
P = P+ 2*dx-2*dy;
}
else
{
x=x;
y=y+1;
putpixel(x,y,WHITE);
P = P+ 2*dx;
}
i++;
}
}
else
{
while(i<=step)
{
x=x+1;
y=y+1;
putpixel(x,y,WHITE);
i++;
}
}
getch();
closegraph();
return 0;
}
OUTPUT:
- Get link
- X
- Other Apps
Popular posts from this blog
Download and install MATLAB R2017a in Ubuntu 18.04 | Linux Free | Cracked
Smile emoji using graphics in Java using Applet
import java.awt.*; import java.awt.event.*; import java.applet.*; public class Smile extends Applet { public void paint(Graphics g) { setBackground(Color.BLACK); g.setColor(Color.YELLOW); g.fillOval(30,50,100, 100); g.setColor(Color.BLACK); g.fillOval(55,75,10, 10); g.fillOval(95,75,10, 10); g.drawArc(60, 85, 40,40,-30,-120); } } /* <applet code="Smile.class" width="200" height="200"> </applet> */ OUTPUT:
Program to find the LCM & HCF of n numbers
class HcfLcm { public static void main(String[] args) { int n,x; System.out.println("Number of integers: "); n = Integer.parseInt(System.console().readLine()); if(n<1) { System.out.print("Invalid input!"); System.exit(0); } int[] arr = new int[n]; for(int i =0; i<n; i++) { System.out.print("Number "+(i+1)+":"); ...
Comments
Post a Comment