Unexpected token error? _pos
              in 
             Programming Questions 
              •  
              1 year ago    
            
 
           
             Could somebody please point out where I am going wrong with this code? I tried to merge two together, but wasn't so successful (obviously, since I wouldn't be here). 
            
             
            
            
             
            
            
              
           
 
            
           
             This is pretty urgent and I am pulling my hair out over this - I feel as though I am so close, yet so far...
            
            
             Please help! 
            
            - Disease[] d = new Disease[55];
 - HealthyCell health;
 - ArrayList<kaleidoscope> kal;
 - kaleidoscope selectedkaleidoscope;
 - // vars for ill cell / kaleidoscope
 - int kaleidoscope_num = 50;
 - float[] kaleidoscope_x= new float[kaleidoscope_num]; //x value
 - float[] kaleidoscope_y= new float[kaleidoscope_num]; //y value
 - float[] kaleidoscope_a= new float[kaleidoscope_num]; //rate of growth
 - color[] kaleidoscope_c= new color[kaleidoscope_num]; //colour
 - //
 - void setup () {
 - size (500, 500);
 - smooth();
 - for (int i = 0; i < d.length; i++) {
 - float x = random(0, 15);
 - float y = map(i, 0, d.length, -100, height-200);
 - d[i] = new Disease(30, x, y);
 - health = new HealthyCell(380, 380, 200);
 - kal = new ArrayList<kaleidoscope>();
 - kal.add(new kaleidoscope(50, 50));
 - }
 - // infected cell
 - for (int i=0; i< kaleidoscope_num;i++) {
 - kaleidoscope_x[i] = random(50);
 - kaleidoscope_y[i] = i* (5/kaleidoscope_num);
 - kaleidoscope_a[i] = random(0.1, 0.3);
 - kaleidoscope_c[i] = color(int(random(255)), 50, 100, 50);
 - }
 - for (kaleidoscope k: kal) {
 - k.draw();
 - }
 - if (isMoving & selectedkaleidoscope!= null) {
 - PVector motion = new PVector(mouseX - pmouseX, mouseY - pmouseY);
 - selectedkaleidoscope._pos.add(motion);
 - }
 - }
 - void draw () {
 - background(0);
 - health.display();
 - for (int i = 0; i < d.length; i++) {
 - d[i].display();
 - d[i].move();
 - if (d[i].intersect(health)) {
 - d[i].attach();
 - }
 - }
 - }
 - void mousePressed() {
 - PVector mousePos = new PVector(mouseX, mouseY);
 - for (kaleidoscope k: kal) {
 - if (k.isMouseOver(mousePos)) {
 - kal.add(new kaleidoscope(k._pos.x, k._pos.y));
 - selectedkaleidoscope = kal.get(kal.size() - 1);
 - break;
 - }
 - }
 - isMoving = true;
 - }
 - void mouseReleased() {
 - isMoving = false;
 - selectedkaleidoscope = null;
 - }
 - /////////////////////////////
 - class Disease {
 - float s;
 - float x;
 - float y;
 - float xIncrement = 5.0;
 - float yIncrement = 5.01;
 - float d;
 - //this determines whether the cell is attached to the health cell or not
 - boolean attached = false;
 - Disease (float d, float tempX, float tempY) {
 - d = s;
 - xIncrement = tempX;
 - yIncrement = tempY;
 - x = 40;
 - y = 40;
 - }
 - void move () {
 - //if I am not attached to the helth cell
 - if (attached == false) {
 - float d = dist(mouseX, mouseY, x, y);
 - d = constrain(d, 0, 50);
 - float speed = map(d, 0, 49, 0.2, 0.001);
 - xIncrement += speed;
 - yIncrement += speed-0.01;
 - x = noise(xIncrement)*width;
 - y = noise(yIncrement)*height;
 - }
 - else {
 - //get it to do the stuff that attaches it to the healthy cell
 - //"constrain" it within the cell
 - //move slower
 - float speed = 0.005;
 - xIncrement += speed;
 - yIncrement += speed-0.001;
 - //instead of being able to move anywhere one the screen move only around the cell area
 - //i.e. move to the top of the circle then constrict the noise to the diameter of the health cell
 - y = (health.y-health.diam/2) + noise(yIncrement)*health.diam;
 - x = (health.x-health.diam/2) + noise(xIncrement)*health.diam;
 - fill(0, 255, 0);
 - }
 - }
 - void attach() {
 - //speed = 0;
 - //y = 10;
 - //changes the attached variable to true
 - if (!attached) {
 - // tell the cell it got one virus more
 - health.cellCount++;
 - attached = true;
 - }
 - }
 - boolean intersect(HealthyCell tempH) {
 - // Calculate distance
 - float distance = dist(x, y, tempH.x, tempH.y);
 - if (distance < d/2 + tempH.diam/2) {
 - return true;
 - }
 - else {
 - return false;
 - }
 - }
 - void display () {
 - noStroke();
 - stroke(random(255), 50, 100);
 - fill(30);
 - ellipse(random(x, x+3), random(y, y+3), s-5, s-5);
 - }
 - }
 - ////////////////////////////
 - class HealthyCell {
 - float x;
 - float y;
 - int diam;
 - float angle = 0.0;
 - float offset = 60;
 - float scalar = 30;
 - float speed = 0.05;
 - // health data
 - boolean bHealthy;
 - int cellCount;
 - //click drag
 - boolean isMoving;
 - PVector _pos.x;
 - PVector _pos.y;
 - int _radius = 200;
 - HealthyCell (float tempX, float tempY, int d) {
 - x = tempX;
 - y = tempY;
 - diam = d;
 - cellCount = 0;
 - bHealthy = true;
 - _pos.x = new PVector;
 - _pos.y = new PVector;
 - }
 - void display() {
 - strokeWeight(5);
 - if (cellCount > 15) {
 - if (bHealthy) {
 - println ("infection");
 - }
 - bHealthy=false;
 - }
 - // if healthy
 - if (bHealthy) {
 - // if healthy border is gray
 - stroke(random(255), 50, 50, 50);
 - fill(50);
 - ellipse(x, y, diam, diam);
 - } // if
 - else {
 - kaleidoscope();
 - } // else
 - } // method
 - void kaleidoscope () {
 - for (int i=0; i< kaleidoscope_num; i++) {
 - stroke(random(255), 50, 50);
 - fill(kaleidoscope_c[i]);
 - ellipse(_pos.x, _pos.y, _radius-int(kaleidoscope_x[i]), _radius-int(kaleidoscope_x[i]));
 - kaleidoscope_x[i]=kaleidoscope_x[i]+ kaleidoscope_a[i];
 - if (kaleidoscope_x[i]> 200) {
 - kaleidoscope_x[i] = -100;
 - } // if
 - } // for
 - } // method
 - boolean isMouseOver(PVector mouse) {
 - if (_pos.dist(mouse) <= _radius) {
 - return true;
 - }
 - else {
 - return false;
 - }
 - }
 - } // class
 - class HealthyCell {
 - float x;
 - float y;
 - int diam;
 - float angle = 0.0;
 - float offset = 60;
 - float scalar = 30;
 - float speed = 0.05;
 - // health data
 - boolean bHealthy;
 - int cellCount;
 - //click drag
 - boolean isMoving;
 - PVector _pos.x;
 - PVector _pos.y;
 - int _radius = 200;
 - HealthyCell (float tempX, float tempY, int d) {
 - x = tempX;
 - y = tempY;
 - diam = d;
 - cellCount = 0;
 - bHealthy = true;
 - _pos.x = new PVector;
 - _pos.y = new PVector;
 - }
 - void display() {
 - strokeWeight(5);
 - if (cellCount > 15) {
 - if (bHealthy) {
 - println ("infection");
 - }
 - bHealthy=false;
 - }
 - // if healthy
 - if (bHealthy) {
 - // if healthy border is gray
 - stroke(random(255), 50, 50, 50);
 - fill(50);
 - ellipse(x, y, diam, diam);
 - } // if
 - else {
 - kaleidoscope();
 - } // else
 - } // method
 - void kaleidoscope () {
 - for (int i=0; i< kaleidoscope_num; i++) {
 - stroke(random(255), 50, 50);
 - fill(kaleidoscope_c[i]);
 - ellipse(_pos.x, _pos.y, _radius-int(kaleidoscope_x[i]), _radius-int(kaleidoscope_x[i]));
 - kaleidoscope_x[i]=kaleidoscope_x[i]+ kaleidoscope_a[i];
 - if (kaleidoscope_x[i]> 200) {
 - kaleidoscope_x[i] = -100;
 - } // if
 - } // for
 - } // method
 - boolean isMouseOver(PVector mouse) {
 - if (_pos.dist(mouse) <= _radius) {
 - return true;
 - }
 - else {
 - return false;
 - }
 - }
 - } // class
 
 
              
              1  
            
 
            