Skip to content

Instantly share code, notes, and snippets.

@slambert
Created April 25, 2018 16:13
Show Gist options
  • Save slambert/bbe5b3ed6e7d2ef1b668c0e285d41c67 to your computer and use it in GitHub Desktop.
Save slambert/bbe5b3ed6e7d2ef1b668c0e285d41c67 to your computer and use it in GitHub Desktop.
using controlp5 example
/**
* ControlP5 Knob - modified by Steve
*
*
* find a list of public methods available for the Knob Controller
* at the bottom of this sketch.
*
* by Andreas Schlegel, 2012
* www.sojamo.de/libraries/controlp5
*
*/
import controlP5.*;
ControlP5 cp5;
float radius=150;
int knobValue = 100;
int knobRadius;
Knob myKnobA;
void setup() {
size(700,400);
smooth();
noStroke();
cp5 = new ControlP5(this);
myKnobA = cp5.addKnob("knob")
.setRange(0,255)
.setValue(50)
.setPosition(100,height-150)
.setRadius(50)
.setDragDirection(Knob.VERTICAL)
.setColorForeground(color(255))
.setColorBackground(color(0, 160, 100))
.setColorActive(color(255,255,0))
;
}
void draw() {
background(0);
//fill(255,0,0);
//rect(100,100,myColorBackground+300,myColorBackground+100);
stroke(255);
strokeWeight(3);
pushMatrix();
translate(width/2, height/2);
float angle=TWO_PI/(float)knobRadius;
for(int i=0;i<knobRadius;i++)
{
point(radius*sin(angle*i),radius*cos(angle*i));
}
popMatrix();
noStroke();
}
void knob(int theValue) {
knobRadius = theValue;
println("a knob event. setting background to "+theValue);
}
void keyPressed() {
switch(key) {
case('1'):myKnobA.setValue(50);break;
case('2'):myKnobA.shuffle();break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment