ControlP5 interactions for Binary Tree Example

public void gui() { p5 = new ControlP5(this); Group g = p5.addGroup("myGroup") .setBackgroundColor(color(255, 64)) .setPosition(0, 0) .setCaptionLabel("Component Color"); Accordion accordion = p5.addAccordion("acc") .setWidth(width) .addItem(g) .setItemHeight(90) .open(); p5.addSlider("redChannel") .setPosition(100, 30) .setSize(200, 20) .setRange(0, 255) .setValue(255) .moveTo(g) .hide(); p5.addSlider("greenChannel") .setPosition(400, 30) .setSize(200, 20) .setRange(0, 255) .setValue(255) .moveTo(g) .hide(); p5.addSlider("blueChannel") .setPosition(700, 30) .setSize(200, 20) .setRange(0, 255) .setValue(255) .moveTo(g) .hide(); } public void mousePressed() { if (mouseY > 100) selection = root.select(mouseX, mouseY); if (selection != null) { p5.getController("redChannel").show(); p5.getController("greenChannel").show(); p5.getController("blueChannel").show(); p5.getController("redChannel").setValue(red(selection.color)); p5.getController("greenChannel").setValue(green(selection.color)); p5.getController("blueChannel").setValue(blue(selection.color)); //p5.getController("Thickness").setValue(selection.strokeWeight); } else { p5.getController("redChannel").hide(); p5.getController("greenChannel").hide(); p5.getController("blueChannel").hide(); } } public void redChannel(int t) { if (selection != null) { float r = t; float g = green(selection.color); float b = blue(selection.color); selection.color = color(r,g,b); } } public void greenChannel(int t) { if (selection != null) { float r = red(selection.color); float g = t; float b = blue(selection.color); selection.color = color(r,g,b); } } public void blueChannel(int t) { if (selection != null) { float r = red(selection.color); float g = green(selection.color); float b = t; selection.color = color(r,g,b); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.