Processing code

processingjs

#1

Hi guys! I don't know if anybody can help me with my processing code. I currently need to use the data string rgb values generated by the mouse rollover. I want to use these values to make a fill() on new elipses on top of the old array of elipses.
Does anyone know how to do so?

Help much appreciated!

import http.requests.*;
import processing.net.*;

PVector[] circles = new PVector[25];
int circleSize = 50;
int currentIndex = 0;
void setup() {
  size(1280, 720);
  // add circles to the screen
  buildUI();
}
// loop
void draw() {
// updates mouse position  
  update();  
}

void buildUI() {
  int rows = 0; // current number of columns
  int column = 0; // generic counter
  // loop through the number of circles we want 
  for (int i=0; i<circles.length; i++) {
    // calculate position x and y for the circles
    int circleX = 100 + ((circleSize + 10) * column);
    int circleY = 100 + ((circleSize + 10 ) * rows); 
    // define a new point and add it to the list of circle positions
    circles[i] = new PVector(circleX, circleY);
    // draw a circle
    ellipse(circleX, circleY, circleSize, circleSize);
    // if the counter is equals to 4, 
    //reset and create a new column
    if (column >= 4) {
      rows++;
      column = 0;
    } else {
      column++;
    }
  }
}
void update () {
  // iterate over circles
  for (int i = 0; i < circles.length; i++) {
    // verify if it' a hit
    if ( overCircle( int(circles[i].x), int(circles[i].y), circleSize) ) {
      // if current hit is not the same as before
      if (i != currentIndex) {
        
        ellipse(circles[i].x, circles[i].y, circleSize, circleSize);
        // update our current selected circle
        currentIndex = i;
        // do the request
        doRequest();
      }
    }
  }
}
void doRequest() {
  // generate random values to the parameters expected by the lights
  String data = "/?fq1=1&fq2=" + int(random(254)) + "&fq3=" + int(random(254)) + "&fq4=" + int(random(254)) + "&fq5=1&fq6=0&fq7=" + int(random (12));
  
  GetRequest httpRequest = new GetRequest("http://192.168.4." + (currentIndex + 1)+ data);
  httpRequest.send();
  println("Reponse Content: " + httpRequest.getContent());
  println("Reponse Content-Length Header: " + httpRequest.getHeader("Content-Length"));
}
// check rollover
boolean overCircle(int x, int y, int diameter) {
  // calculate mouse distance from the circle 
  float disX = x - mouseX;
  float disY = y - mouseY;
  // check if the mouse is in bounds.
  if (sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
    return true;
  } else {
    return false;
  }
}