controlling ellipse radius with dial rather than mouse?
in
Contributed Library Questions
•
1 year ago
Hi,
I have coded this so that pressing 'r' and dragging ellipse circumference increases the radius. I want to be able to control this using the knob in the control window instead.. can anyone help me with this?
- float x;
- float y;
- float d;
- float dx;
- float dy;
- import controlP5.*;
- import processing.opengl.*;
- ControlP5 cp5;
- Button buttons;
- float rad=50;
- void setup()
- {
- size(800, 600);
- smooth();
- buttons= new Button(width/2, height/2);
- background(0); // draw a black background
- cp5 = new ControlP5(this);
- ControlWindow cw = cp5.addControlWindow("controlP5window", 208, 396, 800, 250, 30);
- Knob k = cp5.addKnob("dial", 0, width, 40, 90, 30);
- k.setWindow(cw);
- }
- void draw() {
- background(10);
- dx=mouseX-width/2;
- //dx=dial;
- dy=mouseY-height/2;
- float d = dist(0, 0, dx, dy);
- fill(0, 0, 255, 150);
- noStroke();
- ellipse(width/2, height/2, 50, 50);
- buttons.display();
- if (mousePressed&&keyPressed) {
- rad=d*2;
- }
- rad=constrain (rad, 50, 120);
- }
- class Button {
- float x, y;
- float h, s, b;
- float transparency;
- Button(float _cx, float _cy) {
- x = _cx;
- y = _cy;
- h=100;
- s=100;
- b=100;
- transparency=20;
- }
- void display() {
- stroke(0.5);
- fill(0, 0, 255, transparency);
- stroke(50, 0, 255, 50);
- strokeWeight(2);
- ellipse (x, y, rad, rad);
- }
- }
1