summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-05-15 01:56:06 +0200
committerdec05eba <dec05eba@protonmail.com>2021-05-15 01:56:06 +0200
commitcd05828923f5241b1d71ad211cce5c8605de38fd (patch)
tree6b3eb544e41f4d12a88ec56e0d34e3726c941b66
lole
-rw-r--r--.gitignore6
-rw-r--r--flag.glsl21
-rw-r--r--flag.pngbin0 -> 92398 bytes
-rw-r--r--project.conf8
-rw-r--r--src/main.cpp65
-rw-r--r--tests/main.cpp7
6 files changed, 107 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7cbd65d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+# Compiled sibs files
+sibs-build/
+compile_commands.json
+tests/sibs-build/
+tests/compile_commands.json
+frames/
diff --git a/flag.glsl b/flag.glsl
new file mode 100644
index 0000000..f52c2f2
--- /dev/null
+++ b/flag.glsl
@@ -0,0 +1,21 @@
+uniform sampler2D texture;
+uniform float iTime;
+
+void main() {
+ vec2 uv = gl_TexCoord[0].xy;
+ float sine = sin(uv.x*24.0 - iTime*7.0);
+ float offset = sine*0.04;
+ uv.x -= 0.25;
+ uv.x += offset*0.5*uv.x;
+ uv.y += offset*uv.x*2.0 - 0.25;
+
+ vec4 col = texture2D(texture, uv*2.0);
+ //col.rgb *= (1.0 + (0.0 + 0.5*(offset+0.04)*50.0));
+ col.rgb *= 0.9;
+ col.rgb += 0.1 * -sine;
+
+ if(uv.x < 0.0 || uv.x > 0.5 || uv.y < 0.0 || uv.y > 0.5)
+ col.a = 0.0;
+
+ gl_FragColor = col;
+} \ No newline at end of file
diff --git a/flag.png b/flag.png
new file mode 100644
index 0000000..0564dec
--- /dev/null
+++ b/flag.png
Binary files differ
diff --git a/project.conf b/project.conf
new file mode 100644
index 0000000..0c86cd9
--- /dev/null
+++ b/project.conf
@@ -0,0 +1,8 @@
+[package]
+name = "flag-maker"
+type = "executable"
+version = "0.1.0"
+platforms = ["posix"]
+
+[dependencies]
+sfml-graphics = "2"
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..5876efc
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,65 @@
+#include <SFML/Graphics.hpp>
+
+int main() {
+ sf::Texture texture;
+ if(!texture.loadFromFile("flag.png"))
+ return 1;
+
+ texture.setSmooth(true);
+
+ sf::Vector2u window_size = texture.getSize();
+ sf::RenderWindow window(sf::VideoMode(window_size.x, window_size.y), "SFML works!", 0);
+ window.setVerticalSyncEnabled(true);
+ window.setFramerateLimit(24);
+
+ sf::Shader shader;
+ if(!shader.loadFromFile("flag.glsl", sf::Shader::Type::Fragment))
+ return 1;
+
+ shader.setUniform("texture", texture);
+
+ sf::Vertex vertex[4];
+ vertex[0] = sf::Vertex(sf::Vector2f(0.0f, 0.0f), sf::Color::White, sf::Vector2f(0.0f, 0.0f));
+ vertex[1] = sf::Vertex(sf::Vector2f(window_size.x, 0.0f), sf::Color::White, sf::Vector2f(1.0f, 0.0f));
+ vertex[2] = sf::Vertex(sf::Vector2f(window_size.x, window_size.y), sf::Color::White, sf::Vector2f(1.0f, 1.0f));
+ vertex[3] = sf::Vertex(sf::Vector2f(0.0f, window_size.y), sf::Color::White, sf::Vector2f(0.0f, 1.0f));
+
+ sf::Texture texture_output;
+ texture_output.create(texture.getSize().x, texture.getSize().y);
+
+ int flag_start_x = texture.getSize().x*0.2;
+ int flag_start_y = texture.getSize().y*0.2;
+ int flag_width = texture.getSize().x*0.6;
+ int flag_height = texture.getSize().y*0.6;
+
+ sf::Image output_image;
+ output_image.create(flag_width, flag_height, sf::Color::Transparent);
+ std::vector<sf::Image> frames;
+
+ sf::Clock timer;
+ while (window.isOpen()) {
+ sf::Event event;
+ while (window.pollEvent(event)) {
+ if (event.type == sf::Event::Closed)
+ window.close();
+ }
+
+ shader.setUniform("iTime", timer.getElapsedTime().asSeconds());
+ window.clear(sf::Color::Transparent);
+ window.draw(vertex, 4, sf::PrimitiveType::Quads, &shader);
+ window.display();
+
+ texture_output.update(window);
+ sf::Image image = texture_output.copyToImage();
+ output_image.copy(image, 0, 0, sf::IntRect(flag_start_x, flag_start_y, flag_width, flag_height), false);
+ frames.push_back(std::move(output_image));
+ }
+
+ system("rm -rf frames/*; mkdir frames");
+ for(size_t i = 0; i < frames.size(); ++i) {
+ frames[i].saveToFile("frames/" + std::to_string(i) + ".png");
+ }
+ system("ffmpeg -i \"frames/%d.png\" -framerate 24 -filter_complex \"fps=24,split=2[palette_in][gif];[palette_in]palettegen[palette_out];[gif]fifo[gif_fifo]; [gif_fifo][palette_out]paletteuse\" -y frames/output.gif");
+
+ return 0;
+} \ No newline at end of file
diff --git a/tests/main.cpp b/tests/main.cpp
new file mode 100644
index 0000000..9ad80a6
--- /dev/null
+++ b/tests/main.cpp
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+ printf("hello, world!\n");
+ return 0;
+}