On a computer it is possible to represent colors using numbers.
A traditional approach is to use a set of three values from 0 to 255.
The first number sets the intensity of red, the second
controls green and the third defines blue.
color(red,green,blue);
I like using the following
up-down counters to vary the color to all possible hues.
int rr,gg,bb;//color variables
int rq=1; // color up-down factors
int gq=2; // these require a numerical value.
int bq=3; // to start out with... NOT ZERO...
int x,y,z,a; //endpoint locations
for (int i=0;i<5000;i++)
{
//color changer up-down counters
rr=rr+rq;
if(rr>254){rq=-1;}
if(rr<1){rq=1;}
gg=gg+gq;
if(gg>253){gq=-2;}
if(gg<2){gq=2;}
bb=bb+bq;
if(bb>252){bq=-3;}
if(bb<3){bq=3;}
//apply the new numbers for color(red,green,blue)
Color cNew = new Color(rr, gg, bb);
bufferGraphics.setColor(cNew);
//draw the line
bufferGraphics.drawLine(x,y,z,a);
}
The way an up-down counter works.
Let variable rr start out at zero. The first time thru the loop
the value of 1 (rq) is added to it. Every time we pass thru the loop
the value of rr gets bigger by one until it is greater than 254.
At that point the variable rq is set to -1 and on subsequent passes
thru the loop rr is decremented by one.
The values for rr count up to 255 and then down to zero and then back up
to 255 etc. If you plot the values of i (horizontally)
and rr (vertically) on a graph, you will see a triangle shaped wave. The rq,gq and bq variables control the frequency of the triangle waves. Since all three values are used to specify the color, this is a form of FREQUENCY MODULATION.
.....*.........*.........*.........*MAXIMUM VALUE
....*.*.......*.*.......*.*.......*.
...*...*.....*...*.....*...*.....*..
..*.....*...*.....*...*.....*...*...
.*.......*.*.......*.*.......*.*....
*.........*.........*.........*.....minimum value
If you set the color scheme using the same variable
for all three numbers, it is possible to gradually change from
black to white thru all the shades of grey.
Color cNew = new Color(rr, rr, rr);
Location of a point can be changed using up down counters too.
Here we have counters that change the x and y co-ordinates gradually
increasing and then decreasing quickly.
int xx=1;
int yy=2;
for (int i=0;i<5000;i++)
{
x=x+xx;
if(x>350){xx=-3;}
if(x<0){xx=1;}
y=y+yy;
if(y>250){yy=-5;}
if(y<0){yy=2;}
}
If you drew a dot at the x-y location it would appear to
bounce off walls of a rectangle. Since the xx and yy
variables are different numbers, the ball will not bounce off
the wall at a right angle. The slope of the line could be
wierd directions...
In the example applet I have used both the black/white and the color changer. There is a set of 8 lines that move across the screen and gradually change colors. There is ANOTHER set that follows a similar path and is black/white. These sets of lines are in almost the same locations but JUST A LITTLE BIT DIFFERENT. One end point is a pixel up and 3 pixels right... The other endpoint is a pixel left and 4 pixels down (for example). As the lines flow across the screen they create what I call the "shredded" color effect. Since one line crosses the other, the trailing edge varies in color scheme depending on where the crossover point is. That crossover point is changing all the time.
here are the files...
octet13.class file
octet13.java file
use this code to put the applet on your own webpage... Remember to save the class file in the SAME DIRECTORY as your webpage html file...
<applet code="octet13.class"
height=400
width=600>
</applet>
the java file is just for reference and is not needed to make the kaleidoscope WORK... I just included the source code because someone might want to read it, modify it and create something new and different... GO AHEAD!