コード例 #1
0
ファイル: PlanetScape.java プロジェクト: kmshiva/PlanetScape
 public void drawOrbits(ArrayList alObjectsArchive) {
   //  println("SIZE:" + alObjectsArchive.size());
   //  ArrayList alObjectsArchive = timeline.getObjectStateArchive();
   ArrayList alPrevPos = new ArrayList();
   ArrayList alColors = new ArrayList();
   alColors.add(color(255, 0, 0));
   alColors.add(color(255, 255, 0));
   alColors.add(color(255, 0, 255));
   //  for (int i = timeline.getTimeIdx(); i >= 0 && i > (timeline.getTimeIdx() - 1 - 100); i--)
   for (int i = 0; i < alObjectsArchive.size(); i++) {
     ArrayList objects = (ArrayList) alObjectsArchive.get(i);
     for (int j = 0; j < objects.size(); j++) {
       CelestialObject obj = (CelestialObject) objects.get(j);
       //      CelestialObject obj = (CelestialObject)objects.get(1);
       PVector pos = obj.getPosition();
       //      stroke(0, 0, 255);
       stroke((Integer) alColors.get(j));
       if (alPrevPos.size() == objects.size()) {
         PVector prevPos = (PVector) alPrevPos.get(j);
         line(prevPos.x, prevPos.y, pos.x, pos.y);
         alPrevPos.set(j, pos);
       } else alPrevPos.add(pos);
     }
   }
 }
コード例 #2
0
  public void setup() {
    size(600, 400);
    smooth();
    f = createFont("Georgia", 12, true);

    obstacles = new ArrayList();
    boids = new ArrayList();

    // A little algorithm to pick a bunch of random obstacles that don't overlap
    for (int i = 0; i < 100; i++) {
      float x = random(width);
      float y = random(height);
      float r = random(50 - i / 2, 50);
      boolean ok = true;
      for (int j = 0; j < obstacles.size(); j++) {
        Obstacle o = (Obstacle) obstacles.get(j);
        if (dist(x, y, o.loc.x, o.loc.y) < o.radius + r + 20) {
          ok = false;
        }
      }
      if (ok) obstacles.add(new Obstacle(x, y, r));
    }

    // Starting with three boids
    boids.add(new Boid(new PVector(random(width), random(height)), 3f, 0.2f));
    boids.add(new Boid(new PVector(random(width), random(height)), 3f, 0.1f));
    boids.add(new Boid(new PVector(random(width), random(height)), 2f, 0.05f));
  }
コード例 #3
0
ファイル: World.java プロジェクト: sooda/vvtg-kulaworld
 // maailmassa on välttämättä myös pisteitä joissa ei ole haaroja, laitetaan niiden päihin
 // kolikkoja
 // akseli ulospäin siitä suorasta osasta
 // paluuarvot paikka1, akseli1, ...
 ArrayList<PVector> endpoints() {
   ArrayList<PVector> pts = new ArrayList<PVector>();
   for (int z = 0; z < size; z += space + 1) {
     for (int y = 0; y < size; y += space + 1) {
       for (int x = 0; x < size; x += space + 1) {
         PVector pos = head(x, y, z);
         if (pos != null) {
           pts.add(pos);
           pts.add(PVector.sub(pos, new PVector(x, y, z)));
         }
       }
     }
   }
   return pts;
 }
コード例 #4
0
    public void trace(float x, float y) {

      println(x);

      if (frameCounter > 2 && mousePressed) {
        coords.add(new PVector(x, y));
        frameCounter = 0;
        if (coordCounter > 0) {
          PVector tempCoord = (PVector) coords.get(coordCounter - 1);
          line(x, y, tempCoord.x, tempCoord.y);
        }
        coordCounter++;
      }
      // println(coordCounter);

      for (int i = 0; i < coords.size(); i++) {
        PVector tempCoordnear = (PVector) coords.get(i);
        float coordDist = dist(x, y, tempCoordnear.x, tempCoordnear.y);
        if (coordDist < distance) {
          stroke(255, 0, 0);
          line(x, y, tempCoordnear.x, tempCoordnear.y);
        }
      }
      frameCounter++;
    }
