Thứ Hai, 5 tháng 6, 2017

Vẽ một số hình khối.

1. Vẽ viên gạch.
 

     Video ý tưởng:


     Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include "graphics.h"
#include <time.h>
#pragma comment(lib,"graphics.lib")

#define iCOLOR COLOR(238,38,48)
#define iCOLOR_DAM COLOR(214,16,26);
#define iCOLOR_NHAT COLOR(241,73,82);

void drawBrick(int x, int y, int size)
{
 size--;
 //rgb
 int a[10];
 int color;
 int Denta = size / 9; // Phan chenh lech giua phan ngoai va phan trong
 color = iCOLOR_DAM;
 setcolor(color);   // Thiet dat mau cho vien 
 setfillstyle(SOLID_FILL, color);  // Thiet dat mau cho van o trong hinh ve
 a[0] = x;
 a[1] = y;
 a[2] = x;
 a[3] = y + size;
 a[4] = x + size;
 a[5] = y + size;
 // Khong can hai dong nay
 // De xu dung ham fillpoly ta can toa do cac diem, luu trong mang
 fillpoly(3, a); // Ve tam giac
 color = iCOLOR_NHAT;
 setcolor(color);
 setfillstyle(SOLID_FILL, color);
 a[0] = x;
 a[1] = y;
 a[2] = x + size;
 a[3] = y;
 a[4] = x + size;
 a[5] = y + size;
 fillpoly(3, a); //Tuong tu  ve tam giac
 color = iCOLOR;
 setcolor(color);
 setfillstyle(SOLID_FILL, color);
 bar(x + Denta + 1, y + Denta + 1, x + size - Denta, y + size - Denta); // Ve hinh vuong o trong
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevIstance, LPSTR lpCmdLine, int nCmdShow)
{
 initwindow(400, 400, "Test Brick", 100, 100);
 drawBrick(100, 100, 100);
 while (!kbhit())
 {

 }
 closegraph();
 return 0;
}

2. Updating.....


Rất vui nhận được sự đóng góp của các bạn !!!!

Không có nhận xét nào:

Đăng nhận xét