Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Convert Processing sketch to openFrameworks

$
0
0

@Gallo wrote:

Hello,

I am trying to port a processing sketch to openFrameworks
No problem with porting types and other specific language usage but there is one thing i don't know how to deal with :

paths = (pathfinder[]) append(paths, new pathfinder(this));

in the pathfinder update() method.

the paths array is declared elsewhere. And how this 'paths' can be used inside the pathfinder class ?
Sorry i don't really know how to explain the problem... hope i am making myself clear :slight_smile:

here is the Processing code.

thanks a lot

class pathfinder {
  PVector location;
  PVector velocity;
  float diameter;
  pathfinder() {
    location = new PVector(width/2, height);
    velocity = new PVector(0, -1);
    diameter = 32;
  }
  pathfinder(pathfinder parent) {
    location = parent.location.get();
    velocity = parent.velocity.get();
    float area = PI*sq(parent.diameter/2);
    float newDiam = sqrt(area/2/PI)*2;
    diameter = newDiam;
    parent.diameter = newDiam;
  }
  void update() {
    if (diameter>0.5) {
      location.add(velocity);
      PVector bump = new PVector(random(-1, 1), random(-1, 1));
      bump.mult(0.1);
      velocity.add(bump);
      velocity.normalize();
      if (random(0, 1)<0.02) {
        paths = (pathfinder[]) append(paths, new pathfinder(this));
      }
    }
  }
}
pathfinder[] paths;
void setup() {
  size(800, 600);
  background(0);
  ellipseMode(CENTER);
  fill(255);
  noStroke();
  smooth();
  paths = new pathfinder[1];
  paths[0] = new pathfinder();
}
void draw() {
  for (int i=0;i<paths.length;i++) {
    PVector loc = paths[i].location;
    float diam = paths[i].diameter;
    ellipse(loc.x, loc.y, diam, diam);
    paths[i].update();
  }
}
void mousePressed() {
  background(0);
  paths = new pathfinder[1];
  paths[0] = new pathfinder();
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles