Skip to main content

Line

Include:
conio.h

dos.h
stdio.h
process.h
graphics.h
math.h

void DDA_Line();
void Bresenham_Line();


void main()
{
int x,y,x1,y1,x2,y2,i,dx,dy,len,e,r,d,gd,gm,ch;
char ans;
clrscr();

do
{
printf("\n\n-------------Menu-----------");
printf("\n 1. DDA Line");
printf("\n 2. Bresenham's Line");
printf("\n 3. Exit");
printf("\n\n Enter your choice : ");
scanf("%d",&ch);

switch(ch)
{
case 1:
DDA_Line();
break;
case 2:
Bresenham_Line();
break;
case 3:
exit(1);
}
printf("\n\n Do You Want to Continue ? (Y/N) : ");
ans=getche();
}while(ans=='Y'||ans=='y');
}

//---------DDA Line Algorithm-----------------
void DDA_Line()
{
int gd,gm,x1,x2,y1,y2,len,x,y,i,dx,dy;
printf("\n Enter Values as (X1,Y1) & (X2,Y2) : ");
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"bgi");

if(abs(x2-x1)>=abs(y2-y1))
len=abs(x2-x1);
else
len=abs(y2-y1);

dx=(x2-x1)/len;
dy=(y2-y1)/len;
x=x1+0.5;
y=y1+0.5;
i=1;

while(i<=len)
{
putpixel(x,y,11);
delay(20);
x=x+dx;
y=y+dy;
i=i+1;
}

getch();
closegraph();
}

//-------------Bresenham Line----------
void Bresenham_Line()
{
int gd,gm,x1,x2,y1,y2,dx,dy,e,i,x,y;
printf("\n Enter Values as (X1,Y1) & (X2,Y2) : ");
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);

detectgraph(&gd,&gm);
initgraph(&gd,&gm,"bgi");

dx=abs(x2-x1);
dy=abs(y2-y1);

x=x1;
y=y1;

e=(2*dy)-dx;
i=1;

do
{
delay(40);
putpixel(x,y,11);

while(e>=0)
{
y=y+1;
e=e-(2*dx);
}

x=x+1;
e=e+2*dy;
i++;
}while(i<=dx);
getch();
closegraph();
}

Comments

Popular posts from this blog

4. Lex and Yacc Program to detect errors in a 'C' Language Program

Lex and Yacc Program to detect errors in a 'C' Language Program   Lex Code : %{ #include"y.tab.h" #include<stdio.h> int LineNo = 1 ; %} identifier [ a - zA - Z ][ _a - zA - Z0 - 9 ]* number [ 0 - 9 ]+|([ 0 - 9 ]*\.[ 0 - 9 ]+) %% main \(\) return MAIN ; if return IF ; else return ELSE ; while return WHILE ; int | char | flaot return TYPE ; { identifier } return VAR ; { number } return NUM ; \> | \< | \<= | \>= | == return RELOP ; [\ t ] ; [\ n ] LineNo ++; . return yytext [ 0 ]; %% Yacc Code : %{ #include<string.h> #include<stdio.h> extern int LineNo ; int errno = 0 ; %} % token NUM VAR RELOP % token MAIN IF ELSE WHILE TYPE % left '-' '+' % left '*' '/' %% PROGRAM : MAIN BLOCK ; BLOCK : '{' CODE '}' ; CODE : BLOCK | STATEMENT CODE | STATEMENT ; STATEMENT : DECST ';' | DECST { printf ( "\nLine number %d...

Selenium + Python + UnexpectedAlertPresentException: Dealing with annoying alerts

Handling  UnexpectedAlertPresentException   Alerts who hates them? I Do!  Who doesn't hate an annoying alert causing your tests / scraping job to fail? I must say they are pretty much on point on the Unexpected part!  Fortunately, there are easy ways to mitigate the issue. 1. Disable alerts completely: driver . execute_script( 'window.alert = function(){};' ); execute this script just before where you anticipate the alert and you're golden. 2. You want to see the alert text but not disturb the execution flow. driver . execute_script( 'window.alert = console.info;' ); Now the alerts have been redirected to the console and you don't have to worry about them. (Unless you have to - then you'd have to monitor the console) 3. You know exactly when it comes and want to accept the alert and move on. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 from selenium import webdriver from selenium.webdriver.s...

2. Lex program that detects statement type i.e. Simple or Compound

Lex program that detects statement type i.e. Simple or Compound Note: Only AND | OR | BUT conjunctions are supported. Program: % option noyywrap %{ char test = 's' ; %} %% ( "" [ aA ][ nN ][ dD ] "" )|( "" [ oO ][ rR ] "" )|( "" [ bB ][ uU ][ tT ] "" ) { test = 'c' ;} . {;} \ n return 0 ; %% main () { yylex (); if ( test == 's' ) printf ( "\n Its a simple sentence" ); else if ( test == 'c' ) printf ( "\n This is compound sentence" ); }