Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #39459 > unrolled thread

Code for changing same colors on webpage to unique random colors after each webpage display change.

Started byI A <he12457@hotmail.com>
First post2021-02-12 14:43 -0800
Last post2021-02-13 03:37 -0800
Articles 4 — 3 participants

Back to article view | Back to comp.lang.javascript


Contents

  Code for changing same colors on webpage to unique random colors after each webpage display change. I A <he12457@hotmail.com> - 2021-02-12 14:43 -0800
    Re: Code for changing same colors on webpage to unique random colors after each webpage display change. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-02-13 03:28 -0800
      Re: Code for changing same colors on webpage to unique random colors after each webpage display change. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-02-13 12:18 +0000
    Re: Code for changing same colors on webpage to unique random colors after each webpage display change. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-02-13 03:37 -0800

#39459 — Code for changing same colors on webpage to unique random colors after each webpage display change.

FromI A <he12457@hotmail.com>
Date2021-02-12 14:43 -0800
SubjectCode for changing same colors on webpage to unique random colors after each webpage display change.
Message-ID<f432693c-5415-4992-8297-43244b3440d8n@googlegroups.com>
Is this already made ?
If not, then does someone know, how to do this and wants to do that and post it then here ?






I A ( Kpuctjan Pobam )

E-mail: ya12983 mail co m
Telephone number: 372 6861327 

[toc] | [next] | [standalone]


#39460

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2021-02-13 03:28 -0800
Message-ID<e9df338f-c38e-49c9-866e-ddbefe0adee0n@googlegroups.com>
In reply to#39459
fredag 12 februari 2021 kl. 23:43:24 UTC+1 skrev I A:
> Is this already made ? 
> If not, then does someone know, how to do this and wants to do that and post it then here ? 
> 
> 
> 
> 
> 
> 
> I A ( Kpuctjan Pobam ) 
> 
> E-mail: ya12983 mail co m 
> Telephone number: 372 6861327
function rndColor() {
    var hex = ['0', '1', '2', '3', '4', '5', '6', '7',
               '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'],
        color = '#', i;
    for (i = 0; i < 6 ; i++) {
        color = color + hex[Math.floor(Math.random() * 16)];
    }
    return color;
}

[toc] | [prev] | [next] | [standalone]


#39462

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2021-02-13 12:18 +0000
Message-ID<87blcob1pd.fsf@bsb.me.uk>
In reply to#39460
Jonas Thörnvall <jonas.thornvall@gmail.com> writes:

> function rndColor() {
>     var hex = ['0', '1', '2', '3', '4', '5', '6', '7',
>                '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'],
>         color = '#', i;
>     for (i = 0; i < 6 ; i++) {
>         color = color + hex[Math.floor(Math.random() * 16)];
>     }
>     return color;
> }

Or you could use

  '#' + Math.floor((Math.random()*0x1000000)).toString(16).padStart(6, '0')

and, if you want to avoid padStart, (it's a recent addition):

  '#' + ('000000' + Math.floor((Math.random()*0x1000000)).toString(16)).slice(-6)

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#39461

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2021-02-13 03:37 -0800
Message-ID<c81ed937-d5a6-45c6-8a4f-fc6c3abfead9n@googlegroups.com>
In reply to#39459
fredag 12 februari 2021 kl. 23:43:24 UTC+1 skrev I A:
> Is this already made ? 
> If not, then does someone know, how to do this and wants to do that and post it then here ? 
> 
> 
> 
> 
> 
> 
> I A ( Kpuctjan Pobam ) 
> 
> E-mail: ya12983 mail co m 
> Telephone number: 372 6861327
I am not sure what you mean by same colors though, i guess you would have to put your start "orginal" colors in to an array, and when the user change page update the array using getRandomColor function.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web