first commit

This commit is contained in:
stuce-bot 2025-06-30 20:47:33 +02:00
commit 5893b00dd2
1669 changed files with 1982740 additions and 0 deletions

View file

@ -0,0 +1,65 @@
#include "wave.h"
#include "FastLED.h"
DEFINE_GRADIENT_PALETTE(electricBlueFirePal){
0, 0, 0, 0, // Black
32, 0, 0, 70, // Dark blue
128, 20, 57, 255, // Electric blue
255, 255, 255, 255 // White
};
DEFINE_GRADIENT_PALETTE(electricGreenFirePal){
0, 0, 0, 0, // black
8, 128, 64, 64, // green
16, 255, 222, 222, // red
64, 255, 255, 255, // white
255, 255, 255, 255 // white
};
WaveFx::Args CreateArgsLower() {
WaveFx::Args out;
out.factor = SuperSample::SUPER_SAMPLE_2X;
out.half_duplex = true;
out.auto_updates = true;
out.speed = 0.18f;
out.dampening = 9.0f;
out.crgbMap = WaveCrgbGradientMapPtr::New(electricBlueFirePal);
return out;
}
WaveFx::Args CreateArgsUpper() {
WaveFx::Args out;
out.factor = SuperSample::SUPER_SAMPLE_2X;
out.half_duplex = true;
out.auto_updates = true;
out.speed = 0.25f;
out.dampening = 3.0f;
out.crgbMap = WaveCrgbGradientMapPtr::New(electricGreenFirePal);
return out;
}
WaveEffect NewWaveSimulation2D(const XYMap xymap) {
// only apply complex xymap as the last step after compositiing.
XYMap xy_rect =
XYMap::constructRectangularGrid(xymap.getWidth(), xymap.getHeight());
Blend2dPtr fxBlend =
NewPtr<Blend2d>(xymap); // Final transformation goes to the blend stack.
int width = xymap.getWidth();
int height = xymap.getHeight();
XYMap xyRect(width, height, false);
WaveFx::Args args_lower = CreateArgsLower();
WaveFx::Args args_upper = CreateArgsUpper();
WaveFxPtr wave_fx_low = NewPtr<WaveFx>(xy_rect, args_lower);
WaveFxPtr wave_fx_high = NewPtr<WaveFx>(xy_rect, args_upper);
Blend2dPtr blend_stack = NewPtr<Blend2d>(xymap);
blend_stack->add(wave_fx_low);
blend_stack->add(wave_fx_high);
WaveEffect out = {
.wave_fx_low = wave_fx_low,
.wave_fx_high = wave_fx_high,
.blend_stack = blend_stack,
};
return out;
}

View file

@ -0,0 +1,34 @@
#pragma once
#include "fx/2d/blend.h"
#include "fx/2d/wave.h"
#include "fx/fx2d.h"
#include "fl/raster.h"
using namespace fl;
struct WaveEffect {
WaveFxPtr wave_fx_low;
WaveFxPtr wave_fx_high;
Blend2dPtr blend_stack;
void draw(Fx::DrawContext context) { blend_stack->draw(context); }
void addf(size_t x, size_t y, float value) {
wave_fx_low->addf(x, y, value);
wave_fx_high->addf(x, y, value);
}
};
struct DrawRasterToWaveSimulator {
DrawRasterToWaveSimulator(WaveEffect* wave_fx) : mWaveFx(wave_fx) {}
void draw(const vec2<int> &pt, uint32_t index, uint8_t value) {
float valuef = value / 255.0f;
int xx = pt.x;
int yy = pt.y;
mWaveFx->addf(xx, yy, valuef);
}
WaveEffect* mWaveFx;
};
WaveEffect NewWaveSimulation2D(const XYMap xymap);

View file

@ -0,0 +1,41 @@
#include "fl/xypath.h"
#include "fl/vector.h"
#include "fl/map_range.h"
#include "xypaths.h"
using namespace fl;
namespace {
Ptr<CatmullRomParams> make_path(int width, int height) {
// make a triangle.
Ptr<CatmullRomParams> params = NewPtr<CatmullRomParams>();
vector_inlined<vec2f, 5> points;
points.push_back(vec2f(0.0f, 0.0f));
points.push_back(vec2f(width / 3, height / 2));
points.push_back(vec2f(width - 3, height - 1));
points.push_back(vec2f(0.0f, height - 1));
points.push_back(vec2f(0.0f, 0.0f));
for (auto &p : points) {
p.x = map_range<float, float>(p.x, 0.0f, width - 1, -1.0f, 1.0f);
p.y = map_range<float, float>(p.y, 0.0f, height - 1, -1.0f, 1.0f);
params->addPoint(p);
}
return params;
}
}
fl::vector<XYPathPtr> CreateXYPaths(int width, int height) {
fl::vector<XYPathPtr> out;
out.push_back(XYPath::NewCirclePath(width, height));
out.push_back(XYPath::NewRosePath(width, height));
out.push_back(XYPath::NewHeartPath(width, height));
out.push_back(XYPath::NewArchimedeanSpiralPath(width, height));
out.push_back(XYPath::NewPhyllotaxisPath(width, height));
out.push_back(XYPath::NewGielisCurvePath(width, height));
out.push_back(XYPath::NewCatmullRomPath(width, height, make_path(width, height)));
return out;
}

View file

@ -0,0 +1,10 @@
#include "fl/xypath.h"
#include "fl/vector.h"
using namespace fl;
// XYPath::NewRosePath(WIDTH, HEIGHT);
fl::vector<XYPathPtr> CreateXYPaths(int width, int height);