开发者

HTML colour mixer - Time to get out the crayons!

I have a project that needs to produced an array list of hexadecimal colour codes by taking in two colour codes and the number places in the array list. The two colours need to be mixed together and then diluted across the number in the array list.

For example, If colour one was red, the second colour was green and the number passed in was 3 the array list that would be produced would be something like

  • (0) - #FF0000 (Red)
  • (1) - #99661A (Redy/Greeny/brown)
  • (2) - #33CC33 (Green)

The W3Schools has exactly what im looking for, but they have used a fix number of colours returned. I just need to be able to vary the number of colours bought back and how strong they are.

http://www.w3schools.com/tags/ref_colormixer.asp

If anyone could point me in the ri开发者_如何学JAVAght direction, I would be very grateful!


The easiest thing to do would be to convert the hex to R, G, and B values first: http://msdn.microsoft.com/en-us/library/system.drawing.colortranslator.fromhtml.aspx

That will give you a Color object, which will give you the appropriate R, G, and B values. It should be between 0 to 255 for each of them. So take that, figure the difference between the two colors passed in on the R, G, and B values (individually), divide each by the number that was passed in and you have your deltas for R, G, and B. Finally just loop through, adding the delta values each time, create a Color object from the resulting R, G, and B values, and use ColorTranslator.ToHtml() function (http://msdn.microsoft.com/en-us/library/system.drawing.colortranslator.tohtml.aspx) to convert it to the appropriate hex value. With that you'll have your list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