Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import controlP5.*;
- import processing.serial.*;
- Serial port;
- ControlP5 cp5;
- ColorPicker cp;
- void setup() {
- size(400, 600);
- noStroke();
- cp5 = new ControlP5(this);
- cp = cp5.addColorPicker("picker")
- .setPosition(60, 100)
- .setColorValue(color(255, 128, 0, 128))
- ;
- port = new Serial(this, "COM7", 9600);
- }
- void draw() {
- background(cp.getColorValue());
- fill(0, 80);
- rect(50, 90, 275, 80);
- }
- public void controlEvent(ControlEvent c) {
- // when a value change from a ColorPicker is received, extract the ARGB values
- // from the controller's array value
- if(c.isFrom(cp)) {
- int r = int(c.getArrayValue(0));
- int g = int(c.getArrayValue(1));
- int b = int(c.getArrayValue(2));
- int a = int(c.getArrayValue(3));
- color col = color(r,g,b,a);
- println("event\talpha:"+a+"\tred:"+r+"\tgreen:"+g+"\tblue:"+b+"\tcol"+col);
- import controlP5.*;
- import processing.serial.*;
- Serial port;
- ControlP5 cp5;
- ColorPicker cp;
- void setup() {
- size(400, 600);
- noStroke();
- cp5 = new ControlP5(this);
- cp = cp5.addColorPicker("picker")
- .setPosition(60, 100)
- .setColorValue(color(255, 128, 0, 128))
- ;
- port = new Serial(this, "COM7", 9600);
- }
- void draw() {
- background(cp.getColorValue());
- fill(0, 80);
- rect(50, 90, 275, 80);
- }
- public void controlEvent(ControlEvent c) {
- // when a value change from a ColorPicker is received, extract the ARGB values
- // from the controller's array value
- if(c.isFrom(cp)) {
- port.write(int(c.getArrayValue(0));
- port.write(int(c.getArrayValue(1));
- port.write(int(c.getArrayValue(2));
- port.write(int(c.getArrayValue(3));
- color col = color(r,g,b,a);
- println("event\talpha:"+a+"\tred:"+r+"\tgreen:"+g+"\tblue:"+b+"\tcol"+col);
- }
- }
- // color information from ColorPicker 'picker' are forwarded to the picker(int) function
- void picker(int col) {
- println("picker\talpha:"+alpha(col)+"\tred:"+red(col)+"\tgreen:"+green(col)+"\tblue:"+blue(col)+"\tcol"+col);
- }
- void keyPressed() {
- switch(key) {
- case('1'):
- // method A to change color
- cp.setArrayValue(new float[] {120, 0, 120, 255});
- break;
- case('2'):
- // method B to change color
- cp.setColorValue(color(255, 0, 0, 255));
- break;
- }
- }
- }
- }
- // color information from ColorPicker 'picker' are forwarded to the picker(int) function
- void picker(int col) {
- println("picker\talpha:"+alpha(col)+"\tred:"+red(col)+"\tgreen:"+green(col)+"\tblue:"+blue(col)+"\tcol"+col);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement