Issues with updating Array
in
Contributed Library Questions
•
3 months ago
Hello,
I am creating a sketch that uses GUI radio buttons to update the value in my array. I've debugged as much as I could but still do not understand why my visuals (that link to the number in the array) don't update as well. When I click on the radio button, it prints the correct value the array has - but no update has been made on the visuals... Could you please look below and show me where I'm going wrong with this..
to be clear: problem is that my visuals are not updating the same as the array assigned to it.
This is the main code that has all the GUI values and such... to help you I'm using the ControlP5 library (download
http://www.sojamo.de/libraries/controlP5/) for this..
- import java.util.Calendar;
- import processing.pdf.*;
- boolean savePDF = false;
- import controlP5.*;
- ControlP5 cp5;
- ControlP5 cp52;
- ControlP5 cp53;
- ControlP5 cp54;
- RadioButton r;
- RadioButton r2;
- RadioButton r3;
- RadioButton r4;
- RadioButton r5;
- RadioButton r6;
- RadioButton r7;
- int myColorBackground;
- int actRandomSeed = 0;
- int lib1=2448;
- int lib2=1106;
- int web1=3765;
- int web2=912;
- library_1[] library_1Array = new library_1[(lib1)/50];
- library_2[] library_2Array = new library_2[(lib2)/50];
- website_1[] website_1Array = new website_1[(web1)/50];
- website_2[] website_2Array = new website_2[(web2)/50];
- float stepSize = 0.1;
- void setup() {
- size(1200,600);
- background(4,123,181);
- cursor(CROSS);
- smooth();
- //STORED VALUES FOR UTS LIBRARY GENERAL
- cp5 = new ControlP5(this);
- r = cp5.addRadioButton("radioButton")
- .setPosition(100,70)
- .setSize(20,20)
- .setColorForeground(color(120)) // highlight colour
- .setColorActive(color(255)) //once clicked colour
- .setColorLabel(color(0)) //text colour
- .setItemsPerRow(1)
- .setSpacingColumn(50)
- .addItem("0", 2448)
- .addItem("4", 1911)
- .addItem("8", 3517)
- .addItem("12", 2958)
- .addItem("16", 3490)
- .addItem("20", 2109)
- .addItem("24", 963)
- ;
- //STORED VALUES FOR UTS LIBRARY RESEARCH
- cp52 = new ControlP5(this);
- r2 = cp52.addRadioButton("radioButton")
- .setPosition(160,70)
- .setSize(20,20)
- .setColorForeground(color(120))
- .setColorActive(color(255))
- .setColorLabel(color(0))
- .setItemsPerRow(1)
- .setSpacingColumn(50)
- .addItem("1", 1106)
- .addItem("5", 762)
- .addItem("9", 2094)
- .addItem("13", 1626)
- .addItem("17", 1561)
- .addItem("21", 959)
- .addItem("25", 437)
- ;
- //STORED VALUES FOR IOS GENERAL
- cp53 = new ControlP5(this);
- r3 = cp53.addRadioButton("radioButton")
- .setPosition(220,70)
- .setSize(20,20)
- .setColorForeground(color(120))
- .setColorActive(color(255))
- .setColorLabel(color(0))
- .setItemsPerRow(1)
- .setSpacingColumn(50)
- .addItem("2", 3765)
- .addItem("6", 2399)
- .addItem("10", 4611)
- .addItem("14", 3881)
- .addItem("18", 3670)
- .addItem("22", 2955)
- .addItem("26", 1317)
- ;
- //STORED VALUES FOR IOS RESEARCH
- cp54 = new ControlP5(this);
- r4 = cp54.addRadioButton("radioButton")
- .setPosition(280,70)
- .setSize(20,20)
- .setColorForeground(color(120))
- .setColorActive(color(255))
- .setColorLabel(color(0))
- .setItemsPerRow(1)
- .setSpacingColumn(50)
- .addItem("3", 912)
- .addItem("7", 416)
- .addItem("11", 2192)
- .addItem("15", 1739)
- .addItem("19", 1982)
- .addItem("23", 969)
- .addItem("27", 399)
- ;
- for(int i = 0; i<library_1Array.length; i++){
- library_1Array[i]= new library_1(random(400,width),random(height));
- }
- for(int i = 0; i<library_2Array.length; i++){
- library_2Array[i]= new library_2(random(400,width),random(height));
- }
- for(int i = 0; i<website_1Array.length; i++){
- website_1Array[i]= new website_1();
- }
- for(int i = 0; i<website_2Array.length; i++){
- website_2Array[i]= new website_2();
- }
- }
- void draw() {
- // if (savePDF) beginRecord(PDF, timestamp()+".pdf");
- background(255);
- noStroke();
- for(int i = 0; i<library_1Array.length; i++){
- library_1Array[i].update();
- library_1Array[i].draw();
- }
- for(int i = 0; i<library_2Array.length; i++){
- library_2Array[i].update();
- library_2Array[i].draw();
- }
- for(int i = 0; i<website_1Array.length; i++){
- website_1Array[i].update();
- website_1Array[i].draw();
- }
- for(int i = 0; i<website_2Array.length; i++){
- website_2Array[i].update();
- website_2Array[i].draw();
- }
- //text
- fill(0);
- rect(0,0,400,height);
- fill(255);
- text("JUN",60,85);
- text("JUL",60,105);
- text("AUG",60,125);
- text("SEP",60,145);
- text("OCT",60,170);
- text("NOV",60,190);
- text("DEC",60,210);
- textSize(10);
- text("GENERAL",90,60);
- text("RESEARCH",145,60);
- text("GENERAL",210,60);
- text("RESEARCH",265,60);
- text("iOS",250,40);
- text("UTS LIBRARY",110,40);
- String s = "My idea is to compare and analyse the behaviour of students accessing the website (from their devices) for library services VS students using the 'physical' library. I want to draw out how technology affects how students interact with the 'physical' library. This will help us understand what parts of the website are successful and what parts are not and need working - and vice versa with the library help desk.";
- text(s, 60, 250, 255, height);
- }
- void mouseReleased() {
- actRandomSeed = (int) random(100000);
- }
- void keyReleased() {
- if (key == 's' || key == 'S') saveFrame(timestamp()+"_####.png");
- if (key == 'p' || key == 'P') savePDF = true;
- }
- String timestamp() {
- Calendar now = Calendar.getInstance();
- return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
- }
- //GUI radio button controls
- void keyPressed() {
- switch(key) {
- case('0'): r.deactivateAll(); break;
- case('1'): r.activate(0); break;
- case('2'): r.activate(1); break;
- case('3'): r.activate(2); break;
- case('4'): r.activate(3); break;
- case('5'): r.activate(4); break;
- }
- }
- //UTS LIBRARY GENERAL ENQUIRIES
- void controlEvent(ControlEvent theEvent) {
- if(theEvent.isFrom(r)) {
- print("got an event from "+theEvent.getName()+"\t");
- for(int i=0;i<theEvent.getGroup().getArrayValue().length;i++) {
- print(int(theEvent.getGroup().getArrayValue()[i]));
- }
- println("\t "+theEvent.getValue());
- lib1=int(theEvent.group().value());
- library_1[] library_1Array = new library_1[(lib1)/50];
- for(int i = 0; i<library_1Array.length; i++){
- library_1Array[i]= new library_1(width/2,height/2);
- }
- println(library_1Array.length);
- }
- //UTS LIBRARY RESEARCH ENQUIRIES
- if(theEvent.isFrom(r2)) {
- print("got an event from "+theEvent.getName()+"\t");
- for(int i=0;i<theEvent.getGroup().getArrayValue().length;i++) {
- print(int(theEvent.getGroup().getArrayValue()[i]));
- }
- println("\t "+theEvent.getValue());
- lib2=int(theEvent.group().value());
- library_2[] library_2Array = new library_2[(lib2)/50];
- for(int i = 0; i<library_2Array.length; i++){
- library_2Array[i]= new library_2(width/2,height/2);
- }
- }
- //IOS GENERAL ENQUIRIES
- if(theEvent.isFrom(r3)) {
- print("got an event from "+theEvent.getName()+"\t");
- for(int i=0;i<theEvent.getGroup().getArrayValue().length;i++) {
- print(int(theEvent.getGroup().getArrayValue()[i]));
- }
- println("\t "+theEvent.getValue());
- web1=int(theEvent.group().value());
- website_1[] website_1Array = new website_1[(web1)/50];
- for(int i = 0; i<website_1Array.length; i++){
- website_1Array[i]= new website_1();
- }
- }
- //IOS RESEARCH ENQUIRIES
- if(theEvent.isFrom(r4)) {
- print("got an event from "+theEvent.getName()+"\t");
- for(int i=0;i<theEvent.getGroup().getArrayValue().length;i++) {
- print(int(theEvent.getGroup().getArrayValue()[i]));
- }
- println("\t "+theEvent.getValue());
- web2=int(theEvent.group().value());
- website_2[] website_2Array = new website_2[(web2)/50];
- for(int i = 0; i<website_2Array.length; i++){
- website_2Array[i]= new website_2();
- }
- }
- }
- void radioButton(int a) {
- println("a radio Button event: "+a);
- }
You can change the fill() to help you distinguish the classes
- class library_1{
- float xPos; // X-coordinate
- float yPos; // Y-coordinate
- float angle; // Direction of motion
- float speed; // Speed of motion
- float initRadius;
- float radius;
- float minRadius;
- float maxRadius;
- float radiusInc;
- library_1(float a, float b){
- xPos=a;
- yPos=b;
- angle = random(TWO_PI);
- speed = 3;
- initRadius=30;
- radius=random(15,30);
- minRadius=15;
- maxRadius=30;
- radiusInc=0.4;
- }
- void update(){
- float dx = cos(angle) * speed;
- float dy = sin(angle) * speed;
- xPos = constrain(xPos + dx, -(initRadius), width+initRadius);
- yPos = constrain(yPos + dy, -(initRadius), height+initRadius);
- angle += random(-1, 1);
- if(radius<minRadius || radius>maxRadius)
- {
- radiusInc*=-1;
- }
- radius+=radiusInc;
- }
- void draw(){
- noStroke();
- if (xPos > width) xPos = 400;
- if (xPos < 400) xPos = width;
- if (yPos < 0) yPos = height;
- if (yPos > height) yPos = 0;
- //CHANGE MY COLOUR TO DISTINGUISH BETWEEN THE CLASSES
- fill(4,123,181);
- ellipse(xPos,yPos,radius,radius);
- }
- }
astr0boi
1