コード例 #5
0
ファイル: PlanetScape.java プロジェクト: kmshiva/PlanetScape
    // Does a deepcopy of an array list
    public static ArrayList cloneArrayList(ArrayList al) {
      ArrayList alNew = new ArrayList(al.size());
      for (int i = 0; i < al.size(); i++) {
        alNew.add(((CelestialObject) al.get(i)).clone());
      }

      return alNew;
    }
コード例 #6
0
ファイル: PlanetScape.java プロジェクト: kmshiva/PlanetScape
    public ArrayList getPastObjectStates() {
      ArrayList alPast = new ArrayList();
      for (int i = intTimeIdx; i > 0 && i > intTimeIdx - 100; i--) {
        alPast.add(this.alObjectStateArchive.get(i));
      }

      return alPast;
    }
コード例 #7
0
ファイル: PlanetScape.java プロジェクト: kmshiva/PlanetScape
    // Does a deepcopy of an array list
    public ArrayList cloneArrayList(ArrayList al) {
      ArrayList alNew = new ArrayList(al.size());
      for (int i = 0; i < al.size(); i++) {
        PVector pv = (PVector) al.get(i);
        alNew.add(new PVector(pv.x, pv.y));
      }

      return alNew;
    }
コード例 #8
0
ファイル: BChar.java プロジェクト: notlion/rake-p5
  public static ArrayList<BChar> buildString(PApplet app, String str, float wander) {
    ArrayList<BChar> bchars = new ArrayList<BChar>(str.length());

    for (int i = 0, n = str.length(); i < n; i++) {
      bchars.add(new BChar(str.substring(i, i + 1), app.random(-wander, wander)));
      if (i > 0) bchars.get(i - 1).addChild(bchars.get(i));
    }

    return bchars;
  }
コード例 #9
0
  public void setup() {
    size(800, 600);
    smooth();

    strokeWeight(1);

    skaters = new ArrayList();

    skaters.add(new Skater());
  }
コード例 #10
0
  public void setup() {
    size(320, 240);
    smooth();

    // Start with 10 balls
    balls = new ArrayList();
    for (int i = 0; i < 10; i++) {
      Ball ball = new Ball(random(width), random(height));
      balls.add(ball);
    }
  }
コード例 #11
0
ファイル: PlanetScape.java プロジェクト: kmshiva/PlanetScape
    public ArrayList getFutureObjectStates() {
      ArrayList alFutureArchive = new ArrayList();
      ArrayList alFutureObjects = cloneArrayList(alStatefulObjects);

      for (int i = 0; i < 100; i++) {
        sim.calculateForces(alFutureObjects);

        alFutureArchive.add(cloneArrayList(alFutureObjects));
      }

      return alFutureArchive;
    }
コード例 #12
0
ファイル: World.java プロジェクト: bostrt/Processing-Apps
  /** Add a ball to the ArrayList at current mouse position */
  public void addBall() {

    // Store current mouse position
    x1 = mouseX;
    y1 = mouseY;
    // Get a random offset for the ball
    int xDiff = (int) random(-10, 10);
    int yDiff = (int) random(-10, 10);
    // Add the mouse's (x,y) and the random offset
    int x = mouseX + xDiff;
    int y = mouseY + yDiff;
    // Create new ball
    Ball b = new Ball(x, y, ballSize);
    b.STEM = stems;
    b.attract = kelly;
    balls.add(b);
  }
コード例 #13
0
ファイル: PlanetScape.java プロジェクト: kmshiva/PlanetScape
    public int moveForward() {
      //    println("forward!");
      intTimeIdx++;

      // if the future values have already been calculated, just fetch them instead of calculating
      // them again
      if (alObjectStateArchive.size() > intTimeIdx)
        setCurrentState(cloneArrayList((ArrayList) alObjectStateArchive.get(intTimeIdx)));
      else {
        //      println("calculating...");
        sim.calculateForces(alStatefulObjects);
        alObjectStateArchive.add(cloneArrayList(alStatefulObjects));
      }

      sliderTimeline.setValue(intTimeIdx);

      return intTimeIdx;
    }
