Author |
Topic: best way to do graduated colors (Read 729 times) |
|
gennettt
Member in Training
 
member is offline

gadzooks!

Posts: 55
|
 |
best way to do graduated colors
« Thread started on: Oct 30th, 2009, 12:42pm » |
|
Hello all, I am trying to program a graduated colors routine so that colors do not jump, say, from 255 (red) to 0 (black), wen you cross the 255 to 0 boundary, (color values may be controlled by some sine function). I thought maybe I could do it with strings and for/next loops, had a little trouble there. Basically the idea was to start (considering one register at first, say rgb red), with a random number to specify the start in the 0 to 255, count up to 255, then back down to 0, then up to the random number we started with, = 510 values. Same for green, blue registers. the sequence would be started from a single 'go' button, using three random seed numbers,(avoiding use of complicated gui, as in color pickers), one could view the result, and go with whatever was pleasing to the eye. Now, the question is, anyone have any suggestions as to how this may be done, strings? arrays? or what? Just looking for best option? anything? cheers, gennettt
|
|
Logged
|
|
|
|
Welopez
Moderator
    
member is offline

Never underestimate the power of human stupidity. - Robert A. Heinlein

Gender: 
Posts: 3841
|
 |
Re: best way to do graduated colors
« Reply #1 on: Oct 30th, 2009, 1:21pm » |
|
I don't want to rain on your parade, Gennett, but you do realize there are 255*255*255=16,581,375 possible RGB values, don't you? I would definitely stay away from using random values as it would take an inordinate amount of time, and the human eye cannot distinguish many of the subtle variations.
Consider using an r=r+10, g=g+10, b=b+10 algorithm in a loop, now you only have 15,625 possibilities. Or consider using pushbuttons to increase or decrease the RGB values indepently.
When you have decided upon a strategy, post your code and we'll make suggestions. By the way, you must use a GUI since the MAINWIN is not capable of displaying colors.
Good luck!
|
| « Last Edit: Oct 30th, 2009, 1:21pm by Welopez » |
Logged
|
|
|
|
gennettt
Member in Training
 
member is offline

gadzooks!

Posts: 55
|
 |
Re: best way to do graduated colors
« Reply #2 on: Oct 30th, 2009, 1:43pm » |
|
Hi Welopez, Yes, I realize the 255 x 255 x 255 number of possible colours, and I have a graphic display area already set up, with a 'control' gui, ready to add a 'gradcols' button, this prog. does fractal plots in a variety of ways, but it would be much nicer with the graduations of colour I am after. I only need a colour spread of 510 values, out of 16 million! Thanks for your input anyway.  regards, gennettt
|
|
Logged
|
|
|
|
tsh73
Senior Member
    
member is offline


Gender: 
Posts: 931
|
 |
Re: best way to do graduated colors
« Reply #3 on: Oct 30th, 2009, 1:52pm » |
|
gennettt, me a bit confused too  Look at this color tranzitions - color wheel It uses Hiew Saturation Value model Hiew basicaly an angle, so you can change it in small steps and get 510 (hopefully different)? close colors.
BTW why 510? I can understand why it should be <=256 (to be possible to save as 256 color bitmap), but 510? *puzzled*
EDIT: I recalled older program of mine, which uses another color transition. May be it'll fit better, have a look JB plasma
|
| « Last Edit: Oct 30th, 2009, 2:00pm by tsh73 » |
Logged
|
Q: "And if I took your codes and compile them, and sell them for a profit"? A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
|
|
|
Psycho
Member in Training
 
member is offline


Gender: 
Posts: 26
|
 |
Re: best way to do graduated colors
« Reply #4 on: Oct 30th, 2009, 2:52pm » |
|
This code only graduates the red scale but may help you to get what you are looking for.
Code: nomainwin
WindowWidth=280
WindowHeight=570
'show how to use RGB colors
graphicbox #1.graphics, 10, 10, 250, 510
open "graphics" for window as #1
#1, "trapclose quit"
[colorprompt]
prompt "Starting red color number";redColorNum
if (redColorNum >=0) and (redColorNum<=255) then [draw]
notice "The red color number must be between 0 and 255"
goto [colorprompt]
wait
[draw]
print #1.graphics, "size 2 ; down ; fill black"
if redColorNum = 255 then
newStep=-1
else
newStep=1
end if
for loops = 1 to 510
print #1.graphics, "color "; redColorNum; " 0 0"
print #1.graphics, "place 0 "; (loops); " ; goto 250 "; (loops)
redColorNum = redColorNum + newStep
if redColorNum=0 then newStep=1
if redColorNum=255 then newStep=-1
next loops
print #1.graphics, "flush"
wait
sub quit winHandle$
close #winHandle$
end
end sub
John "Psycho" Siejkowski
|
| « Last Edit: Oct 30th, 2009, 2:54pm by Psycho » |
Logged
|
|
|
|
JohnDavidson
Administrator
    
