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