加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 如何根据日期和随机返回颜色值?

发布时间:2020-12-13 17:22:48 所属栏目:PHP教程 来源:网络整理
导读:设计师提出了一个相当奇怪的想法或色轮(36种颜色). 我需要编写一个返回一种颜色但基于日期的函数. 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. 因
设计师提出了一个相当奇怪的想法或色轮(36种颜色).

我需要编写一个返回一种颜色但基于日期的函数.

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种颜色应按照车轮的顺序循环.

我想直到这一点,一个中级程序员可以帮助我,我不知道该怎么做.

但它变得稍微复杂一些
设计师希望网站的每个页面也有不同的颜色.
所以想象一下这个网站有10页(Home,About,Whatever,Gallery),每个页面应该有一个“最接近”的10种颜色.

哇,即使我解释它时也不会解开它.

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

所以在“1月1日”我希望以下颜色被推入数组并随机返回其中一种颜色.

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

知道怎么做吗?

解决方法

每闰年都会有一天的班次,但这应该可以满足您的需求.

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,$alpha),…
        rgba(168,);
    return $colors[($idx + $shift) % count($colors)];
}

我对Wordpress知之甚少,但为了获得每页一种颜色的功能,你应该做一个技巧:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读