Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <graphics.h>
- #include <stdio.h>
- #include <conio.h>
- #include "windows.h"
- using namespace std;
- void KhoiTaoDohoa()
- {
- int driver=0,mode;
- initgraph(&driver,&mode,"");
- }
- void Bresenham_Circle(int xc, int yc, int Radius, int color)
- {
- int x, y, d;
- x = 0; y = Radius;
- d = 3 - 2 * Radius;
- while (x <= y)
- {
- putpixel(xc + x, yc + y, color);
- putpixel(xc - x, yc + y, color);
- putpixel(xc + x, yc - y, color);
- putpixel(xc - x, yc - y, color);
- putpixel(xc + y, yc + x, color);
- putpixel(xc - y, yc + x, color);
- putpixel(xc + y, yc - x, color);
- putpixel(xc - y, yc - x, color);
- if (d < 0)
- d+=4*x+6;
- else {
- d+=4*(x-y)+10;
- y--;
- }
- x++;
- }
- }
- void bline(int x1,int y1,int x2,int y2,int color)
- // 0<m<1
- {
- int x_max,x,y;
- int dx=abs(x1-x2);
- int dy=abs(y1-y2);
- int c1=2*dy;
- int c2=2*(dy-dx);
- int p=2*dy-dx;
- if (x1>x2)
- {
- x=x2; y=y2; x_max=x1;
- }
- else
- {
- x=x1; y=y1; x_max=x2;
- }
- putpixel(x,y,color);
- delay(5);
- while (x < x_max)
- {
- x=x+1;
- if (p<0) p=p+c1;
- else
- {
- y=y+1;
- p=p+c2;
- }
- putpixel(x,y,color);
- delay(5);
- }
- }
- int main(int argc, char *argv[])
- {
- KhoiTaoDohoa();
- setbkcolor(2);
- setcolor(YELLOW);
- line(1,100,800,100);
- delay(5000);
- bline(1,100,800,100,2);
- // Bresenham_Circle(
- //circle(200,150,100);
- setcolor(10); // set text color
- outtextxy(250,100,"DRAW A HOUSE");// print text in window graphics
- setcolor(6);
- line(300,120,500,180);
- delay(50);
- line(100,180,300,120);
- delay(50);
- line(100,180,500,180);
- setcolor(6);
- line(160,180,160,400);
- delay(50);
- line(440,180,440,400);
- delay(50);
- line(160,400,440,400);
- setcolor(6);
- rectangle(250,240,350,399);
- setfillstyle(1,RED);
- floodfill(300,160,6);
- setfillstyle(1,BLUE);
- floodfill(300,230,6);
- setfillstyle(1,WHITE);
- floodfill(300,360,6);
- setcolor(6);
- setfillstyle(1,YELLOW);
- rectangle(180,200,220,240);
- rectangle(420,200,380,240);
- floodfill(200,220,6);
- floodfill(400,220,6);
- line(200,200,200,240);
- line(180,220,220,220);
- line(400,200,400,240);
- line(420,220,380,220);
- line(300,240,300,399);
- line(298,240,298,399);
- setfillstyle(1,BLACK);
- circle(310,320,5);
- circle(290,320,5);
- floodfill(310,320,6);
- floodfill(290,320,6);
- setfillstyle(1,YELLOW);
- for (int i=1;i<=200;i++)
- {
- setcolor(i%13);
- circle(300,50,40);
- setfillstyle(1,i%13);
- floodfill(300,50,i%13);
- delay(1000);
- };
- while(!kbhit()) delay(1); // pause screen
- system("PAUSE");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement