[Lập trình đồ họa máy tính cơ bản] Vẽ hình vuông xoắn ốc bằng C++

Vẽ hình vuông xoắn ốc bằng C++-Tinhoccoban.net
Vẽ hình vuông xoắn ốc bằng C++
Code Vẽ Xoắn Ốc bằng C++:

#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>

int main(){
    initwindow(800,600);
    int xc=400,yc=300,R = 80,loop=200;
    int g=0,gt=83,Rt=3;
    int c = 1;

    for (int i=0;i<loop;i++){
        g+=gt;
        int x = xc + round(cos(g*M_PI/180)*R);
        int y = yc + round(sin(g*M_PI/180)*R);
        setcolor(c);
        c++;
        if (c==16)
        c=1;
        line (xc,yc,x,y);
        xc = x;
        yc = y;
        R+=Rt;
      //  getch();
    }
    getch();
    return 0;
}

[Lập trình đồ họa máy tính cơ bản] Vẽ đền Tajmaha bằng ngôn ngữ C++

Vẽ đền Tajmaha bằng ngôn ngữ C++ - Tinhoccoban.net
Vẽ đền Tajmaha bằng ngôn ngữ C++

Tāj Mahal là một lăng mộ nằm tại Agra, Ấn Độ. Hoàng đế Môgôn Shāh Jahān (gốc Ba Tư, lên ngôi năm 1627); trong tiếng Ba Tư Shah Jahan (شاه ‌جها) có nghĩa là "chúa tể thế giới" đã ra lệnh xây nó cho người vợ yêu dấu của mình là Mumtaz Mahal.Công việc xây dựng bắt đầu năm 1632 và hoàn thành năm 1653. Một số tranh cãi xung quanh câu hỏi ai là người thiết kế Taj Mahal; rõ ràng một đội các nhà thiết kế và thợ thủ công đã chịu trách nhiệm thiết kế công trình và Ustad Ahmad Lahauri được coi là kiến trúc sư chính.


#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<process.h>
#include <time.h>


