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

  • SEARCH
  • Home
  • 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 7723645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:29:38+00:00 2026-06-01T04:29:38+00:00

Im trying to generate a color gradient using ColdFusion. My current code below works

  • 0

Im trying to generate a color gradient using ColdFusion. My current code below works but it basically will only display the start color till the very last line then it will show the end color. No gradient. Just a big block of red then one line of blue. What am i not seeing wrong with my code?

<cfset BoxNumber = RandRange(100,1000) >

<cfset Start_Red = 255 >
<cfset Start_Green = 0 >
<cfset Start_Blue = 0 >

<cfset End_Red = 0 >
<cfset End_Green = 0 >
<cfset End_Blue = 255 >

<div id="color-band">

<cfloop index = "i" from = 0 to = #BoxNumber# >

<cfset Percent = i \ (BoxNumber - 1) >

<cfset Red = int(((End_Red - Start_Red) * Percent) + Start_Red) >
<cfset Green = int(((End_Green - Start_Green) * Percent) + Start_Green) >
<cfset Blue = int(((End_Blue - Start_Blue) * Percent) + Start_Blue) >

<div style="background-color:rgb(<cfoutput>#Red#</cfoutput>, <cfoutput>#Green#  </cfoutput>, <cfoutput>#Blue#</cfoutput>)">&nbsp;</div>

</cfloop>

</div>

I do know a ColdFusion server can be hard to come by sometimes so i can test the code if need be.

  • 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-01T04:29:39+00:00Added an answer on June 1, 2026 at 4:29 am
    <cfset Percent = i \ (BoxNumber - 1) >
    ...
    <cfset Red = int(((End_Red - Start_Red) * Percent) + Start_Red) >
    

    At least one problem is the percent formula returns zero (0) most of the time. So the colors never increment because the code is just adding 0 to the starting value. I think the color formula is off as well.

    Unless this is a learning exercise, you might want to look for an existing function or method rather than reinventing the wheel. (Edit: For example, take a look at Craig’s suggestion). Otherwise, you might take a look at cflib.org for inspiration. The fadeList function shows the basic concept for generating a gradient (albeit with hex). This is not exactly right, but something along these lines

    ...    
    <cfset RedOffset = (Start_Red - End_Red) / BoxNumber>
    <cfset GreenOffset = (Start_Green - End_Green) / BoxNumber>
    <cfset BlueOffset = (Start_Blue - End_Blue) / BoxNumber>
    
    <div id="color-band">
    <cfloop index="i" from="0" to ="#BoxNumber#">
        <cfset Red = int(Start_Red - (RedOffset * i))>
        <cfset Green = int(Start_Green - (GreenOffset * i))>
        <cfset Blue = int(Start_Blue - (BlueOffset * i))>
        <cfoutput>
        <div style="height: 5px; background-color:rgb(#Red#, #Green#, #Blue#)">&nbsp;</div>
        </cfoutput>
    </cfloop>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to generate a dynamic html button in c#,But buttons are being
I'm trying to generate a RDoc using the XML format. Here's the command that
I spent some time trying to generate certain tab icons using Android Asset Studio
I'm using Compass to generate linear gradients but I'm getting a strange error indicating
I'm trying to generate sparklines for a dashboard using the Microsoft chart control on
I'm trying to dynamically generate a gif image of a specified size and color
I'm trying to have table borders in my PDF using pisa to generate the
I'm trying to dynamically generate an image file that will be composed by other
Using my Windows 7 64bit machine, I'm trying to generate an avi file from
I'm trying to generate a color that could highlight an item as selected based

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.