如何返回基于一个日期和随机的彩色值? [英] How to return a color-value based a date and random?

查看:830
本文介绍了如何返回基于一个日期和随机的彩色值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设计师想出了一个相当奇怪的想法或色轮(36色)。

The designer came up with a rather weird idea or a color-wheel (with 36 colors).

我需要编写一个函数返回一个函数有一个的颜色,但根据日期

I need to write a function that is returning one color but based on the date.

如何在网站应该工作结果
  基于当前日期(你看到的图像德国日期下面)的网站应该有这样的背景颜色。

How the website should work
Based on the current date (you see german dates on the image underneath) the site should have this background color.

等等。1月1日第一颜色(蓝紫或者你可以调用)应该是头版的背景。 10天后的下一个颜色。所以,在一年内全部36种颜色应通过车轮的顺序循环。

So on "January 1st" the first color (blueviolet or what you might call that) should be the background of the frontpage. 10 days later the next color. So within one year all 36 colors should be looped through in the order of the wheel.

我猜,直到该点的中级程序员可以帮助我,我不知道该怎么做。

I guess untill that point an intermediate programmer could help me with this, I don't know how to do that.

但它变得稍微复杂些结果
设计师希望每一个网站的网页是在一个不同的颜色也。
所以,想象一下该网站有​​像10页(首页,关于,不管结果如何,图库)的每个页面应该有最接近10种颜色之一。

But it gets slightly more complicated
The designer wants every page of the website to be in a different color also. So imagine the site has like 10 pages (Home, About, Whatever, Gallery) every page should have one of the "closest" 10 colors.

哇,连我自己都不explainig时unterstand它。

所以,我想要做的就是创建一个返回函数的随机颜色的出的 10种颜色的是基于的池当前日期

So what I want to do is create a function that is returning a random color out of a pool of 10 colors that are based on the current date.

等等。1月1日我想下面的颜色数组中的推,并返回这些颜色的一个随机。

So on "January 1st" I want the following the colors to be pushed in an array and return one of those colors randomly.

function colorWheel($alpha) { // 36 colors
    $colors = array(
        rgba(170, 207, 172, 1),
        rgba(180, 211, 164, 1),
        rgba(189, 214, 145, 1),
        rgba(196, 217, 134, 1),
        rgba(206, 222, 124, 1),
        rgba(214, 226, 124, 1),
        rgba(226, 233, 124, 1),
        rgba(234, 235, 122, 1),
        rgba(236, 235, 120, 1),
        rgba(241, 231, 118, 1),
        rgba(240, 224, 118, 1),
        rgba(240, 216, 117, 1),
        rgba(237, 208, 115, 1),
        rgba(233, 199, 112, 1),
        rgba(230, 191, 110, 1),
        rgba(226, 177, 115, 1),
        rgba(221, 162, 110, 1),
        rgba(218, 153, 116, 1),
        rgba(215, 141, 112, 1),
        rgba(209, 140, 120, 1),
        rgba(203, 138, 119, 1),
        rgba(197, 136, 126, 1),
        rgba(191, 138, 134, 1),
        rgba(186, 142, 144, 1),
        rgba(181, 145, 157, 1),
        rgba(176, 151, 170, 1),
        rgba(170, 135, 178, 1),
        rgba(164, 159, 189, 1),
        rgba(166, 167, 194, 1),
        rgba(166, 177, 201, 1),
        rgba(166, 182, 204, 1),
        rgba(163, 186, 201, 1),
        rgba(164, 190, 196, 1),
        rgba(166, 196, 191, 1),
        rgba(167, 198, 185, 1),
        rgba(168, 201, 178, 1),
    );
}

不知道如何做到这一点?

Any idea how to do so?

推荐答案

这将有一个白班每一个闰年,但是这应该是确定您的需求。

This will have a one day shift every leap year but this should be ok for your needs.

function colorWheel($alpha, $shift = 0) { // 36 colors
    $time = time();
    $yearDay = $time % (60 * 60 * 24 * 365);
    $idx = $yearDay / 60 / 60 / 24 / 10;
    $colors = array(
        rgba(170, 207, 172, $alpha),
        …
        rgba(168, 201, 178, $alpha),
    );
    return $colors[($idx + $shift) % count($colors)];
}

我不知道很多有关Word preSS但要获得每页一种颜色functionnality你应该做的伎俩,如:

I do not know much about Wordpress but to get the one color per page functionnality you should do a trick like:

$page_shift = array(
    '/about.html' => 1,
    '/whatever.html' => 2,
    '/gallery.html' => 3,
    …
);
$shift = $page_shift[$_SERVER['REQUEST_URI']];
$color = colorWheel(1, $shift);

这篇关于如何返回基于一个日期和随机的彩色值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