main()
{
srand((unsigned int) time(0));

initwindow(640,480);
int h=40;
line(0,440,639,440);

//line(20,30+h,619,30+h);

//line(25,400,38,120);
//line(85,400,78,120);
//line(85,400,78,120);


//=================================Ist tower========================//
//=================================IIst tower============================//
//#################TOWER%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//
int l=-20;
line(28+l,400+h,33+l,333+h);
line(86+l,400+h,80+l,333+h);
//||||||||||||||||||||||||||||||Ist stage||||||||||||||||||||||||||||||||||||||||||||//
line(23+l,328+h,32+l,334+h);               // slant
line(88+l,328+h,80+l,334+h);                       // slant
line(83+l,323+h,75+l,334+h);                       // slant
line(75+l,323+h,70+l,332+h);
line(66+l,323+h,65+l,332+h);                       // slant
line(57+l,323+h,57+l,332+h);                       // slant
line(30+l,323+h,39+l,334+h);                       // slant
line(38+l,323+h,45+l,332+h);
line(48+l,323+h,51+l,332+h);      // slant

ellipse(57+l,320+h,350,190,34,5);
ellipse(57+l,327+h,350,190,34,5);
ellipse(57+l,337+h,0,180,25,5);
line(22+l,320+h,22+l,328+h);
line(91+l,320+h,91+l,327+h);
setfillstyle(6,15);
floodfill(60+l,320+h,15);

setfillstyle(10,15);

floodfill(60+l,320+h+15,15);


//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
//+++++++++++++++++++++++++++++++++++2nd+++++++++++++++++++++++++++

line(35+l,315+h,38+l,242+h);
line(80+l,315+h,75+l,242+h);

//||||||||||||||||||||||||||||||2ststage||||||||||||||||||||||||||||||||||||||||||||//
int t=-93;
line(23+4+l,328+t+3+h,32+5+l,334+t+h);               // slant
line(88+l,328+t+2+h,76+l,334+t+h);                       // slant
//line(+l83,323+t+4,75,334+t);                       // slant
line(78+l,323+t+3+h,71+l,332+t+h);
line(66+l,323+t+2+h,65+l,332+t+h);                       // slant
line(57+l,323+t+2+h,57+l,332+t-2+h);                       // slant
//line(30,323+t+2,39,334+t);                       // slant
line(35+l,323+t+3+h,45-3+l,332+t+h);
line(48+l,323+t+2+h,51+l,332+t-2+h);      // slant

ellipse(57+l,320+t+3+h,360,190,30,5);
ellipse(57+l,327+t+3+h,360,190,30,5);
ellipse(57+l,337+t-1+h,0,180,18,5);

line(26+l,320+t+3+h,26+l,328+t+2+h);
line(88+l,320+t+3+h,88+l,327+t+3+h);
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
setfillstyle(6,15);
floodfill(60+l,320+h+t,15);                            ////////////////
setfillstyle(10,15);
floodfill(60+l,320+h-35,15);

//||||||||||||||||||||||||||||||3rd stage||||||||||||||||||||||||||||||||||||||||||||//

line(38+l,225+h,41+l,152+h);
line(75+l,225+h,72+l,152+h);



 t=-182;
line(32+l,328+t+4+h,32+7+l,334+t+h);               // slant
line(80+l,328+t+4+h,73+l,334+t+h);                       // slant
//line(+l83,323+t+4,75,334+t);                       // slant
line(76+l,323+t+5+h,71+l,332+t+h);
line(66+l,323+t+4+h,65+l,332+t+h);                       // slant
line(57+l,323+t+4+h,57+l,332+t-2+h);                       // slant
//line(30,323+t+2,39,334+t);                       // slant
line(39+l,323+t+6+h,45+l,332+t+1+h);
line(48+l,323+t+4+h,51+l,332+t+h);      // slant

ellipse(57+l,320+t+6+h,360,190,24,5);
ellipse(57+l,327+t+4+h,360,190,24,5);
ellipse(57+l,337+t-1+h,0,170,16,5);

line(32+l,320+t+6+h,32+l,328+t+3+h);
line(81+l,320+t+6+h,81+l,327+t+3+h);

setfillstyle(6,15);
floodfill(60+l,322+h+t,15);
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
setfillstyle(10,15);
floodfill(60+l,322+h+t+30,15);
//GGF################TOWER%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//

ellipse(51+l,132+h,340,216,4,15);
ellipse(62+l,131+h,327,216,4,15);
ellipse(72+l,132+h,327,216,2,15);
ellipse(42+l,132+h,327,216,2,15);
ellipse(57+l,107+h,0,170,16,5);
line(40+l,107+h,40+l,140+h);
line(75+l,107+h,75+l,140+h);

line(34+l,107+h,40+l,107+h);
line(75+l,107+h,81+l,107+h);

line(34+l,107+h,28+l,102+h);                      //slant
line(81+l,107+h,87+l,102+h);

line(28+l,102+h,34+l,98+h);
line(87+l,102+h,81+l,98+h);

line(34+l,98+h,58+l,95+h);
line(58+l,95+h,81+l,98+h);


ellipse(65+l,92+h,104,190,30,30);

ellipse(50+l,92+h,350,76,30,30);

line(58+l,61+h,58+l,63+h);
circle(58+l,58+h,3);
line(58+l,55+h,58+l,53+h);
circle(58+l,50+h,2);
line(58+l,48+h,58+l,47+h);
circle(58+l,45+h,1);
line(58+l,44+h,58+l,41+h);
setfillstyle(6,15);
floodfill(60+l-2,322+h+t-60,15);

setfillstyle(10,15);
floodfill(60+l-2,322+h+t-30,15);


//=================================IIst tower============================//
//#################TOWER%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//
 l=547;


line(28+l,400+h,33+l,333+h);
line(86+l,400+h,80+l,333+h);
//||||||||||||||||||||||||||||||Ist stage||||||||||||||||||||||||||||||||||||||||||||//
line(23+l,328+h,32+l,334+h);               // slant
line(88+l,328+h,80+l,334+h);                       // slant
line(83+l,323+h,75+l,334+h);                       // slant
line(75+l,323+h,70+l,332+h);
line(66+l,323+h,65+l,332+h);                       // slant
line(57+l,323+h,57+l,332+h);                       // slant
line(30+l,323+h,39+l,334+h);                       // slant
line(38+l,323+h,45+l,332+h);
line(48+l,323+h,51+l,332+h);      // slant

ellipse(57+l,320+h,350,190,34,5);
ellipse(57+l,327+h,350,190,34,5);
ellipse(57+l,337+h,0,180,25,5);
line(22+l,320+h,22+l,328+h);
line(91+l,320+h,91+l,327+h);
setfillstyle(6,15);
floodfill(60+l,320+h,15);

setfillstyle(10,15);

floodfill(60+l,320+h+15,15);


//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
//+++++++++++++++++++++++++++++++++++2nd+++++++++++++++++++++++++++
line(35+l,315+h,38+l,242+h);
line(80+l,315+h,75+l,242+h);

//||||||||||||||||||||||||||||||2st stage||||||||||||||||||||||||||||||||||||||||||||//
t=-93;
line(23+4+l,328+t+3+h,32+5+l,334+t+h);               // slant
line(88+l,328+t+2+h,76+l,334+t+h);                       // slant
//line(+l83,323+t+4,75,334+t);                       // slant
line(78+l,323+t+3+h,71+l,332+t+h);
line(66+l,323+t+2+h,65+l,332+t+h);                       // slant
line(57+l,323+t+2+h,57+l,332+t-2+h);                       // slant
//line(30,323+t+2,39,334+t);                       // slant
line(35+l,323+t+3+h,45-3+l,332+t+h);
line(48+l,323+t+2+h,51+l,332+t-2+h);      // slant

ellipse(57+l,320+t+3+h,360,190,30,5);
ellipse(57+l,327+t+3+h,360,190,30,5);
ellipse(57+l,337+t-1+h,0,180,18,5);

line(26+l,320+t+3+h,26+l,328+t+2+h);
line(88+l,320+t+3+h,88+l,327+t+3+h);
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
setfillstyle(6,15);
floodfill(60+l,320+h+t,15);                            ////////////////
setfillstyle(10,15);
floodfill(60+l,320+h-35,15);

//||||||||||||||||||||||||||||||3rd stage||||||||||||||||||||||||||||||||||||||||||||//

line(38+l,225+h,41+l,152+h);
line(75+l,225+h,72+l,152+h);



 t=-182;
line(32+l,328+t+4+h,32+7+l,334+t+h);               // slant
line(80+l,328+t+4+h,73+l,334+t+h);                       // slant
//line(+l83,323+t+4,75,334+t);                       // slant
line(76+l,323+t+5+h,71+l,332+t+h);
line(66+l,323+t+4+h,65+l,332+t+h);                       // slant
line(57+l,323+t+4+h,57+l,332+t-2+h);                       // slant
//line(30,323+t+2,39,334+t);                       // slant
line(39+l,323+t+6+h,45+l,332+t+1+h);
line(48+l,323+t+4+h,51+l,332+t+h);      // slant

ellipse(57+l,320+t+6+h,360,190,24,5);
ellipse(57+l,327+t+4+h,360,190,24,5);
ellipse(57+l,337+t-1+h,0,170,16,5);

line(32+l,320+t+6+h,32+l,328+t+3+h);
line(81+l,320+t+6+h,81+l,327+t+3+h);

setfillstyle(6,15);
floodfill(60+l,322+h+t,15);
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
setfillstyle(10,15);
floodfill(60+l,322+h+t+30,15);
//GGF################TOWER%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//

ellipse(51+l,132+h,340,216,4,15);
ellipse(62+l,131+h,327,216,4,15);
ellipse(72+l,132+h,327,216,2,15);
ellipse(42+l,132+h,327,216,2,15);
ellipse(57+l,107+h,0,170,16,5);
line(40+l,107+h,40+l,140+h);
line(75+l,107+h,75+l,140+h);

line(34+l,107+h,40+l,107+h);
line(75+l,107+h,81+l,107+h);

line(34+l,107+h,28+l,102+h);                      //slant
line(81+l,107+h,87+l,102+h);

line(28+l,102+h,34+l,98+h);
line(87+l,102+h,81+l,98+h);

line(34+l,98+h,58+l,95+h);
line(58+l,95+h,81+l,98+h);


ellipse(65+l,92+h,104,190,30,30);

ellipse(50+l,92+h,350,76,30,30);

line(58+l,61+h,58+l,63+h);
circle(58+l,58+h,3);
line(58+l,55+h,58+l,53+h);
circle(58+l,50+h,2);
line(58+l,48+h,58+l,47+h);
circle(58+l,45+h,1);
line(58+l,44+h,58+l,41+h);
setfillstyle(6,15);
floodfill(60+l-2,322+h+t-60,15);

setfillstyle(10,15);
floodfill(60+l-2,322+h+t-30,15);
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//

//GGF################TOWER%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//

ellipse(51+l,132+h,340,216,4,15);
ellipse(62+l,131+h,327,216,4,15);
ellipse(72+l,132+h,327,216,2,15);
ellipse(42+l,132+h,327,216,2,15);
ellipse(57+l,107+h,0,170,16,5);
line(40+l,107+h,40+l,140+h);
line(75+l,107+h,75+l,140+h);

line(34+l,107+h,40+l,107+h);
line(75+l,107+h,81+l,107+h);

line(34+l,107+h,28+l,102+h);                      //slant
line(81+l,107+h,87+l,102+h);

line(28+l,102+h,34+l,98+h);
line(87+l,102+h,81+l,98+h);

line(34+l,98+h,58+l,95+h);
line(58+l,95+h,81+l,98+h);


ellipse(65+l,92+h,104,190,30,30);

ellipse(50+l,92+h,350,76,30,30);

line(58+l,61+h,58+l,63+h);
circle(58+l,58+h,3);
line(58+l,55+h,58+l,53+h);
circle(58+l,50+h,2);
line(58+l,48+h,58+l,47+h);
circle(58+l,45+h,1);
line(58+l,44+h,58+l,41+h);


//=================================Ist tower========================//

//+++++++++++++++++++++++++++++++++TAJ mahal++++++++++++++++++++++++//

////setcolor(15);

rectangle(275,290,365,440);         //  inner
rectangle(268,283,372,440);           //     //inner
setfillstyle(1,15);
floodfill(274,294,15);
line(280,440,280,350);
//line(283,440,283,350);
ellipse(315,349,130,180,35,40);
ellipse(275,280,290,326,53,40);

line(360,440,360,350);
ellipse(325,349,360,50,35,40);
ellipse(361,280,216,255,53,40);
setfillstyle(9,7);
floodfill(277,386,15);
putpixel(277,386,14);

line(280,360,359,360);
line(280,364,359,364);
setfillstyle(1,15);
floodfill(281,362,15);

rectangle(295+4,370,345-4,440);
rectangle(292+4,367,348-4,440);
setfillstyle(1,15);
floodfill(294+4,369,15);
rectangle(296,378,344,380);
floodfill(301,379,15);


line(302,405,302,440);
line(338,405,338,440);
ellipse(327,405,108,180,25,20);

ellipse(313,405,360,74,25,20);

setfillstyle(7,15);
//putpixel(312,416,11);
//floodfill(312,406,15);
line(329,390,329,440);
line(310,391,310,440);
line(311,402,329,402);
line(311,422,329,422);
line(302,412,310,412);
line(329,412,338,412);

line(302,428,310,428);
line(329,428,338,428);
//setfillstyle(7,15);


 int p=-60;
line(302,405+p,302,440+p-20);
line(338,405+p,338,440+p-20);
ellipse(327,405+p,108,180,25,20);

ellipse(313,405+p,360,74,25,20);
setfillstyle(7,15);
floodfill(311,406,15);
line(329,390+p,329,440+p-20);
line(310,391+p,310,440+p-20);
line(311,402+p,329,402+p);
line(311,422+p-7,329,422+p-7);
line(302,412+p,310,412+p);
line(329,412+p,338,412+p);



//??//////////////////////////////////2nd portion/////////////////////


rectangle(245,260,400,440);         //  inner
rectangle(230,245,415,440);           //     //inner

rectangle(230,425,275,440);
setfillstyle(1,15);
floodfill(231,426,15);
floodfill(249,426,15);
////setcolor(8);
rectangle(230+135,425,275+140,440);
//setfillstyle(1,15);

floodfill(231+160,426,15);
floodfill(249+159,426,15);



////setcolor(15);
line(415,290,415,440);
line(420,245,420,440);

line(415,240,415,205);
line(420,240,420,205);


line(225,245,225,440);          //vertical
line(230,250,230,440);

line(225,240,225,205);          //vertical
line(230,240,230,205);

line(222,240,425,240);
line(222,245,425,245);                    //horz

ellipse(222,242.5,90,270,2.5,2.5);
ellipse(425,242.5,270,90,2.5,2.5);

rectangle(231,230,414,239);



ellipse(227,206,0,180,9,1);
ellipse(227,204,0,180,9,1);
putpixel(220,204,15);
putpixel(220,205,15);
putpixel(220,206,15);
putpixel(235,204,15);
putpixel(235,205,15);
putpixel(235,206,15);
ellipse(227,203,0,180,6,7);
line(227,195,227,192);
int r=190;

ellipse(227+r,206,0,180,9,1);
ellipse(227+r,204,0,180,9,1);
putpixel(220+r,204,15);
putpixel(220+r,205,15);
putpixel(220+r,206,15);
putpixel(235+r,204,15);
putpixel(235+r,205,15);
putpixel(235+r,206,15);

ellipse(227+r,203,0,180,6,7);
line(227+r,195,227+r,192);

/*

//floodfill(305,424,15);
//floodfill(305,429,15);
//floodfill(325,424,15);
//floodfill(325,421,15);
//floodfill(332,420,15);
//floodfill(332,429,15);
*/

ellipse(315,170,140,210,105,100);
ellipse(330,170,330,40,105,100);

ellipse(292,167,105,140,75,95);
ellipse(353,167,40,75,75,95);

ellipse(323,78,350,190,60,8);
ellipse(323,77,350,190,60,8);


//ellipse(259,24,295,358,58,51);
ellipse(240,24,321,358,78,71);
ellipse(192,40,342,7,128,100);

ellipse(448,30,180,203,128,100);
ellipse(443,5,194,220,128,100);
ellipse(438,-9,203,234,128,100);
ellipse(198,-6,310,340,128,100);

ellipse(319,30,0,360,7,2);

floodfill(320,29,15);
circle(319,24,3);
line(319,20,319,18);
circle(319,14,4);
line(319,9,319,0);
//ellipse(319,4,0,360,2,3);
circle(319,2,1);
line(316,6,322,6);
line(316,6,314,4);
line(322,6,324,4);
//???????????????????????????????????

//////////////////////////////////////////////////////////
//ellipse();
ellipse(321,258,48,130,140,50);
ellipse(321,255,48,130,140,50);

ellipse(321,241,48,130,140,50);
ellipse(321,238,48,130,140,50);
//setfillstyle(6,11);
//  line(265,79,277,70);
//////setcolor(4);
  //line(385,81,380,76);

//while(!kbhit())
//{
 delay(300);
setfillstyle(10,15);

floodfill(322,160,15);
setfillstyle(6,15);

floodfill(322,193,15);

//}
//line(319,26,319,480+h);//center



///////////////////////////////////////////new////////////////////////////
rectangle(150,283,225,294);

//line(146,294,225,294);
line(150,298,225,298);

line(150,240,150,440);            //pole
line(146,240,146,440);

line(150,299,150,440);            //pole
line(146,299,146,440);


r=-80;
int n=34;

ellipse(227+r,206+n,0,180,9,1);
ellipse(227+r,204+n,0,180,9,1);
putpixel(220+r,204+n,15);
putpixel(220+r,205+n,15);
putpixel(220+r,206+n,15);
putpixel(235+r,204+n,15);
putpixel(235+r,205+n,15);
putpixel(235+r,206+n,15);

ellipse(227+r,203+n,0,180,6,7);
line(227+r,195+n,227+r,192+n);

l=128;
h=150;

ellipse(51+l,132+h-7,340,216,4,15);
ellipse(62+l,131+h-7,327,216,4,15);
ellipse(72+l,132+h-7,327,216,2,15);
ellipse(42+l,132+h-7,327,216,2,15);
ellipse(57+l,107+h,0,170,16,5);
line(40+l,107+h,40+l,140+h-7);
line(75+l,107+h,75+l,140+h-7);

line(34+l,107+h,40+l,107+h);
line(75+l,107+h,81+l,107+h);

line(34+l,107+h,28+l,102+h);                      //slant
line(81+l,107+h,87+l,102+h);

line(28+l,102+h,34+l,98+h);
line(87+l,102+h,81+l,98+h);

line(34+l,98+h,58+l,95+h);
line(58+l,95+h,81+l,98+h);


ellipse(65+l,92+h,104,190,30,30);

ellipse(50+l,92+h,350,76,30,30);

line(58+l,61+h,58+l,63+h);
circle(58+l,58+h,3);
line(58+l,55+h,58+l,53+h);
circle(58+l,50+h,2);
line(58+l,48+h,58+l,47+h);
circle(58+l,45+h,1);
line(58+l,44+h,58+l,41+h);


line(100-5,240+15,100-5,440);            //pole
line(96-5,240+15,96-5,440);

r=-134;
 n=49;
ellipse(227+r,206+n,0,180,9,1);
ellipse(227+r,204+n,0,180,9,1);
putpixel(220+r,204+n,15);
putpixel(220+r,205+n,15);
putpixel(220+r,206+n,15);
putpixel(235+r,204+n,15);
putpixel(235+r,205+n,15);
putpixel(235+r,206+n,15);

ellipse(227+r,203+n,0,180,6,7);
line(227+r,195+n,227+r,192+n);


line(146,294,97,302);
line(146,298,97,306);

line(146,283,97,291);


///////////////////////////////////////inner/////////////////

//rectangle(275+k,290,365+k,440);         //  inner
//rectangle(268+k,283,372+k,440);           //     //inner

//line(225,367,151,367);
rectangle(155,302,220,364);
rectangle(155,302+70,220,364+75);

int q=-133;
int d=-2;
line(302+q-5,405+d,302+q-5,440+d);
line(338+q+5,405+d,338+q+5,440+d);
ellipse(327+q+5,405+d,108,180,35,30);

ellipse(313+q-5,406+d,360,74,35,30);


d=-77;
line(302+q-5,405+d,302+q-5,440+d);
line(338+q+5,405+d,338+q+5,440+d);
ellipse(327+q,405+d,105,180,30,25);

ellipse(313+q,405+d,360,80,30,25);
putpixel(163,300,11);
setfillstyle(6,15);
floodfill(163,330,15);
floodfill(160,380,15);

line(141,305,141,360);
line(101,310,101,365);
line(141,305,101,310);
line(141,360,101,365);


int x=70;
line(141,305+x,141,440);
line(101,310+x,101,440);
line(141,305+x,101,310+x);



q=-200;
line(302+q+4,405+d,302+q+4,440+d);
line(338+q-1,405+d,338+q-1,440+d-2);
ellipse(327+q,405+d,105,180,20,15);
ellipse(313+q+4,405+d,360,80,20,15);

d=1;
line(302+q+4,405+d,302+q+4,440+d-2);
line(338+q-1,405+d,338+q-1,440+d-2);
ellipse(327+q,405+d,105,180,20,15);
ellipse(313+q+4,405+d,360,80,20,15);

rectangle(178,415,197,439);
setfillstyle(7,15);
floodfill(179,416,15);
 rectangle(178,415-75,197,440-76);
setfillstyle(7,15);
floodfill(179,415-75+1,15);

line(130-3,417,130-3,440);
line(113+3,420,113+3,440);

line(113+3,420,130-3,417);
putpixel(114,423,4);
line(113,440,130,440);
floodfill(114+3,423,15);



int a=-76;
line(130-3,417+a,130-3,440+a-3);
line(113+3,420+a,113+3,440+a);

line(113+3,420+a,130-3,417+a);
putpixel(114,423,4);
floodfill(114+3,423+a,15);



line(10,400+h,615,400+h);



//////////////////////////////////////////////right\\\\\\\\\\\


int e=270;
rectangle(150+e,283,226+e,294);
line(146+e+4,294,225+e,294);
line(146+e+4,298,225+e,298);


line(150+e+80,240,150+e+80,440);            //pole
line(146+e+80,240,146+e+80,440);

line(150+e+80,299,150+e+80,440);            //pole
line(146+e+80,299,146+e+80,440);





l=400;
h=+149;
ellipse(51+l,132+h-7,340,216,4,15);
ellipse(62+l,131+h-7,327,216,4,15);
ellipse(72+l,132+h-7,327,216,2,15);
ellipse(42+l,132+h-7,327,216,2,15);
ellipse(57+l,107+h,0,170,16,5);
line(40+l,107+h,40+l,140+h-7);
line(75+l,107+h,75+l,140+h-7);

line(34+l,107+h,40+l,107+h);
line(75+l,107+h,81+l,107+h);

line(34+l,107+h,28+l,102+h);                      //slant
line(81+l,107+h,87+l,102+h);

line(28+l,102+h,34+l,98+h);
line(87+l,102+h,81+l,98+h);

line(34+l,98+h,58+l,95+h);
line(58+l,95+h,81+l,98+h);


ellipse(65+l,92+h,104,190,30,30);

ellipse(50+l,92+h,350,76,30,30);

line(58+l,61+h,58+l,63+h);
circle(58+l,58+h,3);
line(58+l,55+h,58+l,53+h);
circle(58+l,50+h,2);
line(58+l,48+h,58+l,47+h);
circle(58+l,45+h,1);
line(58+l,44+h,58+l,41+h);

r=270;
n=n-15;

ellipse(227+r,206+n,0,180,9,1);
ellipse(227+r,204+n,0,180,9,1);
putpixel(220+r,204+n,15);
putpixel(220+r,205+n,15);
putpixel(220+r,206+n,15);
putpixel(235+r,204+n,15);
putpixel(235+r,205+n,15);
putpixel(235+r,206+n,15);

ellipse(227+r,203+n,0,180,6,7);
line(227+r,195+n,227+r,192+n);



line(146+e+135,302,97+e+135,294);
line(146+e+135,306,97+e+135,298);

line(146+e+135,291,97+e+135,283);



line(100-5+e+190,240+15,100-5+e+190,440);            //pole
line(96-5+e+190,240+15,96-5+e+190,440);





r=325;
n+=15;
ellipse(227+r,206+n,0,180,9,1);
ellipse(227+r,204+n,0,180,9,1);
putpixel(220+r,204+n,15);
putpixel(220+r,205+n,15);
putpixel(220+r,206+n,15);
putpixel(235+r,204+n,15);
putpixel(235+r,205+n,15);
putpixel(235+r,206+n,15);

ellipse(227+r,203+n,0,180,6,7);
line(227+r,195+n,227+r,192+n);


rectangle(155+e,302,220+e,364);
rectangle(155+e,302+70,220+e,364+75);


q=140;
d-=1;
line(302+q-5,405+d,302+q-5,440+d);
line(338+q+5,405+d,338+q+5,440+d);
ellipse(327+q+5,405+d,108,180,35,30);

ellipse(313+q-5,406+d,360,74,35,30);

d=-77;
line(302+q-5,405+d,302+q-5,440+d);
line(338+q+5,405+d,338+q+5,440+d);
ellipse(327+q,405+d,105,180,30,25);

ellipse(313+q,405+d,360,80,30,25);
putpixel(163,300,11);
setfillstyle(6,15);
floodfill(163,330,15);
floodfill(160,380,15);
/////////////////////////////
e=e-15;
line(141+e+150,305+5,141+e+150,360+5);
line(101+e+150,310-5,101+e+150,365-5);
line(101+e+150,305,141+e+150,310);
line(101+e+150,360,141+e+150,365);

int v=75;
line(141+e+150,305+5+v-5,141+e+150,440);
line(101+e+150,310-5+v-5,101+e+150,440);
line(101+e+150,305+v-5,141+e+150,310+v-5);
//line(101+e+150,360+v,141+e+150,365+v);

e=e+18;
rectangle(178+e,415,197+e,439);
setfillstyle(7,15);
floodfill(179+e,416,15);
int f=-75;
rectangle(178+e,415+f,197+e,439+f);
setfillstyle(7,15);
floodfill(179+e,416+f,15);


e+=130;
line(130-3+e,440+a-2,130-3+e,417+a+2);
line(113+3+e,440+a-2,113+3+e,420+a-2);

line(113+3+e,417+a,130-3+e,420+a);
putpixel(114+e,423,4);
floodfill(114+3+e,423+a,15);

a=1;
line(130-3+e,440+a-2,130-3+e,417+a+2);
line(113+3+e,440+a-2,113+3+e,420+a-2);

line(113+3+e,417+a,130-3+e,420+a);
putpixel(114+e,423,4);
line(113+3+e,440,130-3+e,440);
floodfill(114+3+e,423+a,15);


q=204;
line(302+q+4,405+d,302+q+4,440+d-2);
line(338+q-1,405+d,338+q-1,440+d+2);
ellipse(327+q,405+d,105,180,20,15);
ellipse(313+q+4,405+d,360,80,20,15);
q=204;

d=0;
line(302+q+4,405+d,302+q+4,440+d-1);
line(338+q-1,405+d,338+q-1,440+d);
ellipse(327+q,405+d,105,180,20,15);
ellipse(313+q+4,405+d,360,80,20,15);
line(302+q+4,440,302+q+4,440);




setfillstyle(10,15);
floodfill(322,160,15);
setfillstyle(6,15);

floodfill(322,193,15);
///////////////////////////////////////////////walls//////////////
setfillstyle(9,15);
floodfill(110,294,15);
floodfill(210,290,15);
floodfill(430,290,15);
floodfill(520,290,15);
/////////////////////////////////////////////poles
setfillstyle(6,15);
floodfill(93,394,15);
floodfill(148,394,15);
floodfill(227,394,15);
floodfill(417,394,15);
floodfill(498,394,15);
floodfill(553,394,15);


setfillstyle(9,15);
floodfill(185,224,15);
floodfill(465,224,15);




  getch();
return 0;
}

[Lập trình đồ họa máy tính cơ bản] Vẽ các hình tròn, các hình vuông đồng tâm

Các hình tròn đồng tâm - Tinhoccoban.net
Vẽ các hình tròn đồng tâm bằng C++


Viết chương trình đồ họa đầu tiên

1. Mẫu chương trình:


#include <stdio.h>
#include <conio.h>
#include <graphics.h>
 
int main(){
    initwindow(800,600);//tao cua so do hoa, size 800x600
    //ma lenh
    getch();
    return 0;
}

2. Chương trình đồ họa đầu tiên:


#include 
#include 
#include 

int main(){
    initwindow(800,600);//tao cua so do hoa, size 800x600
    setcolor(7);
    circle(400,300,200);
    line(400 , 100 , 400 , 500);
    line(200 , 300 , 600 , 300);
    getch();
    return 0;
}

Chú ý:
- Trục Oy có chiều dương hướng xuống
- setcolor(mau): chọn màu cho đường, mau (0->15)
- line(x1,y1,x2,y2): vẽ đường thẳng bắt đầu từ (x1,y1) đến (x2,y2)
- cirle(x,y,r): vẽ đường tròn, tâm (x,y), bán kính r

3. Màn hình đồ họa 800x600, Vẽ hình chữ nhật có tâm là tâm màn hình đồ họa, chiều dài 400, chiều rộng 300

