StepGradient.cs

Go to the documentation of this file.
00001 /*
00002 NPlot - A charting library for .NET
00003 
00004 StepGradient.cs
00005 Copyright (C) 2004
00006 Matt Howlett
00007 
00008 Redistribution and use of NPlot or parts there-of in source and
00009 binary forms, with or without modification, are permitted provided
00010 that the following conditions are met:
00011 
00012 1. Re-distributions in source form must retain at the head of each
00013    source file the above copyright notice, this list of conditions
00014    and the following disclaimer.
00015 
00016 2. Any product ("the product") that makes use NPlot or parts 
00017    there-of must either:
00018   
00019     (a) allow any user of the product to obtain a complete machine-
00020         readable copy of the corresponding source code for the 
00021         product and the version of NPlot used for a charge no more
00022         than your cost of physically performing source distribution,
00023         on a medium customarily used for software interchange, or:
00024 
00025     (b) reproduce the following text in the documentation, about 
00026         box or other materials intended to be read by human users
00027         of the product that is provided to every human user of the
00028         product: 
00029    
00030               "This product includes software developed as 
00031               part of the NPlot library project available 
00032               from: http://www.nplot.com/" 
00033 
00034         The words "This product" may optionally be replace with 
00035         the actual name of the product.
00036 
00037 ------------------------------------------------------------------------
00038 
00039 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00040 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00041 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00042 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00043 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00044 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00045 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00046 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00047 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00048 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00049 
00050 */
00051 
00052 using System;
00053 using System.Drawing;
00054 
00055 namespace NPlot
00056 {
00060         public class StepGradient : IGradient
00061         {
00062 
00066                 public enum Type
00067                 {
00071                         Rainbow,
00072 
00076                         RGB
00077                 }
00078 
00082                 public Type StepType
00083                 {
00084                         get
00085                         {
00086                                 return stepType_;
00087                         }
00088                         set
00089                         {
00090                                 stepType_ = value;
00091                         }
00092                 }
00093                 Type stepType_ = Type.RGB;
00094 
00095 
00099                 public StepGradient()
00100                 {
00101                 }
00102 
00103 
00108                 public StepGradient( Type stepType )
00109                 {
00110                         stepType_  = stepType;
00111                 }
00112 
00119                 public Color GetColor( double prop )
00120                 {
00121                         switch (stepType_)
00122                         {
00123                                 case Type.RGB:
00124                                 {
00125                                         if (prop < 1.0/3.0) return Color.Red;
00126                                         if (prop < 2.0/3.0) return Color.Green;
00127                                         return Color.Blue;
00128                                 }
00129                                 case Type.Rainbow:
00130                                 {
00131                                         if (prop < 0.125) return Color.Red;
00132                                         if (prop < 0.25) return Color.Orange;
00133                                         if (prop < 0.375) return Color.Yellow;
00134                                         if (prop < 0.5) return Color.Green;
00135                                         if (prop < 0.625) return Color.Cyan;
00136                                         if (prop < 0.75) return Color.Blue;
00137                                         if (prop < 0.825) return Color.Purple;
00138                                         return Color.Pink;
00139                                 }
00140                                 default:
00141                                 {
00142                                         return Color.Black;
00143                                 }
00144                         }
00145 
00146                 }
00147 
00148         } 
00149 }

Generated on Sat Nov 5 01:04:06 2005 for NPlot by  doxygen 1.4.5