/* ColorPicker v1.0 by Toh Lik Khoong Last revised 01/03/2001 Please contact me at lktoh@navsurf.com for any comments or suggestions The source code is strictly for educational purposes and cannot be modified or used without the express permission of the author Visit http://navsurf.com for the latest version and other useful applets */ import java.awt.*; import java.awt.image.MemoryImageSource; import java.awt.image.PixelGrabber; public class CanvasHS extends Canvas{ static final int HEIGHT = 255; static final int WIDTH = 255; private int[] colormap = new int[WIDTH*HEIGHT]; private Image col = null; private Point cur_point = new Point(); CanvasHS(){ //super.setBackground(Color.black); super.resize(WIDTH, HEIGHT); for (int x = 0; x < WIDTH; x++){ for (int y = 1; y <= HEIGHT; y++){ colormap[x + (HEIGHT - y)*WIDTH] = Color.HSBtoRGB(((float) x)/HEIGHT, ((float) y)/WIDTH, (float) 0.75); } } col = createImage(new MemoryImageSource(WIDTH, HEIGHT, colormap, 0, WIDTH)); } public Color getColorAt(int x, int y){ Color couleur = new Color(colormap[x + y*WIDTH]); return couleur; } public void paint(Graphics g){ g.drawImage(col, 0, 0, this); } }