int[] minmax_mov = new int[]{1000, 1300}; int zeroing_points = 25; class ball{ float x, ox, y, oy, z, oz;// actual xyz to draw at, and the original xyz we're coming from float steps, step; //stepping along bezier float ax, cx1, cx2, ay, cy1, cy2, az, cz1, cz2; //target anchor, and control points for bezier color c; boolean selected, on; int intc, indx, boxindx, oncount; float em_factor; public ball(int col, int ix){ x = random(room_size[0]); y = random(room_size[1]); z = random(-room_size[2]/2); intc = col; selected = false; on = false; em_factor = 5; set_color(); steps = int(random(minmax_mov[0], minmax_mov[1])); set_path(); indx = ix; boxindx = -1; oncount = 0; } public boolean grab(float bx, float by, float bz, int[] sw, int bi){ if(sw[intc] == 1){ zeroing = false; deselect(); lit_orb = -1; return false; // already has my color } set_path(bx, by, bz); boxindx = bi; steps = zeroing_points; return true; } private void set_color(){ int r = intc == 0 ? 255 : 0; int g = intc == 1 ? 255 : 0; int b = intc == 2 ? 255 : 0; em_factor = selected ? 1.5 : 8; c = color(r,g,b); } public boolean click(){ if (on) return false; float sx = screenX(x, y, z); float sy = screenY(x, y, z); float d = dist(mouseX, mouseY, sx, sy); selected = (d < 10); set_color(); if(selected){ lit_orb = indx; } return selected; } public void deselect(){ selected = false; set_color(); } public void render(){ if(on){ oncount -= 1; if(oncount == 0){ on = false; boxes[boxindx].turnoff(intc); boxindx = -1; set_path(); } return; } travel(); fill(c); emissive(red(c)/em_factor, green(c)/em_factor, blue(c)/em_factor); pushMatrix(); translate(x,y,z); sphere(10); //ellipse(0,0,30,30); popMatrix(); //stroke(200, 5); //bezier(ox, oy, oz, cx1, cy1, cz1, cx2, cy2, cz2, ax, ay, az); //noStroke(); } private void travel(){ float t = step/steps; x = bezierPoint(ox, cx1, cx2, ax, t); y = bezierPoint(oy, cy1, cy2, ay, t); z = bezierPoint(oz, cz1, cz2, az, t); if(step++ >= steps){ if(zeroing && indx == lit_orb){ boxes[boxindx].turnon(intc); on = true; oncount = 2200; // how long the light box stays on with this color.... zeroing = false; selected = false; lit_orb = -1; set_color(); steps = int(random(minmax_mov[0], minmax_mov[1])); }else{ set_path(); } } } private void set_path(){ int padding = 30; float _x = random(padding, room_size[0]-padding); float _y = random(padding, room_size[1]-padding); float _z = random(-padding, (-room_size[2]/2) + padding); set_path(_x, _y, _z); } private void set_path(float px, float py, float pz){ int anchor_range = 180; //set orginal xyz ox = x; oy = y; oz = z; // set anchor point for destination ax = px; ay = py; az = pz; //set control points cx1 = x + random(-anchor_range, anchor_range); cx2 = ax + random(-anchor_range, anchor_range); cy1 = y + random(-anchor_range, anchor_range); cy2 = ay + random(-anchor_range, anchor_range); cz1 = z + random(-anchor_range, anchor_range); cz2 = az + random(-anchor_range, anchor_range); step = 0; } }