-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitmap.h
88 lines (83 loc) · 2.35 KB
/
bitmap.h
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef _BITMAP_H_
#define _BITMAP_H_
#include <iostream>
#include "bitmapbase.h"
using namespace std;
class Bitmap: public BitmapBase{
public:
Bitmap(int x,int y){
xSize=x;
ySize=y;
image = new unsigned char[3*xSize*ySize];
};
~Bitmap(){delete[] image;}
void drawSolidTriangle(const Point& ref, int left, int right, int height, const RGB& c, int m){
float l = left;
float h = height;
float r = right;
for(int i=-(l-1); i<0; i++){
for(float j=0; j<(h/l)*(i+l); j++){
int k = j;
Point a(i,k);
a+=ref;
this->setPixel(a,c,m);
}
}
for(int i=0; i<r; i++){
for(float j = (float)h-(h/r)*i; j>=0; j--){
int k = j;
Point a(i,k);
a+=ref;
this->setPixel(a,c,m);
}
}
};
void drawSolidRect(const Point& base, int width, int height, const RGB& c, int m){
for(int i=0; i<height; i++){
for(int j=0; j<width; j++){
Point a(j,i);
a+=base;
this->setPixel(a,c,m);
}
}
};
void drawSolidCircle(const Point& center, int radius, const RGB& c, int m){
int r = radius;
for(int i=-r; i<=0; i++){
for(int j=0; j<=sqrt(r*r-i*i); j++){
if(j==0){
Point a(i,j);
a+=center;
this->setPixel(a,c,m);
}
else{
Point a(i,j);
a+=center;
this->setPixel(a,c,m);
Point b(i,-j);
b+=center;
this->setPixel(b,c,m);
}
}
}
for(int i=1; i<=r; i++){
for(int j=0; j<=sqrt(r*r-i*i); j++){
if(j==0){
Point a(i,j);
a+=center;
this->setPixel(a,c,m);
}
else{
Point a(i,j);
a+=center;
this->setPixel(a,c,m);
Point b(i,-j);
b+=center;
this->setPixel(b,c,m);
}
}
}
};
private:
};
#endif