- Tâm hình chữ nhật : 400 300
- Vẽ hình chữ nhật, xác định 2 điểm

  • Top Left: 200 150
  • Bottom Right: 600 450



#include 
#include 
#include 
 
int main(){
    initwindow(800,600);//tao cua so do hoa, size 800x600
    rectangle (200,150,600,450);
    rectangle (250,150,550,450);
    circle(400,300,150);
 
    getch();
    return 0;
}

4. Vẽ các hình vuông đồng tâm, màu không đổi


#include 
#include 
#include 
 
int main(){
    initwindow(800,600);//tao cua so do hoa, size 800x600
    int x1=250,y1=150,x2=550,y2=450;
    int d=1;
    int dl=20;
    int n=150;
    while(1){
        setcolor(15);
        for(int i=0;i<=n;i++){
            rectangle(x1+d*i,y1+d*i,x2-d*i,y2-d*i);
            delay(dl);
        }
        setcolor(0);
        for(int i=n;i>=0;i--){
            rectangle(x1+d*i,y1+d*i,x2-d*i,y2-d*i);
            delay(dl);
        }
    }
    getch();
    return 0;
}

5. Vẽ các đường tròn đồng tâm đổi màu


#include 
#include 
#include 
int main(){
    initwindow(800,600);//tao cua so do hoa, size 800x600
    int x=400,y=300,r=200;
    int d=10;
    int dl=200;
    int n=15;
    int color=15;
    while(1){
        for(int i=0;i<=n;i++){
            setcolor(color-i);
            circle(x,y,r-d*i);
            delay(dl);
        }
        setcolor(0);
        for(int i=n;i>=0;i--){
            circle(x,y,r-d*i);
            delay(dl);
        }
    }
    getch();
    return 0;
}

