Language translation

I am working with an old open processing sktech I translated to processing. It used to work but it does not, coul you please help me?

color[] colors = {
  color(#edb218),
  color(#029cc2),
  color(#6b8c87),
  color(#a5473d),
  color(#588344),
  color(#28312e),
  color(#edb218),
  color(#029cc2),
  color(#6b8c87),
  color(#a5473d),
  color(#588344)
};

ArrayList<Placement> fromPlacements = new ArrayList<Placement>();
ArrayList<Placement> toPlacements = new ArrayList<Placement>();
ArrayList<ShapeDancer> shapeDancers = new ArrayList<ShapeDancer>();

int frames = 150;
PGraphics p;

void setup() {
  size(1000, 1000);
  background(color(238, 235, 211));
  
  float spitA = random(-PI/3, PI/3);
  
  Placement spit = new Placement(spitA, new PVector(width/2, height/2), height*0.03, width*0.8);
  fromPlacements.add(spit);
  
  for(int i = 0; i < 3; i++) {
    spit = new Placement(spitA, new PVector(random(width), random(height)), height*0.02, random(height*0.3, height*0.6));
    fromPlacements.add(spit); 
  }
  
  for(float a = spitA + PI/2 + PI/3; a < spitA + PI/2 + TWO_PI - PI/3; a += PI/12) {
    float d = random(height*0.05, height*0.5);
    float xer = width/2 + cos(PI/2 + a) * d;
    float yer = height/2 + sin(PI/2 + a) * d;
    float her = random(height*0.01, height*0.3);
    float wer = random(height*0.01, height*0.3);
    Placement shape = new Placement(spitA, new PVector(xer, yer), her, wer);
    fromPlacements.add(shape);
  }
  
  spitA = random(-PI/3, PI/3);
  spit = new Placement(spitA, new PVector(width/2, height/2), height*0.03, width*0.8);
  toPlacements.add(spit);
  
  for(int i = 0; i < 3; i++) {
    spit = new Placement(spitA, new PVector(random(width), random(height)), height*0.02, random(height*0.3, height*0.6));
    toPlacements.add(spit); 
  }
  
  for(float a = spitA + PI/2 + PI/3; a < spitA + PI/2 + TWO_PI - PI/3; a += PI/12) {
    float d = random(height*0.05, height*0.5);
    float xer = width/2 + cos(PI/2 + a) * d;
    float yer = height/2 + sin(PI/2 + a) * d;
    float her = random(height*0.01, height*0.3);
    float wer = random(height*0.01, height*0.3);
    Placement shape2 = new Placement(spitA, new PVector(xer, yer), her, wer);
    toPlacements.add(shape2);
  }
  
  //Collections.shuffle(toPlacements, true);
  
  for(int i = 0; i < fromPlacements.size(); i++) {
    shapeDancers.add(new ShapeDancer(i));
  }
  
  p = createGraphics((int)(height * 1.5), height);
  
  for(int i = 0; i < 100000; i++) {
    p.noStroke();
    p.fill(255, (int)random(5, 10));
    //p.ellipse(random(width), random(height), random(1, 3));
  }
}

void draw() {
  blendMode(MULTIPLY);
  clear();
  background(238, 235, 211);

  
  if(frameCount % 300 == 0) {
    fromPlacements = new ArrayList<Placement>(toPlacements);
    toPlacements.clear();
    
    float spitA = random(-PI/3, PI/3);
    Placement spit = new Placement(spitA, new PVector(width/2, height/2), height*0.03, width*0.8);
    toPlacements.add(spit);
    
    for(int i = 0; i < 3; i++) {
      spit = new Placement(spitA, new PVector(random(width), random(height)), height*0.02, random(height*0.3, height*0.6));
      toPlacements.add(spit); 
    }
    
    for(float a = spitA + PI/2 + PI/3; a < spitA + PI/2 + TWO_PI - PI/3; a += PI/12) {
      float d = random(height*0.05, height*0.5);
      float xer = width/2 + cos(PI/2 + a) * d;
      float yer = height/2 + sin(PI/2 + a) * d;
      float her = random(height*0.01, height*0.3);
      float wer = random(height*0.01, height*0.3);
      Placement shape2 = new Placement(spitA, new PVector(xer, yer), her, wer);
      toPlacements.add(shape2);
    }
    
    //Collections.shuffle(toPlacements, true);
  }
  
  for(ShapeDancer shapeDancer : shapeDancers) {
    shapeDancer.dance();
    shapeDancer.show();
  }
  
  push();
  blendMode(BLEND);
  image(p, 0, 0);
  pop();
      

}

class Placement {
  float between;
  int index;
  float theta;
  PVector pos;
  float h;
  float w;
  String colors;
  
  Placement(float angle, PVector position, float height, float width) {
    between = 0;
    index = 0;
    theta = angle;
    pos = position;
    h = height;
    w = width;
   // colors = colors.get((int)random(colors.size()));
  }
}

class ShapeDancer {
  float between;
  int index;
  float theta;
  PVector pos;
  float h;
  float w;
  String colors;
  
  ShapeDancer(int idx) {
    between = 0;
    index = idx;
    theta = fromPlacements.get(idx).theta;
    pos = fromPlacements.get(idx).pos;
    h = fromPlacements.get(idx).h;
    w = fromPlacements.get(idx).w;
    colors = fromPlacements.get(idx).colors;
  }
  
  void dance() {
    if(frameCount % 300 == 0) {
      between = 0;
    }
    
    float framesMap = map(between, 0, frames, 0, 1);
    pos = PVector.lerp(fromPlacements.get(index).pos, toPlacements.get(index).pos, easeInOutSine(framesMap));
    h = lerp(fromPlacements.get(index).h, toPlacements.get(index).h, easeInOutSine(framesMap));
    w = lerp(fromPlacements.get(index).w, toPlacements.get(index).w, easeInOutSine(framesMap));
    theta = lerp(fromPlacements.get(index).theta, toPlacements.get(index).theta, easeInOutBounce(framesMap));
    
    if(between < frames) {
      between += 1;

    }
  }
  
  
  void show() {
    noStroke();
    fill(0,124,0);
    push();
    rectMode(CENTER);
    translate(pos.x, pos.y);
    rotate(theta);
    rect(0, 0, w, h);
    pop();
  }
}


float easeInOutSine(float x) {
  return -(cos(PI * x) - 1) / 2;
}

float easeOutBounce(float x) {
  float n1 = 7.5625;
  float d1 = 2.75;
  if (x < 1 / d1) {
    return n1 * x * x;
  } else if (x < 2 / d1) {
    return n1 * (x -= 1.5 / d1) * x + 0.75;
  } else if (x < 2.5 / d1) {
    return n1 * (x -= 2.25 / d1) * x + 0.9375;
  } else {
    return n1 * (x -= 2.625 / d1) * x + 0.984375;
  }
}

float easeInOutBounce(float x) {
  if (x < 0.5) {
    return (1 - easeOutBounce(1 - 2 * x)) / 2;
  } else {
    return (1 + easeOutBounce(2 * x - 1)) / 2;
  }
}

I have to say, it runs here fine.

Can you describe what part is not working for you?

This p is not really doing anything: PGraphics p;

I’m on Win 10 with processing 4.3.2

Chrisir



color[] colors = {
  color(#edb218),
  color(#029cc2),
  color(#6b8c87),
  color(#a5473d),
  color(#588344),
  color(#28312e),
  color(#edb218),
  color(#029cc2),
  color(#6b8c87),
  color(#a5473d),
  color(#588344)
};

ArrayList<Placement>   fromPlacements = new ArrayList<Placement>();
ArrayList<Placement>   toPlacements   = new ArrayList<Placement>();
ArrayList<ShapeDancer> shapeDancers   = new ArrayList<ShapeDancer>();

int frames = 150;
PGraphics p;

// ----------------------------------------------------------------------------------------------

void setup() {
  size(1000, 1000);
  background(color(238, 235, 211));

  float spitA = random(-PI/3, PI/3);

  Placement spit = new Placement(spitA, new PVector(width/2, height/2), height*0.03, width*0.8);
  fromPlacements.add(spit);

  for (int i = 0; i < 3; i++) {
    spit = new Placement(spitA, new PVector(random(width), random(height)), height*0.02, random(height*0.3, height*0.6));
    fromPlacements.add(spit);
  }

  for (float a = spitA + PI/2 + PI/3; a < spitA + PI/2 + TWO_PI - PI/3; a += PI/12) {
    float d = random(height*0.05, height*0.5);
    float xer = width/2 + cos(PI/2 + a) * d;
    float yer = height/2 + sin(PI/2 + a) * d;
    float her = random(height*0.01, height*0.3);
    float wer = random(height*0.01, height*0.3);
    Placement shape = new Placement(spitA, new PVector(xer, yer), her, wer);
    fromPlacements.add(shape);
  }

  spitA = random(-PI/3, PI/3);
  spit = new Placement(spitA, new PVector(width/2, height/2), height*0.03, width*0.8);
  toPlacements.add(spit);

  for (int i = 0; i < 3; i++) {
    spit = new Placement(spitA, new PVector(random(width), random(height)), height*0.02, random(height*0.3, height*0.6));
    toPlacements.add(spit);
  }

  for (float a = spitA + PI/2 + PI/3; a < spitA + PI/2 + TWO_PI - PI/3; a += PI/12) {
    float d = random(height*0.05, height*0.5);
    float xer = width/2 + cos(PI/2 + a) * d;
    float yer = height/2 + sin(PI/2 + a) * d;
    float her = random(height*0.01, height*0.3);
    float wer = random(height*0.01, height*0.3);
    Placement shape2 = new Placement(spitA, new PVector(xer, yer), her, wer);
    toPlacements.add(shape2);
  }

  //Collections.shuffle(toPlacements, true);

  for (int i = 0; i < fromPlacements.size(); i++) {
    shapeDancers.add(new ShapeDancer(i));
  }

  p = createGraphics((int)(height * 1.5), height);

  for (int i = 0; i < 100000; i++) {
    p.noStroke();
    p.fill(255, (int)random(5, 10));
    //p.ellipse(random(width), random(height), random(1, 3));
  }
}//setup

void draw() {
  background(238, 235, 211);
  // clear();
  blendMode(MULTIPLY);

  if (frameCount % 300 == 0) {
    fromPlacements = new ArrayList<Placement>(toPlacements);
    toPlacements.clear();

    float spitA = random(-PI/3, PI/3);
    Placement spit = new Placement(spitA, new PVector(width/2, height/2), height*0.03, width*0.8);
    toPlacements.add(spit);

    for (int i = 0; i < 3; i++) {
      spit = new Placement(spitA, new PVector(random(width), random(height)), height*0.02, random(height*0.3, height*0.6));
      toPlacements.add(spit);
    }

    for (float a = spitA + PI/2 + PI/3; a < spitA + PI/2 + TWO_PI - PI/3; a += PI/12) {
      float d = random(height*0.05, height*0.5);
      float xer = width/2 + cos(PI/2 + a) * d;
      float yer = height/2 + sin(PI/2 + a) * d;
      float her = random(height*0.01, height*0.3);
      float wer = random(height*0.01, height*0.3);
      Placement shape2 = new Placement(spitA, new PVector(xer, yer), her, wer);
      toPlacements.add(shape2);
    }

    //Collections.shuffle(toPlacements, true);
  }

  for (ShapeDancer shapeDancer : shapeDancers) {
    shapeDancer.dance();
    shapeDancer.show();
  }

  push();
  blendMode(BLEND);
  image(p, 0, 0);
  pop();
}//draw

//===================================================================================================

class Placement {
  float between;
  int index;
  float theta;
  PVector pos;
  float h;
  float w;
  String colors;

  Placement(float angle, PVector position, float height, float width) {
    between = 0;
    index = 0;
    theta = angle;
    pos = position;
    h = height;
    w = width;
    // colors = colors.get((int)random(colors.size()));
  }
}

//===================================================================================================

class ShapeDancer {
  float between;
  int index;
  float theta;
  PVector pos;
  float h;
  float w;
  String colors;

  ShapeDancer(int idx) {
    between = 0;
    index = idx;
    theta = fromPlacements.get(idx).theta;
    pos = fromPlacements.get(idx).pos;
    h = fromPlacements.get(idx).h;
    w = fromPlacements.get(idx).w;
    colors = fromPlacements.get(idx).colors;
  }

  void dance() {
    if (frameCount % 300 == 0) {
      between = 0;
    }

    float framesMap = map(between, 0, frames, 0, 1);
    pos = PVector.lerp(fromPlacements.get(index).pos, toPlacements.get(index).pos, easeInOutSine(framesMap));
    h = lerp(fromPlacements.get(index).h, toPlacements.get(index).h, easeInOutSine(framesMap));
    w = lerp(fromPlacements.get(index).w, toPlacements.get(index).w, easeInOutSine(framesMap));
    theta = lerp(fromPlacements.get(index).theta, toPlacements.get(index).theta, easeInOutBounce(framesMap));

    if (between < frames) {
      between += 1;
    }
  }

  void show() {
    noStroke();
    fill(0, 124, 0);
    push();
    rectMode(CENTER);
    translate(pos.x, pos.y);
    rotate(theta);
    rect(0, 0, w, h);
    pop();
  }

  float easeInOutSine(float x) {
    return -(cos(PI * x) - 1) / 2;
  }//method

  float easeOutBounce(float x) {
    float n1 = 7.5625;
    float d1 = 2.75;
    if (x < 1 / d1) {
      return n1 * x * x;
    } else if (x < 2 / d1) {
      return n1 * (x -= 1.5 / d1) * x + 0.75;
    } else if (x < 2.5 / d1) {
      return n1 * (x -= 2.25 / d1) * x + 0.9375;
    } else {
      return n1 * (x -= 2.625 / d1) * x + 0.984375;
    }
  }//method

  float easeInOutBounce(float x) {
    if (x < 0.5) {
      return (1 - easeOutBounce(1 - 2 * x)) / 2;
    } else {
      return (1 + easeOutBounce(2 * x - 1)) / 2;
    }
  }//method
  //
}//class
//===================================================================================================
//

1 Like

This is the android app

sorry, can’t help you with that

1 Like