0

# i want to draw a rectangle inside it a saqure the inside it a trianglet +using bresenham algorithm

the doctor give us this for code triangle i want to change the code (void main ) for rectangle and square bresenham algorithm #include<iostream.h> #include<graphics.h> #include <conio.h> #include <stdlib.h> void BRH(int x1, int y1, int x2,int y2 ,int c ) { int dx,dy,stepx,stepy,ac,x,y; dx=x2-x1; dy=y2-y1; if(dx>0) stepx=1; else stepx=-1; if(dy>0) stepy=1; else stepy=-1; x=x1; y=y1;ac=0; if(abs(dx)>abs(dy)) { putpixel(x,y,c); do { x+=stepx; ac+=abs(dy); if(ac>= abs(dx)) { y+=stepy; ac-=abs(dx); } putpixel(x,y,c); } while((x!=x2)&&(y!=y2)); } else if(abs(dx)<abs(dy)) { putpixel(x,y,c); do { y+=stepy; ac+=abs(dx); if( ac>= abs(dy)) { x+=stepx; ac-=abs(dy); } putpixel(x,y,c); } while((x!=x2)&&(y!=y2)); } } void main() { int driver=DETECT,mode; int x,y,x1,x2,y1,y2,x3,y3,stepx,stepy,ac,dx,dy,c,i; cout<<"x1,y1 x2,y2 ,c\n "; cin>> x1>>y1>>x2>>y2>>x3>>y3>>c; initgraph(&driver,&mode,"c:/turboc3/bgi"); BRH(x1,y1,x2,y2,c); BRH(x1,y1,x3,y3,c); BRH(x2,y2,x3,y3,c); getch(); closegraph();

11th Oct 2021, 11:37 AM
Sallyariel44
2 Réponses
+ 1
Why u not using rectangle property and set size according to your need you don't need to do much more calculation
11th Oct 2021, 11:48 AM
A S Raghuvanshi
0
The doctor want us to using this method +bresenham algorithm I slove the tringle BRH(x1,y1,x2,y2,c); BRH(x1,y1,x3,y3,c); BRH(x2,y2,x3,y3,c); Using this (200,120,252,210,150,212) and it works But the it dosent works for rectangle and square Can u help me please I tried a lot but it dosent work :( 🌠🌠
11th Oct 2021, 11:59 AM
Sallyariel44
Aujourd'hui en vedette
super laggy