我正在处理亚音速喷嘴模拟器,因为我想根据函数中获得的值来绘制喷嘴的不同部分,因此遇到了麻烦。我不知道要用ColorMap来实现,因此我做了一个函数,该函数返回一系列值的10种颜色。
下面是我使用的代码,但我想将此代码更改为ColorMap代码。
这是返回颜色的功能
公共字符串ColorCeldaMach(double Mach) {
if (Mach > 1.05)
color = "Black";
if (Mach <= 1.05 && Mach > 1.00875)
color = "Firebrick";
if (Mach <= 1.00875 && Mach > 0.9675)
color = "Red";
if (Mach <= 0.9675 && Mach > 0.92625)
color = "Orange";
if (Mach <= 0.92625 && Mach > 0.885)
color = "Yellow";
if (Mach <= 0.885 && Mach > 0.84375)
color = "Green";
if (Mach <= 0.84375 && Mach > 0.8025)
color = "Cyan";
if (Mach <= 0.8025 && Mach > 0.76125)
color = "Blue";
if (Mach <= 0.76125 && Mach > 0.72)
color = "Purple";
if (Mach <= 0.72 && Mach > 0)
color = "Indigo";
return this.color;
}
这是主窗口中的代码:
for (int j = 0; j < columns; j++)
{
System.Windows.Controls.Label lbl = new System.Windows.Controls.Label();
lbl.Height = Areas[j] * 30;
lbl.Width = rejilla.Width / columns;
// Este tag nos permitira identificar la celda cuando cliquemos en ella
lbl.Tag = new Point(1, j); //Para poder identificarlo posteriormente
// Definimos las caracteristicas del borde de la celda
lbl.BorderBrush = new SolidColorBrush(Colors.Gray);
lbl.BorderThickness = new Thickness(1);
lbl.Background = (Brush)new BrushConverter().ConvertFromString(nozzleQ1D.ColorCeldaDensidad(Density[j]));
// Añadimos la etiqueta a la fila
stkPanel.Children.Add(lbl);
}
// Añadimos la fila a la rejilla
rejilla.Children.Add(stkPanel);