[Lập trình đồ họa máy tính cơ bản] Vẽ thần Voi Ganesha Ấn Độ



Vẽ thần Voi Ganesha Ấn Độ - tinhoccoban.net
Vẽ thần Voi Ganesha Ấn Độ bằng C++

Ganesha là một vị thần đáng kính trong Ấn Độ giáo, nhân dạng của thần kỳ dị, với đầu voi mình người. Thần Ganesha là tượng trưng của tài trí, hạnh phúc và thành công. Ngài là con của thần Shiva và nữ thần Parvati.




#include <graphics.h>
#include <dos.h>
#include <stdlib.h>
#include <time.h>

main(){
srand((unsigned int) time(0));
   int gd=0,gm=0,i,j=800,r,c;

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

   cleardevice();

   line(160,240,410,240);

   line(170,250,400,250);

   line(160,240,160,256);

   line(170,250,160,256);

   line(410,240,410,256);

   line(400,250,410,256);

   line(260,240,220,240);

   line(220,240,220,230);

   line(220,230,200,225);

   line(200,225,200,200);

   line(200,200,220,200);

   line(220,200,260,220);

   line(266,226,280,220);

   line(270,240,280,240);

   line(280,240,280,230);

   line(270,240,266,234);

   arc(280,225,270,0,5);

   line(340,240,380,230);

   line(380,230,380,200);

   line(380,200,340,200);

   line(340,200,300,230);

   line(320,240,300,230);

   line(319,240,300,231);

   line(318,240,300,232);

   line(317,240,300,233);

   line(316,240,300,234);

   line(294,236,290,240);

   line(290,240,280,240);

   line(280,244,290,250);

   line(289,250,296,260);

   line(296,260,306,260);

   line(306,260,300,250);

   line(300,250,306,240);

   line(202,200,202,198);

   line(218,200,218,198);

   line(202,198,218,198);

   line(203,198,203,196);

   line(217,198,217,196);

   line(203,196,217,196);

   line(206,194,200,190);

   line(217,196,220,190);

   line(200,190,200,170);

   line(220,190,220,180);

   line(205,180,205,170);

   arc(203,170,0,180,2);

   line(210,180,210,169);

   arc(208,169,0,180,2);

   line(214,180,214,169);

   arc(212.5,169,0,180,2);

   line(217,180,217,170);

   arc(216,170,0,180,1);

   line(220,180,218,180);

   line(216,180,217,186);

   line(378,200,378,196);

   line(352,200,352,196);

   line(378,196,352,196);

   line(354,196,354,190);

   line(370,196,370,192);

   line(370,192,380,186);

   line(354,190,360,186);

   line(390,186,350,186);

   line(350,186,346,184);

   line(390,186,394,184);

   line(346,184,394,184);

   arc(354,186,0,180,5);

   arc(359,186,0,180,5);

   arc(364,186,0,180,5);

   arc(369,186,0,180,5);

   arc(374,186,0,180,5);

   arc(379,186,0,180,5);

   arc(384,186,0,180,5);

   arc(359,182,0,180,5);

   arc(364,182,0,180,5);

   arc(369,182,0,180,5);

   arc(374,182,0,180,5);

   arc(379,182,0,180,5);

   arc(364,178,0,180,5);

   arc(369,178,0,180,5);

   arc(374,178,0,180,5);

   arc(369,176,0,180,7);

   line(330,140,330,110);

   line(250,140,250,110);

   line(330,110,310,100);

   line(250,110,270,100);

   line(310,100,270,100);

   line(330,140,300,160);

   line(250,140,280,160);

   line(300,160,300,180);

   line(280,160,280,190);

   arc(290,190,180,260,10);

   arc(310,180,180,360,10);

   arc(330,190,270,360,10);

   line(340,190,340,170);

   line(320,180,320,170);

   arc(330,170,90,180,10);

   arc(350,170,90,180,10);

   line(350,160,330,160);

   line(330,80,250,80);

   line(330,70,250,70);

   line(330,80,350,100);

   line(330,70,350,90);

   line(250,80,230,100);

   line(250,70,230,90);

   arc(240,90,180,230,10);

   arc(340,90,320,360,10);

   arc(240,90,240,270,3);

   line(250,90,240,100);

   line(330,90,340,100);

   line(260,90,250,100);

   line(320,90,330,100);

   arc(250,90,220,270,10);

   arc(330,90,270,320,10);

   line(320,50,260,50);

   line(320,50,330,60);

   line(260,50,250,60);

   arc(260,60,180,270,10);

   arc(320,60,270,360,10);

   rectangle(270,40,310,50);

   line(240,100,240,150);

   line(340,100,340,150);

   line(240,150,210,150);

   line(340,150,380,150);

   line(240,100,210,100);

   line(340,100,380,100);

   line(210,150,210,120);

   line(210,120,200,110);

   line(380,150,380,120);

   line(380,120,390,110);

   arc(210,110,90,180,10);

   arc(380,110,0,93,10);

   line(230,150,230,202);

   line(350,200,350,150);

   line(250,160,250,190);

   line(250,190,280,190);

   line(250,160,240,150);

   line(250,160,260,150);

   line(289,200,330,200);

   rectangle(180,250,190,260);

   rectangle(380,250,390,260);

   rectangle(278,33,303,40);

   ellipse(185,265,0,360,10,5);

   ellipse(385,265,0,360,10,5);

   line(270,90,310,90);

   line(270,94,310,94);

   line(270,100,270,90);

   line(310,100,310,90);

   line(270,124,260,120);

   line(270,125,260,120);

   line(270,126,260,120);

   line(270,127,260,120);

   line(310,124,320,120);

   line(310,125,320,120);

   line(310,126,320,120);

   line(310,127,320,120);

   /*Eyebrose*/

   arc(265,125,40,80,10);

   arc(315,125,100,140,10);

   line(40,400,80,400);

   line(480,400,520,400);

   line(480,400,500,360);

   line(520,400,500,360);

   line(40,400,60,360);

   line(80,400,60,360);

   while(!kbhit()){

   for(i=1;i<=3;i++){

delay(100);

   setcolor(rand()%15);

   circle(290,45,i*1);

   }

   for(i=1;i<=2;i++){

delay(100);

   setcolor(rand()%15);

   circle(290,36,i*1);

   }

   for(i=1;i<=8;i++){

   delay(100);

   setcolor(rand()%15);

   circle(290,60,i*1);

   }

   for(i=1;i<=28;i++){

   delay(100);

   setcolor(rand()%15);

   circle(100,100,i*1);

   }

   for(i=1;i<=28;i++){

   delay(100);

   setcolor(rand()%15);

   circle(490,100,i*1);

   }

   for(i=1;i<=4;i++){

   delay(100);

   setcolor(rand()%15);

   circle(210,185,i*1);

   }

   for(i=1;i<=5;i++){

   setcolor(rand()%15);

   line(60,360,70,300);

   line(60,360,50,300);

setcolor(rand()%15);

   line(60,360,55,300);

   line(60,360,65,300);

   setcolor(rand()%15);

   line(65,300,68,260);

   line(55,300,52,260);

setcolor(rand()%15);

   line(70,300,73,260);

   line(50,300,47,260);

setcolor(rand()%15);

   line(60,360,60,260);

   line(68,260,72,240);

setcolor(rand()%15);

   line(52,260,48,240);

   line(60,260,60,250);

setcolor(rand()%15);

   line(65,260,69,240);

   line(55,260,51,240);

setcolor(rand()%15);

   line(53,260,49,240);

   line(500,360,510,300);

setcolor(rand()%15);

   line(500,360,490,300);

   line(500,360,505,300);

setcolor(rand()%15);

   line(500,360,495,300);

   line(500,360,500,300);

   setcolor(rand()%15);

   line(500,300,500,252);

   line(495,300,492,260);

setcolor(rand()%15);

   line(505,300,508,260);

   line(490,300,487,260);

setcolor(rand()%15);

   line(510,300,513,260);

   line(492,260,489,240);

setcolor(rand()%15);

   line(489,260,486,240);

   line(505,260,507,240);

   setcolor(rand()%15);

   line(507,260,509,240);

   putpixel(rand()%640,rand()%400,15);

   }

   for(i=1;i<=4;i++){

   delay(100);

   setcolor(rand()%15);

   circle(210,185,i*1);

   }

/*      for(i=j;i<5000;i+=10)

      {

         sound(i);

         delay(10);

      }*/

      j=j+50;



   }

/*   nosound();*/

   setcolor(WHITE);

   settextstyle(1,HORIZ_DIR,6);

   outtextxy(175,300,"GANESH");

   settextstyle(1,HORIZ_DIR,3);

   outtextxy(500,450,"Aditya");

   getch();

}

