Amiga.org
Amiga computer related discussion => General chat about Amiga topics => Topic started by: Rowbeartoe on May 23, 2008, 09:55:22 AM
-
i=0
for red=0 to 7
for blue=0 to 7
for green=0 to 7
rainbow( i )=((red*3) mod 8)* 256
+green* 16
+blue
i=i+1
next
next
next
Ok, I know a lot of you program- and since I don't I was hoping you can help me understand this. Now this was for an Atari ST. I understand the RGB values, the ST was 0-7 (not nearly as impressive as the Amigas 0-15). I wanted to duplicate this rainbow manually with a paint program but don't know how to do this. This was from my favorite Fujiboink Demo.
If you can break it down to something like this
R0 G0 B0
R0 G1 B1
R0 G2 B2
R0 G3 B3
Ro G4 B4
etc etc. That would be great because I can understand this. I could copy this.
Thank you as always. =)
-
Hmm... I don't know that I can break it down the way you want - certainly not this early in the morning. :) However, I can explain what the listing does; hopefully that will help.
i=0
for red=0 to 7
for blue=0 to 7
for green=0 to 7
rainbow( i )=((red*3) mod 8)* 256
+green* 16
+blue
i=i+1
next
next
next
What this does, basically, is execute the line that starts with the word rainbow 512 times (8 * 8 * 8). This is just making a list of the colors in each arc of the rainbow, one at a time. Each time it runs this line, red, green and blue have different values. The loops will get us through every single combination of these colors between 0d,0d,0d and 7d,7d,7d. The progression will go like this:
R G B
0 0 0
0 0 1
0 0 2
...
0 1 0
0 1 1
etc...
Now, this line has a color value on the right hand side of the equal sign, built by using arithmetic to put the bits for red, green, and blue into separate parts of the number so that it's a single quantity - just like an HTML color value except only half the bits. :) In a 12 bit quantity like this one, the four most significant bits would represent red, the four in the middle green, and the low-order bits to blue, like so: rrrrggggbbbb.
The first part of the equation ((red * 3) MOD 8) - that is, the remainder of (red * 3) / 8 - is the red value. We multiply by 256 to shift the bits over to the left. Since 256 = 2 ^ 8, the bits are moved over by 10 places. So if red is 5, the number becomes 1792 (011100000000 - leading zero tacked on for clarity). Now we generate the middle five bits, for green, in the same way. If the green value is, for instance, 7, then 7 (00111) times 16 (10000) = 112 (01110000). Add these two quantities and you get 1904 (011101110000), and then you just add the blue value to it because as you see, those bits are blank, and the value of blue is constrained to be less than 8 so we don't have to worry about it changing the green value!
So now you have the color value to use for each of the 512 arcs that make up the rainbow, listed in order. Now, you want to have a separate number for each color value, presumably so you can punch them into some paint program. What you can do is change this:
rainbow( i )=((red*3) mod 8)* 256
+green* 16
+blue
to this:
reds( i )=((red*3) mod 8)
greens( i )=green
blues( i )=blue
and then you'd just need to add a line at the end of this to output it. since i don't recognize the grammar this is constructed in, I can't give you a specific line to insert, but maybe someone else can help with that. [Translation of printf("r:%d g:%d b:%d", reds( i ), greens( i ), blues( i )) anyone?]
I hope this explanation will help you at the least understand the code well enough to come up with your table.
-
Thank you so very much. It makes sense now. =)
-
no problem at all...
I'm curious, can anyone identify the language in use here? it looks to me like a variant of basic but I've never seen the particular syntax before. (I'm starting a master's program in cs this fall, to do a thesis in programming language design, so I'm always interested to see different language implementations.)
-
pkillo wrote:
no problem at all...
I'm curious, can anyone identify the language in use here? it looks to me like a variant of basic but I've never seen the particular syntax before. (I'm starting a master's program in cs this fall, to do a thesis in programming language design, so I'm always interested to see different language implementations.)
I'd put money on it being STOS.
-
http://www.atarimagazines.com/startv1n2/Fujiboink.html
That is the link talking about the program.
You know I must confess I thought I would understand the color values you exmplaind so I can just go in and paint the rainbow- but I'm at a loss.
R G B
0 0 0
0 0 1
0 0 2
0 1 0
0 1 1
0 1 2
0 2 0
0 2 1
0 2 2
0 3 0
0 3 1
0 3 2
0 4 0
0 4 1
0 4 2
0 5 0
0 5 1
0 5 2
0 6 0
0 6 1
0 6 2
0 7 0
0 7 1
0 7 2
1 0 0
1 0 1
1 0 2
1 1 0
1 1 1
1 1 2
not sure how to intrupet that code- this is my guess? Remember I never programed before- well in basic on the 8-bit machines, but I was very amature. =(
-
Your original snippet of code was not real code but only the simple outline (in pretend code) of what was actually done to make the rainbow.
What system/program are you doing this on?
Dave G 8-)
-
If you tell me what kind of system you would have available, I'll be happy to make you a small program to output the values... it wouldn't take me more than 5 or 10 minutes. of course, my Amiga is not working well enough to do it right now, but if you have a mac, or a windows box, or a 32-bit x86 linux system, I could send you an executable over the weekend.
-
Why not just build a LUT in a spreadsheet program?
-
I have an Atari ST- and this PC. Maybe you can run it on your program, and make it a word document? I can give you a personal email as well?
-
I have Excell on the PC- how would you do that? I'm such a bad programmer. =(
-
sure, I don't know why I didn't think of that... you just need the color values in order, right? pm me your email and I'll send you an excel spreadsheet with the values.
-
pkillo wrote:
sure, I don't know why I didn't think of that... you just need the color values in order, right? pm me your email and I'll send you an excel spreadsheet with the values.
I always develop algorithms using a spreadsheet... Each cell then contains a snapshot of each iteration... It becomes easy to see where an error has occured and if need be, one can graph the results, which can make it easy to spot an error!