Package examples.colorpicker2

Source Code of examples.colorpicker2.CanvasHS

package examples.colorpicker2;

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);
  }
}
TOP

Related Classes of examples.colorpicker2.CanvasHS

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.