[Lập trình đồ họa máy tính cơ bản] Vẽ hình cơ bản

Vẽ hình ngôi sao bằng C++

Tạo màu ngẫu nhiên từ 1 đến 15, ta có đoạn code sau:

#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <time.h>
int main(){
    initwindow(800,600);
    srand((unsigned int) time(0));
    int t=0;
    while (1){
        for(int i=0;i<300;i=i+10){
            while (t==0)
                t = rand()%16;
            setcolor(t);
            line(100,100+i,500,100+i);
            delay(100);
            t=0;
        }
    }
    getch();
    return 0;
}


Cách sử dụng hàm setbkcolor trong thư viện WinBGIm là phải sử dụng liên tục 2 câu lệnh setbkcolor(mau) và cleardevice().

Hàm settextstyle(font_chữ,hướng,kích_cỡ) dùng để thiết lập font chữ (0-10), hướng (trái sang phải - 0, dưới lên trên - 1) và cỡ chữ.



#include <stdio.h>
#include <graphics.h>
int main(){
    initwindow(500,300);
    setbkcolor(GREEN);
    cleardevice();
    settextstyle(10,0 ,5);
    moveto(50,100);
    outtext("Xin chao TH9");
    int maxx = getmaxx();//499
    int maxy = getmaxy();//299
    printf("%d  %d",maxx,maxy);
    int x = getx();//350
    int y = gety();//100
    printf("\n%d %d\n",x,y);
    getch();
    return 0;
}

