English 中文(简体)
Java方案梯度
原标题:Programmatic gradient stops with Javascript

与Javascript(jQuery)合作,给出了2个彩色值(2033ff3300a<0>/code>,例如),我如何确定它们之间的某些梯度。

正因为如此,我打算使用一系列彩色价值:

    0 =>  000000 
 8400 =>  f0ff00 
44000 =>  2033ff 
68400 =>  3300a0 

There being 86400 seconds in a day, 12:00AM maps to 0, and 11:59PM maps to 86399. As time passes, the background color of a specified element changes to the appropriate color in gradient list via window.setInterval(function(e){ ... }, 1000). For example 2:32:11PM = 52331, which from the example would be somewhere between 2033ff and 3300a0.

我无需把阵列同价值观(除非更容易)相聚,而是将指数和价值作为参考。

最佳回答

就线性干涉而言:

Given 2033ff and 3300a0 as start and end you ll do:

red1 = 0x2033ff >> 16;
green1 = (0x2033ff >> 8) & 0xFF;
blue1  = 0x2033ff & 0xFF;

red2 = 0x3300a0 >> 16;
green2 = (0x3300a0 >> 8) & 0xFF;
blue2  = 0x3300a0 & 0xFF;

time = 0.3 // This should be between 0 and 1

outred = time * red1 + (1-time) * red2;
outgreen = time * green1 + (1-time) * green2;
outblue = time * blue1 + (1-time) * blue2;
问题回答

我写了以下图书馆:RainbowVis-JS,作为绘制颜色地图的普遍解决办法。 例如,你将使用:

var rainbow = new Rainbow(); 
rainbow.setSpectrum( 2033ff ,  3300a0 );
rainbow.setNumberRange(1, 86400);
var colour = rainbow.colourAt(52331); // 2c14c5




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.