Example #1
0
  /**
   * Constructor.
   *
   * @param inpParApp Parent PApplet.
   * @param inpResNbr Resolution of the sphere.
   * @param inpModelRadiusNbr Radius of the sphere.
   * @param inpExtDatFilePathTxt Path to an external data file for manipulating the sphere.
   */
  public Sphere(
      PApplet inpParApp, float inpResNbr, float inpModelRadiusNbr, String inpExtDatFilePathTxt) {
    _parApp = inpParApp;
    _resNbr = inpResNbr;
    _modelRadiusNbr = inpModelRadiusNbr;

    _latitudeLnCnt = (int) (180 / _resNbr);
    _longitudeLnCnt = (int) (360 / _resNbr);

    // The number of vertices is the number of longitudinal lines multiplied by the number of
    // latitudinal lines minus 1, plus 2 vertices for the poles.
    int vertexCnt = _longitudeLnCnt * (_latitudeLnCnt - 1) + 2;
    _latitudeDegs = new float[vertexCnt];
    _longitudeDegs = new float[vertexCnt];
    _radiusLenNbrs = new float[vertexCnt];

    // createVertices(0);
    crteVertices();

    FROM_CLR_NBR = _parApp.color(144, 29, 31);
    TO_CLR_NBR = _parApp.color(215, 180, 15);

    _loadFilePathTxt = inpExtDatFilePathTxt;

    loadExtData();
  }
Example #2
0
  public void display() {
    PImage img = kinect.getDepthImage();

    // PImage img = kinect.getVideoImage();
    // Being overly cautious here
    if (depth == null || img == null) return;

    // Going to rewrite the depth image to show which pixels are in threshold
    // A lot of this is redundant, but this is just for demonstration purposes
    display.loadPixels();
    for (int x = 0; x < kw; x++) {
      for (int y = 0; y < kh; y++) {
        // mirroring image
        int offset = kw - x - 1 + y * kw;
        // Raw depth
        int rawDepth = depth[offset];

        int pix = x + y * display.width;
        if (rawDepth < threshold) {
          // A red color instead
          display.pixels[pix] = p.color(150, 50, 50);
        } else {
          display.pixels[pix] = img.pixels[offset];
        }
      }
    }
    display.updatePixels();

    // Draw the image
    p.image(display, 0, 0);
  }
Example #3
0
  /**
   * a Constructor, usually called in the setup() method in your sketch to initialize and start the
   * library.
   *
   * @example Oscilloscope
   * @param theParent
   */
  public Oscilloscope(PApplet theParent, int[] posv, int[] dimv) {
    myParent = theParent;

    // set some defaults
    bounds_color = myParent.color(30);
    resolution = 1024.0f;
    multiplier = 5f;
    logic = false;
    pause = false;

    pos = posv;
    dim = dimv;
    line_color = myParent.color(255, 255, 255);

    logic_colors[0] = myParent.color(255, 0, 0);
    logic_colors[1] = myParent.color(0, 255, 0);

    minval = (int) resolution;

    values = new int[dim[0]];
  }
Example #4
0
 /**
  * Label constructor
  *
  * @param parent
  * @param id
  * @param x
  * @param y
  * @param width
  * @param height
  * @param name
  */
 public Label(
     PApplet parent,
     String id,
     int x,
     int y,
     int width,
     int height,
     XAlign xAlign,
     YAlign yAlign,
     String name) {
   this(parent, id, x, y, width, height, xAlign, yAlign, name, parent.color(0));
 }
  private int getColor() {
    // Setup color
    float colorPart1 = sumOfColorIntensity;
    float colorPart2 = sumOfColorIntensity;
    // Get random intervals
    while (colorPart1 >= colorPart2
        || colorPart1 > 255f
        || colorPart2 - colorPart1 > 255f
        || sumOfColorIntensity - colorPart2 > 255f) {
      colorPart1 = p.random(sumOfColorIntensity);
      colorPart2 = p.random(sumOfColorIntensity);
    }
    //
    float red = colorPart1;
    float green = colorPart2 - colorPart1;
    float blue = sumOfColorIntensity - colorPart2;

    return p.color(red, green, blue);
  }
Example #6
0
 // Draw a box at the location
 public void highlightLocation(Location l) {
   p.fill(p.color(50, 200, 50, 150));
   p.rect(xCoordOf(l), yCoordOf(l), dx, dy);
 }
Example #7
0
  void generate(PApplet pa) {
    int space = World.space;
    // sz^3 pisteitä, joiden välillä space tyhjää (tyhjä 0: kuutio)
    // eli (sz + (sz - 1) * space) ^ 3 tileä
    // visited ~ V_new wikipedian algossa

    boolean[] visited = new boolean[size3];
    int[] visitorder = new int[size3]; // indeksoidaan järjestysnumerolla

    // aluksi size on pisteiden määrä, newsize sitten kun niiden väliin on venytetty kulkuväyliä
    int newsz = size + (size - 1) * space;
    int newsz3 = newsz * newsz * newsz;
    map = new int[newsz3];

    // lähtöpaikka
    visitorder[0] = 0;
    visited[0] = true;
    map[0] = 0xffffffff;

    // käydään kaikki alkuperäiset pisteet läpi, jokaiseen mennään jotenkin
    for (int count = 1; count < size3; count++) {
      // - arvo tiili reunalta
      // (randomilla saattaa tulla sellainenkin joka ei ole reunalla, ei väliä kun ei jättikarttoja)
      // vois tietty pitää listaa sellaisista joista ei vielä pääse kaikkialle...
      // - arvo sille suunta
      // - visitoi se.
      int vidx;
      do {
        vidx = (int) (pa.random(0, count)); // monesko jo visitoitu leviää.
      } while (full(visited, visitorder[vidx]));

      int idx = visitorder[vidx];
      int z = idx / (size * size), y = idx / size % size, x = idx % size;

      // joku vierestä, dir on akselin suuntainen yksikkövektori
      int[] dir = getadj(pa, x, y, z, visited);
      int nx = x + dir[0], ny = y + dir[1], nz = z + dir[2];
      int newidx = world.at(nx, ny, nz);

      visitorder[count] = newidx;
      visited[newidx] = true;

      // nykykohta venytetyssä maailmassa
      int i = x * (space + 1), j = y * (space + 1), k = z * (space + 1);

      // nurkkien välillä debugväreillä
      for (int a = 0; a < space; a++) {
        i += dir[0];
        j += dir[1];
        k += dir[2];
        // vihreä kasvaa iteraatioiden kasvaessa, sininen taas z:n mukaan
        map[world.at(i, j, k, newsz)] =
            pa.color(1, (int) ((float) count / size3 * 255), (int) ((float) k / newsz * 255));
      }
      // verkon kärkipisteet punaisia
      map[world.at(i + dir[0], j + dir[1], k + dir[2], newsz)] = pa.color(255, 0, 0);
    }

    world.size = newsz;
    world.size3 = newsz3;
    world.map = map;
  }
  /**
   * Set the second color of the Repeller
   *
   * @param h hue 0-360
   * @param s saturation 0-100
   * @param b brightness 0 -100
   * @param a alpha 0-100
   */
  public void setColor2(int h, int s, int b, int a) {

    this.color2 = p.color(h, s, b, a);
  }
  public AnimatedParticle(PApplet p) {
    this.p = p;

    timerDiff = p.random(0.01f, 0.04f);
    color = p.color(p.random(255), p.random(255), 255);
  }