コード例 #14
0
ファイル: Compiler.java プロジェクト: CM-9xx/cm9xx
 static public ArrayList<File> findFilesInFolder(File folder, String extension,
                                                 boolean recurse) {
   ArrayList<File> files = new ArrayList<File>();
   
   if (folder.listFiles() == null) return files;
   
   for (File file : folder.listFiles()) {
     if (file.getName().startsWith(".")) continue; // skip hidden files
     
     if (file.getName().endsWith("." + extension))
       files.add(file);
       
     if (recurse && file.isDirectory()) {
       files.addAll(findFilesInFolder(file, extension, true));
     }
   }
   
   return files;
 }
コード例 #15
0
    public void addPoint(long handId, PVector handPoint) {
      ArrayList curList = getPointList(handId);

      curList.add(0, handPoint);
      if (curList.size() > _maxPoints) curList.remove(curList.size() - 1);
    }
コード例 #16
0
ファイル: Runner.java プロジェクト: hsiaotaiyeh/processing
  protected String[] getSketchParams(boolean presenting) {
    ArrayList<String> params = new ArrayList<String>();

    // It's dangerous to add your own main() to your code,
    // but if you've done it, we'll respect your right to hang yourself.
    // http://processing.org/bugs/bugzilla/1446.html
    if (build.getFoundMain()) {
      params.add(build.getSketchClassName());

    } else {
      params.add("processing.core.PApplet");

      // get the stored device index (starts at 0)
      int runDisplay = Preferences.getInteger("run.display");

      // If there was a saved location (this guy has been run more than once)
      // then the location will be set to the last position of the sketch window.
      // This will be passed to the PApplet runner using something like
      // --location=30,20
      // Otherwise, the editor location will be passed, and the applet will
      // figure out where to place itself based on the editor location.
      // --editor-location=150,20
      if (editor != null) { // if running processing-cmd, don't do placement
        GraphicsDevice editorDevice = editor.getGraphicsConfiguration().getDevice();
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = ge.getScreenDevices();

        // Make sure the display set in Preferences actually exists
        GraphicsDevice runDevice = editorDevice;
        if (runDisplay >= 0 && runDisplay < devices.length) {
          runDevice = devices[runDisplay];
        } else {
          runDevice = editorDevice;
          for (int i = 0; i < devices.length; i++) {
            if (devices[i] == runDevice) {
              runDisplay = i;
              break;
              // Don't set the pref, might be a temporary thing. Users can
              // open/close Preferences to reset the device themselves.
              //              Preferences.setInteger("run.display", runDisplay);
            }
          }
        }

        Point windowLocation = editor.getSketchLocation();
        //        if (windowLocation != null) {
        //          // could check to make sure the sketch location is on the device
        //          // that's specified in Preferences, but that's going to be annoying
        //          // if you move a sketch to another window, then it keeps jumping
        //          // back to the specified window.
        ////          Rectangle screenRect =
        ////            runDevice.getDefaultConfiguration().getBounds();
        //        }
        if (windowLocation == null) {
          if (editorDevice == runDevice) {
            // If sketches are to be shown on the same display as the editor,
            // provide the editor location so the sketch's main() can place it.
            Point editorLocation = editor.getLocation();
            params.add(
                PApplet.ARGS_EDITOR_LOCATION + "=" + editorLocation.x + "," + editorLocation.y);
          } else {
            // The sketch's main() will set a location centered on the new
            // display. It has to happen in main() because the width/height
            // of the sketch are not known here.
            //             Set a location centered on the other display
            //            Rectangle screenRect =
            //              runDevice.getDefaultConfiguration().getBounds();
            //            int runX =
            //            params.add(PApplet.ARGS_LOCATION + "=" + runX + "," + runY);
          }
        } else {
          params.add(PApplet.ARGS_LOCATION + "=" + windowLocation.x + "," + windowLocation.y);
        }
        params.add(PApplet.ARGS_EXTERNAL);
      }

      params.add(PApplet.ARGS_DISPLAY + "=" + runDisplay);

      if (presenting) {
        params.add(PApplet.ARGS_FULL_SCREEN);
        //        if (Preferences.getBoolean("run.present.exclusive")) {
        //          params.add(PApplet.ARGS_EXCLUSIVE);
        //        }
        params.add(PApplet.ARGS_STOP_COLOR + "=" + Preferences.get("run.present.stop.color"));
        params.add(PApplet.ARGS_BGCOLOR + "=" + Preferences.get("run.present.bgcolor"));
      }

      params.add(build.getSketchClassName());
      params.add(PApplet.ARGS_SKETCH_FOLDER + "=" + build.getSketchPath());
      // Adding sketch path in the end coz it's likely to
      // contain spaces and things go wrong on UNIX systems.
    }

    //    String outgoing[] = new String[params.size()];
    //    params.toArray(outgoing);
    //    return outgoing;
    return params.toArray(new String[0]);
  }
