Flex RGB color gradient

Source: Internet
Author: User
ArticleDirectory
    • Uniform gradient
Uniform gradient

The following are theories:

Gradient is an important formal beauty law in aesthetics. It corresponds to a mutation. Shape, size, position, direction, color, and other visual factors can be gradient. In color, the color phase, brightness, and purity can also produce gradient effects, and will show a variety of aesthetic levels. This article describes the gradient of two color RGB values.Algorithm.

Known: A = 50, B = 200, A and B are evenly divided into three parts (step = 3), and the value of each part (stepn) is calculated respectively.

Formula:Gradient = a + (B-A)/step * n

[Note] in programming to improve efficiency to avoid floating point operations, division is often placed at the end of the formula: gradient = a + (B-A) * n/step

Step = 3, according to the formula can be obtained Step1 = a + (A-B)/3 *1= 50 + (200-50)/3 =100, Step 2 = a + (A-B)/3 *2= 50 + (200-50)/3*2 = 150. This is the principle of the even gradient algorithm. It is very simple, with primary knowledge.

The gradient of the two colors is calculated for the RGB channels of the two colors. For example, the two colors are RGB (50,200, 50, 0) and RGB (, 0 ), the above formula is used for calculation:

Rstep1 = Ra + (BA-RA)/step * n = 200 + (50-200)/3*1 = 200-50 =150

Gstep1 = Ga = GA + (GA-GA)/step * n = 50 + (200-50)/3*1 = 50 + 50 =100

Bstep1 = BA + (BA-BA)/step * n =0

Therefore, rgbstep1 = (150,100, 0). You can use the same method to obtain rgbstep2 = (100,150, 0 ).

CodeIn specific implementation, the GIS Raster traffic rendering I used here is divided into 5 gradient colors, according to the traffic volume of the raster, and then according to the traffic volume to gradient color

As shown below, the effect is not very obvious because only some test data is used. During full-grid rendering, it looks good. Currently, only 0 ~ 157 of the traffic seems obvious, which is also related to the contrast between the map background color:

 

Code

  VaR  Redarr: Array  =  New  Array ();
VaR Greenarr: Array = New Array ();
VaR Bluearr: Array = New Array ();

VaR Redarrend: Array = New Array ();
VaR Greenarrend: Array = New Array ();
VaR Bluearrend: Array = New Array ();

Redarr. Push ( 200 );
Greenarr. Push ( 218 );
Bluearr. Push ( 249 );
Redarrend. Push ( 0 );
Greenarrend. Push ( 0 );
Bluearrend. Push ( 255 );

Redarr. Push ( 165 );
Greenarr. Push ( 225 );
Bluearr. Push ( 250 );
Redarrend. Push ( 0 );
Greenarrend. Push ( 255 );
Bluearrend. Push ( 255 );

Redarr. Push ( 150 );
Greenarr. Push ( 206 );
Bluearr. Push ( 129 );
Redarrend. Push ( 0 );
Greenarrend. Push ( 255 );
Bluearrend. Push ( 0 );

Redarr. Push ( 183 );
Greenarr. Push ( 235 );
Bluearr. Push ( 116 );
Redarrend. Push ( 255 );
Greenarrend. Push ( 255 );
Bluearrend. Push ( 0 );

Redarr. Push ( 253 );
Greenarr. Push ( 89 );
Bluearr. Push ( 0 );
Redarrend. Push ( 255 );
Greenarrend. Push ( 0 );
Bluearrend. Push ( 0 );

For ( VaR I: Int = 0 ; I < Len; I ++ )
{
Mygraphic = Featureset. features [I];
VaR Boolean : Boolean = False ;
For ( VaR J: Int = 0 ; J < Griddata. Length (); j ++ )
{
If (Mygraphic. Attributes. area_id = Griddata [J]. grid_name)
{
Rgbindex = Griddata [J]. Traffic / Levelvalue; // Level
Flevel = (Griddata [J]. Traffic / (Levelvalue * (Rgbindex + 1 ))) * Gsize; // Percentage calculated

Red = Redarr [rgbindex] + (Redarrend [rgbindex] - Redarr [rgbindex]) / Gsize * Flevel;
Green = Greenarr [rgbindex] + (Greenarrend [rgbindex] - Greenarr [rgbindex]) / Gsize * Flevel;
Blue = Bluearr [rgbindex] + (Bluearrend [rgbindex] - Bluearr [rgbindex]) / Gsize * Flevel;

Color = Fixedint (rgbtoint (red, green, blue ));
Mygraphic. tooltip = " Grid: " + Griddata [J]. grid_name + " Traffic: " + Griddata [J]. traffic;
Mygraphic. Symbol = New Simplefillsymbol ( "" , Number (color ), 0.5 );
Querygraphicslayer. Add (mygraphic );
Unionedextent = Unionedextent. Union (polygon (mygraphic. Geometry). extent );
Delete Griddata [J];
Boolean = True ;
Break ;
}
}
If ( ! Boolean )
{
Red = Redarr [ 0 ];
Green = Greenarr [ 0 ];
Blue = Bluearr [ 0 ];

Color = Fixedint (rgbtoint (red, green, blue ));
Mygraphic. Symbol = New Simplefillsymbol ( "" , Number (color ), 0.5 );
Querygraphicslayer. Add (mygraphic );
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.