• We just launched and are currently in beta. Join us as we build and grow the community.

Random RGB and Hex Color Generator Application in JavaScript Free Source Code

saadhfathi

User Acquisition Specialist
S Rep
0
0
0
Rep
0
S Vouches
0
0
0
Vouches
0
Posts
189
Likes
129
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
Introduction

This simple project is a Random RGB and Hex Color Generator Application. This is a web-based application project developed in JavaScript, jQuery, HTML, and CSS. The main purpose of this application is to generate a random RGB and Hex Color. This application can help new programmers or students to have a reference on how to generate random values in JavaScript. The application has a simple user interface using the Bootstrap 5 Framework and consists of simple and user-friendly features and functionalities.

About the Random RGB and Hex Color Generator Application

I developed the Application using the following:

  • HTML
  • CSS
  • JavaScript
  • jQuery

Logic and Method

  • DOM Manipulation
  • Click Event Listener
  • Math.ceil()
  • Math.random()

This Random RGB and Hex Color Generator Application contain only a very simple and small scope of functions. Users can generate either an RGB or Hex color code. On this application, the user can simply generate color code by clicking either the "Generate RGB Color" or the "Generate Hex Color" buttons. Each of these buttons triggers the application to generate a random color and display the color by changing the Page Background Color with the generated color. Then, the application also returns the generated color code above the buttons.

Script Used for Generating the Color

RGB Color Code

  1. // Red Random Value
  2. var

    r =

    Math

    .ceil

    (

    Math

    .random

    (

    )

    *

    255

    )

    ;
  3. // Green Random Value
  4. var

    g =

    Math

    .ceil

    (

    Math

    .random

    (

    )

    *

    255

    )

    ;
  5. // Blue Random Value
  6. var

    b =

    Math

    .ceil

    (

    Math

    .random

    (

    )

    *

    255

    )

    ;

  7. // Generated Random RGB Color
  8. var

    rgb =

    `rgb(

    ${

    r}

    ,

    ${

    g}

    ,

    ${

    b}

    )

    `;

Hex Color Code

  1. // HEX Values
  2. var

    hex_values =

    [

    '0'

    ,

    '1'

    ,

    '2'

    ,

    '3'

    ,

    '4'

    ,

    '5'

    ,

    '6'

    ,

    '7'

    ,

    '8'

    ,

    '9'

    ,

    'A'

    ,

    'B'

    ,

    'C'

    ,

    'D'

    ,

    'F'

    ]

    ;

  3. // Hex Generated Values
  4. var

    v1 =

    hex_values[

    Math

    .ceil

    (

    Math

    .random

    (

    )

    *

    (

    Object

    .keys

    (

    hex_values)

    .length

    -

    1

    )

    )

    ]
  5. var

    v2 =

    hex_values[

    Math

    .ceil

    (

    Math

    .random

    (

    )

    *

    (

    Object

    .keys

    (

    hex_values)

    .length

    -

    1

    )

    )

    ]
  6. var

    v3 =

    hex_values[

    Math

    .ceil

    (

    Math

    .random

    (

    )

    *

    (

    Object

    .keys

    (

    hex_values)

    .length

    -

    1

    )

    )

    ]
  7. var

    v4 =

    hex_values[

    Math

    .ceil

    (

    Math

    .random

    (

    )

    *

    (

    Object

    .keys

    (

    hex_values)

    .length

    -

    1

    )

    )

    ]
  8. var

    v5 =

    hex_values[

    Math

    .ceil

    (

    Math

    .random

    (

    )

    *

    (

    Object

    .keys

    (

    hex_values)

    .length

    -

    1

    )

    )

    ]
  9. var

    v6 =

    hex_values[

    Math

    .ceil

    (

    Math

    .random

    (

    )

    *

    (

    Object

    .keys

    (

    hex_values)

    .length

    -

    1

    )

    )

    ]

  10. // Generated Random HEX Color
  11. var

    hex =

    `#${

    v1}

    ${

    v2}

    ${

    v3}

    ${

    v4}

    ${

    v5}

    ${

    v6}

    `

Features

  • Generate RGB Color Code
  • Generate Hex Color Code
  • Changing Page Background Color
  • Returns the Generated Background Color

The source code was developed only for educational purposes only. You can download the source code for free and modify it the way you wanted.

System Snapshots of some Features

Page User Interface

Sample Generated RGB Color Code

Sample Generated Hex Color Code

How to Run ??

  1. Download the provided source code zip file. (download button is located below)
  2. Extract the downloaded source code zip file.
  3. Locate the index.html file.
  4. Open the index.html file with your preferred browsers such as Chrome Browser or you can directly browse the index.html file path on your browser. i.e. file:///C:/personal/desktop/js-color_generator/index.html

DEMO VIDEO

That's it. You can now explore the features and functionalities of this Random RGB and Hex Color Generator Application in JavaScript. I hope this will help you with what you are looking for and you'll find something useful for your future projects.

Explore more on this website for more Free Source Codes and Tutorials.

Enjoy :)

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.

2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

440,010

316,559

316,568

Top