コード例 #17
0
ファイル: Runner.java プロジェクト: hsiaotaiyeh/processing
  protected String[] getMachineParams() {
    ArrayList<String> params = new ArrayList<String>();

    // params.add("-Xint"); // interpreted mode
    // params.add("-Xprof");  // profiler
    // params.add("-Xaprof");  // allocation profiler
    // params.add("-Xrunhprof:cpu=samples");  // old-style profiler

    // TODO change this to use run.args = true, run.args.0, run.args.1, etc.
    // so that spaces can be included in the arg names
    String options = Preferences.get("run.options");
    if (options.length() > 0) {
      String pieces[] = PApplet.split(options, ' ');
      for (int i = 0; i < pieces.length; i++) {
        String p = pieces[i].trim();
        if (p.length() > 0) {
          params.add(p);
        }
      }
    }

    //    params.add("-Djava.ext.dirs=nuffing");

    if (Preferences.getBoolean("run.options.memory")) {
      params.add("-Xms" + Preferences.get("run.options.memory.initial") + "m");
      params.add("-Xmx" + Preferences.get("run.options.memory.maximum") + "m");
    }

    if (Base.isMacOS()) {
      params.add("-Xdock:name=" + build.getSketchClassName());
      //      params.add("-Dcom.apple.mrj.application.apple.menu.about.name=" +
      //                 sketch.getMainClassName());
    }
    // sketch.libraryPath might be ""
    // librariesClassPath will always have sep char prepended
    params.add(
        "-Djava.library.path="
            + build.getJavaLibraryPath()
            + File.pathSeparator
            + System.getProperty("java.library.path"));

    params.add("-cp");
    params.add(build.getClassPath());
    //    params.add(sketch.getClassPath() +
    //        File.pathSeparator +
    //        Base.librariesClassPath);

    // enable assertions
    // http://dev.processing.org/bugs/show_bug.cgi?id=1188
    params.add("-ea");
    // PApplet.println(PApplet.split(sketch.classPath, ':'));

    String outgoing[] = new String[params.size()];
    params.toArray(outgoing);

    //    PApplet.println(outgoing);
    //    PApplet.println(PApplet.split(outgoing[0], ":"));
    //    PApplet.println();
    //    PApplet.println("class path");
    //    PApplet.println(PApplet.split(outgoing[2], ":"));

    return outgoing;
    // return (String[]) params.toArray();

    //  System.out.println("sketch class path");
    //  PApplet.println(PApplet.split(sketch.classPath, ';'));
    //  System.out.println();
    //  System.out.println("libraries class path");
    //  PApplet.println(PApplet.split(Base.librariesClassPath, ';'));
    //  System.out.println();
  }
コード例 #18
0
 /*
 	Register a sensor inside this robot, with the given ID
 */
 protected void registerSensor(Sensor sensor, String ID) {
   mappedSensors.put(ID, sensor);
   sensors.add(sensor);
 }
コード例 #19
0
ファイル: BChar.java プロジェクト: notlion/rake-p5
 public void addChild(BChar childNode) {
   children.add(childNode);
   childNode.parent = this;
 }
