Example 4: Lighting/Blur effect
using System;
using odl;
namespace TestNamespace
{
class Program
{
public static void Main(string[] args)
{
Graphics.Start();
Window win = new Window();
win.Initialize(true, true);
Viewport vp = new Viewport(0, 0, win.Width, win.Height);
Sprite s = new Sprite(vp);
win.Show();
bool down = false;
int radius = 1;
while (Graphics.CanUpdate())
{
s.Bitmap?.Dispose();
s.Bitmap = GenerateLighting(Color.RED, radius);
s.X = vp.Width / 2 - s.Bitmap.Width / 2;
s.Y = vp.Height / 2 - s.Bitmap.Height / 2;
radius += down ? -2 : 2;
if (radius >= 240) down = true;
else if (radius <= 2) down = false;
Graphics.Update(false, true);
}
if (!vp.Disposed) vp.Dispose();
Graphics.Stop();
}
public static Bitmap GenerateLighting(Color c, int Radius)
{
Bitmap bmp = new Bitmap(Radius * 2 + 1, Radius * 2 + 1);
bmp.Unlock();
int mid = Radius;
for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
double dist = Math.Sqrt(Math.Pow(x - mid, 2) + Math.Pow(y - mid, 2));
if (dist >= Radius) continue;
double fraction = 1 - dist / Radius;
bmp.SetPixel(x, y, c.Red, c.Green, c.Blue, Convert.ToByte(255 * fraction));
}
}
bmp.Lock();
return bmp;
}
}
}
Last updated