Registriert seit: 10. Jun 2004
Ort: Garching (TUM)
4.579 Beiträge
|
Re: Verlauf mit "gewichteter" Farbe mittels Log?
4. Apr 2009, 14:31
Ich hätte da auch was im Angebot
Code:
namespace Test_1
{
public partial class Form1 : Form
{
double potenz;
Color col1;
Color col2;
public Form1()
{
InitializeComponent();
col1 = Color.Red;
col2 = Color.Blue;
potenz = 1;
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
double pos = 0;
double amount = 0;
Color tempColor;
Pen myPen = new Pen(col1);
for (int i = 0; i < pictureBox1.Width; i++)
{
pos = (double)i / (pictureBox1.Width - 1);
amount = 1 - Math.Pow(pos, potenz);
// 1 - Weil wir den Betrag der ersten Farbe haben wollen
tempColor = MixColors(col1, col2, amount);
myPen.Color = tempColor;
e.Graphics.DrawLine(myPen, new Point(i, 0), new Point(i, pictureBox1.Height - 1));
}
}
private Color MixColors(Color col1, Color col2, double amount)
{
if (amount < 0 || amount > 1)
throw new ArgumentOutOfRangeException("amount");
byte R = (byte)(col1.R * amount + col2.R * (1 - amount));
byte G = (byte)(col1.G * amount + col2.G * (1 - amount));
byte B = (byte)(col1.B * amount + col2.B * (1 - amount));
return Color.FromArgb(R, G, B);
}
private void trackBar1_ValueChanged(object sender, EventArgs e)
{
potenz = Math.Pow(1.1, trackBar1.Value);
label1.Text = String.Format("Potenz: {0:F3}", potenz);
pictureBox1.Invalidate();
}
}
}
|
|
Zitat
|