-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
54 lines (46 loc) · 1.49 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
#include <sil/sil.hpp>
#include <iostream>
#include <vector>
#include <algorithm>
#include "random.hpp"
float brightness(glm::vec3 &color)
{
return (color.r + color.g + color.b);
}
void getRectangle(sil::Image &image)
{
std::vector<glm::vec3> table;
glm::vec2 inputPositionStart{random_int(0, image.width()), random_int(0, image.height())};
glm::vec2 rectangleSize{random_int(20, 30), 1};
for (int i{0}; i < rectangleSize.x; i++)
{
for (int j{0}; j < rectangleSize.y; j++)
{
if (inputPositionStart.x + i < image.width() &&
inputPositionStart.y + j < image.height())
table.push_back(image.pixel(inputPositionStart.x + i, inputPositionStart.y + j));
}
}
std::sort(table.begin(), table.end(), [](glm::vec3 &color1, glm::vec3 &color2)
{ return brightness(color1) < brightness(color2); });
int count{0};
for (int i{0}; i < rectangleSize.x; i++)
{
for (int j{0}; j < rectangleSize.y; j++)
{
if (inputPositionStart.x + i < image.width() &&
inputPositionStart.y + j < image.height())
{
image.pixel(inputPositionStart.x + i, inputPositionStart.y + j) = table[count];
count++;
}
}
}
}
int main()
{
sil::Image image{"images/logo.png"};
for (int i{0}; i < 1000; i++)
getRectangle(image);
image.save("output/pouet.png");
}