Vẽ ngôi sao quay bằng cách sử dụng cấu trúc accoordstype và getarccoords:



#include <graphics.h>
#include <conio.h>
#include <stdio.h>
int main(){
    initwindow(800,600);
    arccoordstype a;
    int g = 0;
    int c = 1;
    int gtang = 144;
    while (1){ //lap vo tan
        int gt = g;
        for(int i=0;i<5;i++){
            setcolor(BLACK);
            arc(400,300, gt,gt+gtang,200);
            getarccoords(&a);
            setcolor(c);
            line(a.xstart,a.ystart,a.xend,a.yend);
            gt=gt+gtang;
        }
        g+=5; //tang goc bat dau len 5 sau moi lan ve
        delay(100);
        c++;
        if (c==16)// mau thay doi nhung k vuot qua gioi han
            c=1;
        if (g==360) //goc tang nhung k vuot qua gioi han
            g=0;
        cleardevice();//xoa man hinh
    }
    getch();
}

[Lập trình đồ họa máy tính cơ bản] Vẽ hoa văn

Vẽ hoa văn -tinhoccoban.net
Vẽ hoa văn bằng ngôn ngữ C/C++


Hàm Arc, vẽ bông hoa



#include 
#include 
#include 

void VeBongHoa(int x,int y, int r){
    arc(x,y-r,180,360,r);
    arc(x,y+r,0,180,r);
    arc(x-r,y,270,90,r);
    arc(x+r,y,90,270,r);
}
int main(){
    initwindow(800,600);
    intx =400,y=300, r = 200;
    while(r>0){
        VeBongHoa(x,y,r);
        r=r-5;
        delay(200);
    }
    getch();
    return 0;
}








