Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8307285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:29:45+00:00 2026-06-08T18:29:45+00:00

I am wanting to make a progress-bar-type-thing which goes from green-orange-red as it moves

  • 0

I am wanting to make a progress-bar-type-thing which goes from green-orange-red as it moves across the screen. For example:

enter image description here

How can I find what the colour should be at a given point?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:29:46+00:00Added an answer on June 8, 2026 at 6:29 pm

    Edit: here’s a link to a jsfiddle implementing this: http://jsfiddle.net/EAM9a/

    For the simplest method, you can do a linear interpolation between the colors. Let’s assume that the progress goes from 0.0 to 1.0 to make things easy. So

    0.0 - green  - rgb(0,   100, 0)
    0.5 - orange - rgb(255, 165, 0)
    1.0 - red    - rgb(139,   0, 0)
    

    Then we can just interpolate between green and orange or between orange and red, depending on the color we want.

    var  green = [0, 100, 0],
        orange = [255, 165, 0],
           red = [139, 0, 0];
    
    function color(val) {
      if (val < 0.5) {
        return colorToString(interpolate(val * 2, green, orange));
      } else {
        return colorToString(interpolate((val-0.5) * 2, orange, red));
      }
    }
    
    // val should be in the range [0.0, 1.0]
    // rgb1 and rgb2 should be an array of 3 values each in the range [0, 255]
    function interpolate(val, rgb1, rgb2) {
      var rgb = [0,0,0];
      var i;
      for (i = 0; i < 3; i++) {
        rgb[i] = rgb1[i] * (1.0 - val) + rgb2[i] * val;
      }
      return rgb;
    }
    
    // quick helper function to convert the array into something we can use for css
    function colorToString(rgb) {
      return "rgb(" + rgb[0] + ", " + rgb[1] + ", " + rgb[2] + ")";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wanting to make sure I'm using classes properly. The main script accepts this from
I'm wanting to make a component that inherits from rotate canvas using a storyboard.
I've been wanting to make the switch from PHP. Anyone care to highlight the
I'm trying to make a progress bar that starts at 0%, and takes 5
I'm wanting to make a password unlock screen for my app, and I'm not
I'm wanting to make a URL look pleasing to the eye. from /index.php?a=grapes to
I'm wanting to make sure I understand pass-by-value vs pass-by-reference properly. In particular, I'm
I'm wanting to make an API quickly, following REST principles - for a simple
so I'm pretty much wanting to make my code cleaner, and all of my
Is there any way to make the method readline() (from bufferedReader) block until it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.