javascript - script to randomly change background gradient colors [but from specific range] -
i found neat script randomly changes background gradient colors.
ask, how can narrow spectrum of colors - use shades of yellow , orange.
in advance :)
function newgradient() { var c1 = { r: math.floor(math.random()*255), g: math.floor(math.random()*255), b: math.floor(math.random()*255) }; var c2 = { r: math.floor(math.random()*255), g: math.floor(math.random()*255), b: math.floor(math.random()*255) }; c1.rgb = 'rgb('+c1.r+','+c1.g+','+c1.b+')'; c2.rgb = 'rgb('+c2.r+','+c2.g+','+c2.b+')'; return 'radial-gradient(at top left, '+c1.rgb+', '+c2.rgb+')'; } function rollbg() { $('.bg.hidden').css('background', newgradient()); $('.bg').toggleclass('hidden'); }
look here:
var c1 = { r: math.floor(math.random()*255), g: math.floor(math.random()*255), b: math.floor(math.random()*255) }; var c2 = { r: math.floor(math.random()*255), g: math.floor(math.random()*255), b: math.floor(math.random()*255) };
it random 2 rgb colors 0 255 (max). gotta change random values color component around yellow ranges. yellow r=255, g=255, b=0. want output colors near these values.
you can search desired color range using 1 of online rgb color pickers.
for example:
function newgradient() { var c1 = { r: math.floor(255), g: math.floor(35+math.random()*220), b: math.floor(math.random()*55) }; var c2 = { r: math.floor(255), g: math.floor(35+math.random()*220), b: math.floor(math.random()*85) }; c1.rgb = 'rgb('+c1.r+','+c1.g+','+c1.b+')'; c2.rgb = 'rgb('+c2.r+','+c2.g+','+c2.b+')'; return 'radial-gradient(at top left, '+c1.rgb+', '+c2.rgb+')'; } function rollbg() { $('body').css('background', newgradient()); settimeout(function(){rollbg();}, 1000); } rollbg();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <body> </body>
play ranges , experiment until like. sure not out of 0-255 range, , remember yellowish need height r , g , low b.
Comments
Post a Comment