コード例 #20
0
ファイル: Runner.java プロジェクト: nconfrey/processing
  protected String[] getSketchParams(boolean presenting) {
    ArrayList<String> params = new ArrayList<String>();

    // It's dangerous to add your own main() to your code,
    // but if you've done it, we'll respect your right to hang yourself.
    // http://processing.org/bugs/bugzilla/1446.html
    if (build.getFoundMain()) {
      params.add(build.getSketchClassName());

    } else {
      params.add("processing.core.PApplet");

      // get the stored device index (starts at 1)
      int runDisplay = Preferences.getInteger("run.display");

      // If there was a saved location (this guy has been run more than once)
      // then the location will be set to the last position of the sketch window.
      // This will be passed to the PApplet runner using something like
      // --location=30,20
      // Otherwise, the editor location will be passed, and the applet will
      // figure out where to place itself based on the editor location.
      // --editor-location=150,20
      if (editor != null) { // if running processing-cmd, don't do placement
        GraphicsDevice editorDevice = editor.getGraphicsConfiguration().getDevice();
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = ge.getScreenDevices();

        // Make sure the display set in Preferences actually exists
        GraphicsDevice runDevice = editorDevice;
        if (runDisplay > 0 && runDisplay <= devices.length) {
          runDevice = devices[runDisplay - 1];
        } else {
          // If a bad display is selected, use the same display as the editor
          if (runDisplay > 0) { // don't complain about -1 or 0
            System.err.println("Display " + runDisplay + " not available.");
          }
          runDevice = editorDevice;
          for (int i = 0; i < devices.length; i++) {
            if (devices[i] == runDevice) {
              // Wasn't setting the pref to avoid screwing things up with
              // something temporary. But not setting it makes debugging one's
              // setup just too damn weird, so changing that behavior.
              runDisplay = i + 1;
              System.err.println(
                  "Setting 'Run Sketches on Display' preference to display " + runDisplay);
              Preferences.setInteger("run.display", runDisplay);
              break;
            }
          }
        }

        Point windowLocation = editor.getSketchLocation();
        //        if (windowLocation != null) {
        //          // could check to make sure the sketch location is on the device
        //          // that's specified in Preferences, but that's going to be annoying
        //          // if you move a sketch to another window, then it keeps jumping
        //          // back to the specified window.
        ////          Rectangle screenRect =
        ////            runDevice.getDefaultConfiguration().getBounds();
        //        }
        if (windowLocation == null) {
          if (editorDevice == runDevice) {
            // If sketches are to be shown on the same display as the editor,
            // provide the editor location so the sketch's main() can place it.
            Point editorLocation = editor.getLocation();
            params.add(
                PApplet.ARGS_EDITOR_LOCATION + "=" + editorLocation.x + "," + editorLocation.y);
          } else {
            // The sketch's main() will set a location centered on the new
            // display. It has to happen in main() because the width/height
            // of the sketch are not known here.
            //             Set a location centered on the other display
            //            Rectangle screenRect =
            //              runDevice.getDefaultConfiguration().getBounds();
            //            int runX =
            //            params.add(PApplet.ARGS_LOCATION + "=" + runX + "," + runY);
          }
        } else {
          params.add(PApplet.ARGS_LOCATION + "=" + windowLocation.x + "," + windowLocation.y);
        }
        params.add(PApplet.ARGS_EXTERNAL);
      }

      params.add(PApplet.ARGS_DISPLAY + "=" + runDisplay);

      if (presenting) {
        params.add(PApplet.ARGS_PRESENT);
        //        if (Preferences.getBoolean("run.present.exclusive")) {
        //          params.add(PApplet.ARGS_EXCLUSIVE);
        //        }
        params.add(PApplet.ARGS_STOP_COLOR + "=" + Preferences.get("run.present.stop.color"));
        params.add(PApplet.ARGS_WINDOW_COLOR + "=" + Preferences.get("run.present.bgcolor"));
      }

      // There was a PDE X hack that put this after the class name, but it was
      // removed for 3.0a6 because it would break the args passed to sketches.
      params.add(PApplet.ARGS_SKETCH_FOLDER + "=" + build.getSketchPath());

      params.add(build.getSketchClassName());
    }

    //    String outgoing[] = new String[params.size()];
    //    params.toArray(outgoing);
    //    return outgoing;
    return params.toArray(new String[0]);
  }
コード例 #21
0
 public void mousePressed() {
   balls.add(new Ball(mouseX, mouseY));
 }
コード例 #22
0
 public void mousePressed() {
   boids.add(new Boid(new PVector(mouseX, mouseY), random(2, 5), random(0.05f, 0.2f)));
 }
コード例 #23
0
ファイル: PlanetScape.java プロジェクト: kmshiva/PlanetScape
 public void registerStatefulObject(CelestialObject obj) {
   alStatefulObjects.add(obj);
 }