Scale using controlp5 controler
in
Contributed Library Questions
•
3 months ago
Hi,
I'm trying to scale the rectaingles using slider from controlp5 library. I've found some similar example at
http://www.stefanstubbe.com/blog/wp-content/uploads/2008/05/difa_07_s_ringplant.pde, but unfortunatelly I can't run this example, because P3D is not supported by my hardware/diver, so I can't really figure out how it works.
I've written some piece of code, with 2d rectangles, but it seems to not be working... Can somebody tell me what is wrong here, please ?
- import controlP5.*;
- ControlP5 controlP5;
- float x1, y1, x2, y2, x3, y3, h1, h2, h3, w;
- float scale = 0.92;
- void setup(){
- controlP5 = new ControlP5(this);
- Controller mySlider4 = controlP5.addSlider("scale",0.7,1.3,scale,20,80,100,10);
- size(779, 500);
- background(2, 240, 222);
- x1 = 0;
- y1 = 140;
- x2 = 0;
- y2 = 250;
- y3 = 0;
- y3 = 380;
- w = 2;
- h1 = 2.5;
- h2 = 5;
- h3 = 10;
- noStroke();
- }
- void draw(){
- fill(255);
- rect(x1, y1, h1, w);
- rect(x1 + 2.5, y1, h1, w);
- rect(x1 +5, y1, h1, w);
- rect(x1 +7.5, y1, h1, w);
- rect(x2, y2, h2, w);
- rect(x2+5, y2, h2, w);
- rect(x3, y3, h3, w);
- rect(x1*10, y1, h1, w);
- rect((x1*10) + 2.5, y1, h1, w);
- rect((x1*10) + 5, y1, h1, w);
- rect((x1*10) + 7.5, y1, h1, w);
- rect(x2*10, y2, h2, w);
- rect((x2*10) + 5, y2, h2, w);
- rect(x3*10, y3, h3, w);
- }
- void controlEvent(ControlEvent theEvent) {
- if (theEvent.isGroup()) {
- println(theEvent.getGroup().getName());
- }
- else if (theEvent.isController()) {
- println(theEvent.getController().getName());
- if (theEvent.controller().name()=="scale") {
- scale(scale*y1*x1*x2*y2*x3*y3*h1*h2*h3*w); }
- }
- }
1