Greyscale bars/Display: Difference between revisions
Content added Content deleted
(→{{header|C}}: Adding C# Version) |
(→{{header|C sharp|C#}}: removing some repetition from c# version) |
||
Line 257: | Line 257: | ||
using System.Drawing; |
using System.Drawing; |
||
using System.Windows.Forms; |
using System.Windows.Forms; |
||
static class Program |
static class Program { static void Main() { Application.Run(new FullScreen()); } } |
||
{ |
|||
static void Main() |
|||
{ |
|||
Application.Run(new FullScreen()); |
|||
} |
|||
} |
|||
public sealed class FullScreen : Form |
public sealed class FullScreen : Form |
||
{ |
{ |
||
const int ColorCount = 256; |
|||
public FullScreen() |
public FullScreen() |
||
{ |
{ |
||
Line 273: | Line 268: | ||
BackgroundImage = ColorBars(Screen.FromControl(this).Bounds); |
BackgroundImage = ColorBars(Screen.FromControl(this).Bounds); |
||
} |
} |
||
private static Bitmap ColorBars(Rectangle |
private static Bitmap ColorBars(Rectangle size) |
||
{ |
{ |
||
var colorBars = new Bitmap(size.Width, size.Height); |
|||
Func<int, int, int> forwardColor = (x, divs) => (int)(x * ((float)divs / size.Width)) * ColorCount / divs; |
|||
var colorBars = new Bitmap(width, height); |
|||
Func<int, int, int> reverseColor = (x, divs) => ColorCount - 1 - forwardColor(x, divs); |
|||
var colorLimit = 256; |
|||
⚫ | |||
int stripeHeight = height/4; |
|||
Action<int, int, int> setForward = (x, y, divs) => setGray(x, y, forwardColor(x, divs)); |
|||
Action<int, int, int> setReverse = (x, y, divs) => setGray(x, y, reverseColor(x, divs)); |
|||
int verticalStripe = size.Height / 4; |
|||
⚫ | |||
{ |
{ |
||
int |
for (int y = 0; y < verticalStripe; y++) setForward(x, y, 8); |
||
⚫ | |||
Func<int> forwardColor = () => x/(width/divisions)*(colorLimit/divisions); |
|||
for (int y = verticalStripe * 2; y < verticalStripe * 3; y++) setForward(x, y, 32); |
|||
for (int y = verticalStripe * 3; y < verticalStripe * 4; y++) setReverse(x, y, 64); |
|||
⚫ | |||
⚫ | |||
divisions = 16; |
|||
⚫ | |||
divisions = 32; |
|||
for (int y = stripeHeight*2; y < stripeHeight*3; y++) setForward(y); |
|||
divisions = 64; |
|||
for (int y = stripeHeight*3; y < stripeHeight*4; y++) setReverse(y); |
|||
} |
} |
||
return colorBars; |
return colorBars; |