ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
GlitchX.cpp
Go to the documentation of this file.
1#include "GlitchX.h"
2
3GlitchX::GlitchX(uint8_t pixels) : pixels(pixels) {}
4
6 RGBColor* pixelColors = pixelGroup->GetColors();
7 RGBColor* colorBuffer = pixelGroup->GetColorBuffer();
8
9 for (uint16_t i = 0; i < pixelGroup->GetPixelCount(); i++) {
10 uint16_t index = i;
11 uint16_t tIndex = 0;
12 bool valid = true;
13 int blurRange = Mathematics::Map(ratio, 0.0f, 1.0f, 1.0f, float(pixels / 2));
14 int randX = random(-blurRange, blurRange);
15 int randSkip = random(1, blurRange);
16
17 valid = pixelGroup->GetOffsetXIndex(index, &tIndex, randX);
18
19 for (int j = 0; j < randSkip; j++) {
20 if (randSkip < blurRange / 2 && valid) {
21 colorBuffer[i].R = (uint16_t)pixelColors[tIndex].B;
22 colorBuffer[i].G = (uint16_t)pixelColors[tIndex].R;
23 colorBuffer[i].B = (uint16_t)pixelColors[tIndex].G;
24 } else if (valid) {
25 colorBuffer[i].R = (uint16_t)pixelColors[tIndex].R;
26 colorBuffer[i].G = (uint16_t)pixelColors[tIndex].G;
27 colorBuffer[i].B = (uint16_t)pixelColors[tIndex].B;
28 } else {
29 colorBuffer[i].R = 0;
30 colorBuffer[i].B = 0;
31 colorBuffer[i].G = 0;
32 }
33
34 if (j > 0) i++;
35
36 if (i >= pixelGroup->GetPixelCount()) break;
37 }
38 }
39
40 for (uint16_t i = 0; i < pixelGroup->GetPixelCount(); i++) {
41 pixelColors[i].R = colorBuffer[i].R;
42 pixelColors[i].G = colorBuffer[i].G;
43 pixelColors[i].B = colorBuffer[i].B;
44 }
45}
Defines the GlitchX effect class for applying glitch effects along the X-axis to pixel groups.
float ratio
A scaling ratio used for dynamic effect adjustments.
Definition Effect.h:28
GlitchX(uint8_t pixels)
Constructs a GlitchX effect with a specified number of pixels.
Definition GlitchX.cpp:3
void ApplyEffect(IPixelGroup *pixelGroup) override
Applies the glitch effect along the X-axis to the given pixel group.
Definition GlitchX.cpp:5
const uint8_t pixels
The number of pixels to distort.
Definition GlitchX.h:28
Interface for managing and interacting with a collection of pixels.
Definition IPixelGroup.h:25
virtual RGBColor * GetColors()=0
Retrieves the array of colors for the pixel group.
virtual RGBColor * GetColorBuffer()=0
Retrieves the color buffer for the pixel group.
virtual uint16_t GetPixelCount()=0
Retrieves the total number of pixels in the group.
virtual bool GetOffsetXIndex(uint16_t count, uint16_t *index, int x1)=0
Retrieves an offset X-axis index for a given pixel.
static T Map(T value, T inLow, T inMax, T outMin, T outMax)
Maps a value from one range to another.
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
uint8_t B
Blue component of the color (0-255).
Definition RGBColor.h:27
uint8_t G
Green component of the color (0-255).
Definition RGBColor.h:26
uint8_t R
Red component of the color (0-255).
Definition RGBColor.h:25