member is offline


Posts: 3745
|
 |
Re: best way to do graduated colors
« Reply #5 on: Oct 30th, 2009, 2:53pm » |
|
It's early ,for me, and I haven't finished my first cup of coffee yet so...
I thing the number of color possibilities may be causing some confusion. No matter the value used, valid of course, it creates only one color.
You have opted for Rnd() to seed your colors but you don't state the values you are trying to retrieve. I would use something like Code: It will allow you to create a range of colors starting at red and incrementing by one until the red value =red + 8 without going above 255. Using red, green, and blue will create a spread of 512.
John
|
|
Logged
|
John Davidson e-me: johnshomeport@yahoo.com My JB Page: http://john.jbusers.com/ Did ya Libby yet? http://lblibby.com/
|
|
|
gennettt
Member in Training
 
member is offline

gadzooks!

Posts: 55
|
 |
Re: best way to do graduated colors
« Reply #6 on: Oct 30th, 2009, 2:56pm » |
|
Hi, thanks for info, Tsh73 and Welopez. The idea I had was to use an rnd number to specify a point within each of the 0 to 255 colour range, fill a string with values up to 255, check for reaching 255, reverse count, down to 0, check for reaching zero, and reverse to count up to original rnd number (again filling strings) add strings together, and use final string as colour spread. Done for all three colour registers. Reason for 510 was so didn't lose any colours below rnd start value. Each rgb register would have different start points, so should result in different grauated colour spreads. Re-intializing the rnd's via a button would result in random spreads of colour. If it can be done using less than 510 (up to 255, turn round, down to 0, turn round, back to rnd start) then great. Also is the reason for 510 is that sine calcs (inc tan etc) applied to colour values, can range outside of the 255 colour range, (maybe I'm in a cul-de-sac!) I may have some code that doesn't work shortly!! regards, gennettt  p.s. any simple alternative ideas welcome
|
|
Logged
|
|
|
|
gennettt
Member in Training
 
member is offline

gadzooks!

Posts: 55
|
 |
Re: best way to do graduated colors
« Reply #7 on: Oct 30th, 2009, 3:06pm » |
|
Thanks Psycho, very good! pretty well what I have been trying to do, much obliged  regards, gennettt
|
|
Logged
|
|
|
|
Psycho
Member in Training
 
member is offline


Gender: 
Posts: 26
|
 |
Re: best way to do graduated colors
« Reply #8 on: Oct 30th, 2009, 3:42pm » |
|
gennett, you are welcome. This version randomizes all the values but still only graduates the red. I was guessing that you wanted to keep the pattern linear as opposed to moving all three values up and down but if that's your goal, it should be a simple modification.
Code: nomainwin
WindowWidth=280
WindowHeight=600
button #1.again, "Again", [start], UL, 200, 530
graphicbox #1.graphics, 10, 10, 250, 510
open "graphics" for window as #1
#1, "trapclose quit"
[start]
#1.graphics, "cls"
'pick random red, green blue values
redColorNum=int(rnd(0)*256)
greenColorNum=int(rnd(0)*256)
blueColorNum=int(rnd(0)*256)
[draw]
print #1.graphics, "size 1 ; down"
if redColorNum = 255 then
newStep=-1
else
newStep=1
end if
'gradute the red value
for loops = 1 to 510
print #1.graphics, "color "; redColorNum;" ";greenColorNum;" ";blueColorNum
print #1.graphics, "place 0 "; loops-1; " ; goto 250 "; loops-1
redColorNum = redColorNum + newStep
if redColorNum=0 then newStep=1
if redColorNum=255 then newStep=-1
next loops
print #1.graphics, "flush"
wait
sub quit winHandle$
close #winHandle$
end
end sub
John "Psycho" Siejkowski
|
|
Logged
|
|
|
|
tenochtitlanuk
Member in Training
 
member is offline


Gender: 
Posts: 46
|
 |
Re: best way to do graduated colors
« Reply #9 on: Oct 30th, 2009, 3:50pm » |
|
You might also enjoy my cos-wave cycling version- each RGB component cycles up and down at a different frequency- the second graphic window shows them all starting in-phase and drifting in & out.. Code:
nomainwin
WindowWidth =360
WindowHeight =420
UpperLeftX =int( ( DisplayWidth -WindowWidth) /2)
UpperLeftY =int( ( DisplayHeight -WindowHeight) /2)
graphicbox #w.g1, 10, 50, 330, 180
graphicbox #w.g2, 10, 240, 330, 90
textbox #w.tb1, 10, 10, 330, 30
button #w.exit, "Exit", [quit], LR, 30, 10
open "Cycling RGB" for window as #w
#w, "trapclose [quit]"
#w.g1, "down"
#w.g2, "down ; fill black"
#w, "font arial 12"
for i =0 to 100 step 0.01 ' remember angles are in radians; this is ~16 cycles
red =int( 128 +127 *cos( 1.1 *i)) ' each component follows a cos curve
grn =int( 128 +127 *cos( 1.7 *i)) ' but of diff't freq'y up to 2.9 per cycle.
blu =int( 128 +127 *cos( 2.9 *i)) ' NB cos( 0) =+1 so start at white
#w.g1, "cls ; fill "; red; " "; grn; " "; blu
#w.tb1, " Red = "; right$( " " +str$( red), 3);_
" & green = "; right$( " " +str$( grn), 3);_
" & blue = "; right$( " " +str$( blu), 3)
#w.g2, "color red ; set "; i /100 *330; " "; 75 -red /255 *20
#w.g2, "color green ; set "; i /100 *330; " "; 50 -grn /255 *20
#w.g2, "color blue ; set "; i /100 *330; " "; 25 -blu /255 *20
timer 50, [MoveOn]
wait
[MoveOn]
timer 0
scan
next i
wait
[quit]
close #w
end
|
|
Logged
|
|
|
|
gennettt
Member in Training
 
member is offline

gadzooks!

Posts: 55
|
 |
Re: best way to do graduated colors
« Reply #10 on: Oct 30th, 2009, 4:13pm » |
|
Wow, I'm spoilt for choices! Thank you Psycho - Tenochtitlanuk - JohnDavison and all for the help. regards, gennettt
|
| « Last Edit: Oct 30th, 2009, 4:14pm by gennettt » |
Logged
|
|
|
|
gennettt
Member in Training
 
member is offline

gadzooks!

Posts: 55
|
 |
Re: best way to do graduated colors
« Reply #11 on: Oct 30th, 2009, 7:07pm » |
|
Hello Psycho, I have been attempting to use your color graduation prog. to graduate more than two colors. Can that be done? I have tried repeating the loops for green and blue, still two colors. any suggestion? regards, gennettt
|
|
Logged
|
|
|
|
Psycho
Member in Training
 
member is offline


Gender: 
Posts: 26
|
 |
Re: best way to do graduated colors
« Reply #12 on: Oct 30th, 2009, 8:30pm » |
|
This isn't eloquent but a continuation of my earlier code. Is this what you are trying to achieve?
Code: nomainwin
WindowWidth=280
WindowHeight=600
button #1.again, "Again", [start], UL, 200, 530
graphicbox #1.graphics, 10, 10, 250, 510
open "graphics" for window as #1
#1, "trapclose quit"
[start]
#1.graphics, "cls"
'pick random red, green & blue values
redColorNum=int(rnd(0)*256)
greenColorNum=int(rnd(0)*256)
blueColorNum=int(rnd(0)*256)
[draw]
print #1.graphics, "size 1 ; down"
if redColorNum = 255 then
rednewStep=-1
else
rednewStep=1
end if
if greenColorNum = 255 then
greennewStep=-1
else
greennewStep=1
end if
if blueColorNum = 255 then
bluenewStep=-1
else
bluenewStep=1
end if
'gradute the red, green & blue values
for loops = 1 to 510
print #1.graphics, "color "; redColorNum;" ";greenColorNum;" ";blueColorNum
print #1.graphics, "place 0 "; loops-1; " ; goto 250 "; loops-1
redColorNum = redColorNum + rednewStep
if redColorNum=0 then rednewStep=1
if redColorNum=255 then rednewStep=-1
greenColorNum = greenColorNum + greennewStep
if greenColorNum=0 then greennewStep=1
if greenColorNum=255 then greennewStep=-1
blueColorNum = blueColorNum + bluenewStep
if blueColorNum=0 then bluenewStep=1
if blueColorNum=255 then bluenewStep=-1
next loops
print #1.graphics, "flush"
wait
sub quit winHandle$
close #winHandle$
end
end sub
***Edited to correct blueStep=1 to bluenewStep=1 inside if/then/else loop***
John "Psycho" Siejkowski
|
| « Last Edit: Oct 30th, 2009, 9:24pm by Psycho » |
Logged
|
|
|
|
gennettt
Member in Training
 
member is offline

gadzooks!

Posts: 55
|
 |
Re: best way to do graduated colors
« Reply #13 on: Oct 30th, 2009, 8:49pm » |
|
Hi Psycho, looks good, thanks for the insight into how to do it.  regards, gennettt
|
|
Logged
|
|
|
|
Psycho
Member in Training
 
member is offline


Gender: 
Posts: 26
|
 |
Re: best way to do graduated colors
« Reply #14 on: Oct 30th, 2009, 9:42pm » |
|
gennett, glad to help.
Please note that I edited my last post to correct a variable typo that wasn't allowing the blue value to cycle properly.
John "Psycho" Siejkowski
|
|
Logged
|
|
|
|
|