mstiegl
YaBB Newbies
Offline
Posts: 12
generating a flexible grid - Part 2
Jul 29th , 2007, 2:26am
//----------------------Beginning of Part 2 calcTone(); } void calcTone(){ toneMap[0] = color(red(refColor) + srOff.getValue(),green(refColor) + sgOff.getValue(),blue(refColor) + sbOff.getValue() ); float tr = (red(refColor)-(populationPerc[0]*red(toneMap[0])))/populationPerc[1]; float tg = (green(refColor)-(populationPerc[0]*green(toneMap[0])))/populationPerc[1]; float tb = (blue(refColor)-(populationPerc[0]*blue(toneMap[0])))/populationPerc[1]; if (tr < 0 || tg < 0 || tb < 0 || tr > 255 || tg > 255 || tb > 255 || red(toneMap[0]) < 0 || red(toneMap[0]) > 255 || green(toneMap[0]) < 0 || green(toneMap[0]) > 255 || blue(toneMap[0]) < 0 || blue(toneMap[0]) > 255 ){ outOfGamut = true; } else{ outOfGamut = false; } toneMap[1] = color(tr,tg,tb); } class Slider extends control{ int min = 0; int span = 255; String label = "label"; float value = .5; int locx, locy; Slider(String label, int locx, int locy, float value, int min, int span){ this.min = min; this.span = span; this.label = label; this.locx = locx; this.locy = locy; this.value = value; } void draw(){ stroke(255); fill(0,0,0,0); rect(locx ,locy,100,10); fill(255); rect(locx + value*90,locy,10,10); text(label + ":" + getValue(),locx,locy + 10); } void handleInput(){ int dx = (int)(mouseX - (locx + value*100)); int dy = mouseY - locy; if (dy > 0 && dy < 10){ if (dx > -50 && dx < 50){ value += dx/100.f; if (value > 1.f) value = 1.f; if (value < 0.f) value = 0.f; } } } int getValue(){ return (int)(min + value*span); } } abstract class control{ abstract void draw(); abstract void handleInput(); } // This class is used to hold an image while on the clipboard. public static class ImageSelection implements Transferable { private Image image; public ImageSelection(Image image) { this.image = image; } // Returns supported flavors public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[]{DataFlavor.imageFlavor}; } // Returns true if flavor is supported public boolean isDataFlavorSupported(DataFlavor flavor) { return DataFlavor.imageFlavor.equals(flavor); } // Returns image public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (!DataFlavor.imageFlavor.equals(flavor)) { throw new UnsupportedFlavorException(flavor); } return image; } }