Color Wheel
Previous
Next
Alternative
RB2.java (w/ DB)
RB1.java (w/o DB)
Home
// Color Wheel - Hue from 0-1 and Saturation from 0-1.
// The example below draws a color wheel that disappears with
// a window event. The applet compares the action of this one
// with another version that draws to an offscreen image buffer.
import java.awt.*;
import java.applet.*;
public class RB1 extends Applet {
Color color;
TextField sat, bright;
Button button;
public void init() {
repaint();
}
public void paint (Graphics g) {
double r1 = 200;
double pi = 355.0/113.0;
double c = 0, d = 0;
int x,y;
int n=1440;
for (int j=0 ; j <= 50 ; j++) {
c=0; d=0;
for (int i=0 ; i < n ; i++, c+=2*pi/n, d+=1/(double)n ) {
color = Color.getHSBColor((float)d, (float)((50.0-j)/50.0), (float)1.0);
g.setColor(color);
x = (int)(r1*Math.sin(c)+250);
y = (int)(r1*Math.cos(c)+250);
g.fillRect(x,y,3,3);
}
r1 -= 3;
}
}
}