Skip to content

Commit

Permalink
Renamed the Hue Gradient glitch type to Hue Gradient Random. Added a …
Browse files Browse the repository at this point in the history
…new glitch type: Hue Gradient Random
  • Loading branch information
Robson committed Jul 14, 2020
1 parent c39ce1b commit 87e06d2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
3 changes: 2 additions & 1 deletion GlitchGenerator/Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ internal static List<Glitch> GetAllGlitches()
new Glitch("Horizontal Freeze", "Random", Glitches.HorizontalFreezeRandom),
new Glitch("Horizontal Freeze", "Waves Bumpy", Glitches.HorizontalFreezeWavesBumpy),
new Glitch("Horizontal Freeze", "Waves Smooth", Glitches.HorizontalFreezeWavesSmooth),
new Glitch("Hue", "Gradient", Glitches.HueGradient),
new Glitch("Hue", "Gradient Rainbow", Glitches.HueGradientRainbow),
new Glitch("Hue", "Gradient Random", Glitches.HueGradientRandom),
new Glitch("Hue", "Luminosity", Glitches.HueLuminosity),
new Glitch("Hue", "Shift", Glitches.HueShift),
new Glitch("Hue", "Unify", Glitches.HueUnify),
Expand Down
29 changes: 27 additions & 2 deletions GlitchGenerator/Glitches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,40 @@ internal static Bitmap HorizontalFreezeWavesSmooth(Bitmap bitmap)
return HorizontalFrozenWaves(bitmap, isSmooth: true);
}

internal static Bitmap HueGradient(Bitmap bitmap)
internal static Bitmap HueGradientRainbow(Bitmap bitmap)
{
var graphics = Graphics.FromImage(bitmap);
var offset = RNG.Random.Next(360);
var direction = RNG.Random.NextDouble() > 0.5 ? 1 : -1;
for (int y = 0; y < bitmap.Height; y++)
{
for (int x = 0; x < bitmap.Width; x++)
{
var randomHue = (offset + (int)(360f * ((float)x / (float)bitmap.Width))) % 360;
var randomHue = (offset + (direction * (int)(360f * ((float)x / (float)bitmap.Width)))) % 360;

var colour = bitmap.GetPixel(x, y);
var hsb = ColourConverter.RGBtoHSB(new ColourConverter.RGB() { R = colour.R, G = colour.G, B = colour.B });
hsb.H = randomHue;
var rgb = ColourConverter.HSBtoRGB(hsb);
var newColour = Color.FromArgb(rgb.R, rgb.G, rgb.B);
graphics.FillRectangle(new SolidBrush(newColour), new Rectangle(x, y, 1, 1));
}
}

return bitmap;
}

internal static Bitmap HueGradientRandom(Bitmap bitmap)
{
var graphics = Graphics.FromImage(bitmap);
var start = RNG.Random.Next(360);
var amount = RNG.Random.Next(360);
var direction = RNG.Random.NextDouble() > 0.5 ? 1 : -1;
for (int y = 0; y < bitmap.Height; y++)
{
for (int x = 0; x < bitmap.Width; x++)
{
var randomHue = (360 + start + (direction * (int)(amount * ((float)x / (float)bitmap.Width)))) % 360;

var colour = bitmap.GetPixel(x, y);
var hsb = ColourConverter.RGBtoHSB(new ColourConverter.RGB() { R = colour.R, G = colour.G, B = colour.B });
Expand Down
4 changes: 2 additions & 2 deletions GlitchGenerator/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]

0 comments on commit 87e06d2

Please sign in to comment.