Hàm ellipse vẽ cung elip

#include 

#include 

#include 



int main(){

    initwindow(800,600);

    int x = 400,y=300, r = 200;

    ellipse(x,y,0,360,150,200);

    ellipse(x,y,0,360,200,150);

    getch();

    return 0;

}



Vẽ bàn cờ vua có hoa văn trên từng ô

#include 
#include 
#include 
int c = 50;
int r = c/2;
void VeO(int x,int y,int i){
    if (i%2==0){
        setcolor(BLUE);
        setfillstyle(1,WHITE);
    }
    else{
        setfillstyle(1,RED);
        setcolor(LIGHTGREEN);
    }
    bar(x,y,x+c,y+c);

   /* arc(x+r,y,180,0,r);
    arc(x,y+r,270,90,r);
    arc(x+r,y+r+r,0,180,r);
    arc(x+r+r,y+r,90,270,r);
    */
      arc(x,y,270,0 ,r);
    arc(x+c,y+c,90,180 ,r);
    arc(x,y+c,0,90,r);
    arc(x+c,y,180,270,r);
    circle(x+c/2,y+c/2,r);

}
int main(){
    initwindow(400,400);
    int x=0,y=0;
    int k = 0;
    for(int i=0;i<=7;i++)
     for(int j=0;j<=7;j++)
      VeO(x+i*c,y+j*c,i*7+j);
    getch();
    return 0;
}




Tô màu bằng hàm floodfill và vẽ đa giác bằng hàm drawpoly (fillpoly)

#include 
#include 
#include 

int main(){
    initwindow(800,600);
    setcolor(13);
    circle(400,300,100);
    setfillstyle(1,4);
    floodfill(400,300,13);
    int n = 4;
    int a[]={100,100,300,400,200,100,100,100};

    setcolor(12);
    drawpoly(n,a);
    setfillstyle(8,15);
    floodfill(120,120,12);
    getch();
    return 0;


}
 


Bài đăng phổ biến

Bài viết mới nhất

Tin học cơ bản - Nền tảng của mọi kỹ năng

Mọi thông tin trên blog đều được giữ bản quyền bởi Tin học cơ bản. Các bạn nếu muốn lấy thông tin từ blog vui lòng ghi rõ nguồn Tinhoccoban.net

TIN HỌC CƠ BẢN