Control P5のチュートリアル

主なコンポーネントの使用方法
http://www.kasperkamperman.com/blog/processing-code/controlp5-library-example1/

フォントの変更方法(デフォルトだとcontrolP5のフォントは小さいと思う)
http://forum.processing.org/topic/control-p5-changing-mouseover-color-font-size-font

色とかサイズとか自分の好みにカスタマイズしてテンプレート化しておく。

import controlP5.*;

ControlP5 controlP5;

void setup() {
  size(640,480);
  smooth();
  //frameRate(30);
  controlP5 = new ControlP5(this);  
  ControlFont cf1 = new ControlFont(createFont("Arial",20));
  createButton("hello",10,200,100,cf1);
  createSlider("LED Slider",0,255,128,100,350,cf1);
  createKnob("Knob",0,255,128,100,200,cf1);
  createNumberBox("NumberBox",100,300,200,cf1);
  createTextfield("Value",200,300,cf1);
}


Textfield createTextfield(String theName,int theX,int theY,ControlFont theFont) {
  Textfield tf = controlP5.addTextfield(theName,theX,theY,100,30);
  tf.captionLabel().setControlFont(theFont);     
  return tf;
}

Numberbox createNumberBox(String theName, int theValue, int theX, int theY, ControlFont theFont) {
  Numberbox n = controlP5.addNumberbox(theName,theValue,theX,theY,100,30);  
  n.captionLabel().setControlFont(theFont);
  return n;
}

Knob createKnob(String theName, int minimum, int maximum, int theValue, int theX, int theY, ControlFont theFont) {
  Knob k = controlP5.addKnob(theName,minimum,maximum,theValue,theX,theY,70);
  k.captionLabel().setControlFont(theFont);
  return k;   
}

//Parameter "Name",min,max,default,x,y,color when clicked,font
//width=300,height=40 is set. Change below.
Slider createSlider(String theName, int minimum, int maximum, int theValue, int theX, int theY, ControlFont theFont) {
  Slider s = controlP5.addSlider(theName,minimum,maximum,theValue,theX,theY,300,40);
  s.captionLabel().setControlFont(theFont);
  return s;    
}

Button createButton(String theName, int theValue, int theX, int theY, ControlFont theFont) {
  Button b = controlP5.addButton(theName,theValue,theX,theY,120,39);
  b.captionLabel().setControlFont(theFont);
  return b;
}


void draw() {
  background(0);
}


public void Knob(int theValue){
   ((Textfield)controlP5.controller("Value")).setValue(""+theValue);
}