-
Notifications
You must be signed in to change notification settings - Fork 3
/
sample.cpp
44 lines (41 loc) · 1.09 KB
/
sample.cpp
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
#include "EasyBMP.hpp"
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
struct point
{
double x, y;
point(double _x, double _y) : x(_x), y(_y) { }
double distanceTo(const point& o) {
double dx = (x - o.x);
double dy = (y - o.y);
return sqrt(dx * dx + dy * dy);
}
};
int main()
{
vector< point > centers = {
{256, 256},
{192, 192}
};
vector< double > charges = {1024.0, 2048.0};
// R, G, B [0, 255]
EasyBMP::RGBColor black(0, 0, 0);
// sizeX, sizeY, FileName, BackgroundColor
EasyBMP::Image img(512, 512, "sample.bmp", black);
for (int y = 0; y < 512; ++y) {
for (int x = 0; x < 512; ++x) {
double intensity = 0.0;
for (int i = 0; i < 2; ++i) {
double dist = max(centers[i].distanceTo(point(x, y)), 1.0);
intensity += charges[i] / (dist * dist);
}
int final_color = min(255, int(255. * intensity));
// PositionX, PisitionY, Color
img.SetPixel(x, y, EasyBMP::RGBColor(final_color, final_color, 0));
}
}
img.Write();
return 0;
}