Exemplo n.º 1
0
  public void clientEvent(Client myClient) {

    String response = myClient.readString();

    if (response != null) parent.println("response: " + response);

    if (response != null && isConnected) {

      if (parent.match(response, "100") != null && !isLoggedIn) {

        parent.println("trying to log in...");
        myClient.write("login(test,test)\n");
      }

      if (parent.match(response, "200") != null && !isLoggedIn) {

        isLoggedIn = true;
        myClient.write("task.set(active,true)\n");
        parent.println("we are logged in!");
      }

      if (parent.match(response, "200") != null && isLoggedIn) {

        serverIsReady = true;
        parent.println("server is now ready for tasks!");
      }
    }
  }
Exemplo n.º 2
0
  public void draw(int[] pixels) {

    frameCount++;

    parent.println("draw!");

    String data = "";

    data += "task.animation.set(leds, 50, ";

    if (isLoggedIn) { // && serverIsReady){

      for (int i = 0; i < pixels.length; i++) {
        String value = Integer.toHexString(pixels[i]);
        value = value.substring(2, value.length());
        data += "#" + value + ",";
      }
      data = data.substring(0, data.length() - 1);
      data += ")\n";

      parent.println(data);
      lumoClient.write(data);

      serverIsReady = false;
    }
  }
Exemplo n.º 3
0
  public void initXMLObject() {

    numProfiles = xmlFeed.getChildCount();
    println("NUM PROFILES: " + numProfiles);
    for (int i = 0; i < numProfiles; i++) {
      XMLElement profile = xmlFeed.getChild(i);
      /// *
      try {
        headerList.add(profile.getChild(0).getContent());
        nameList.add(profile.getChild(1).getContent());
        blurbList.add(profile.getChild(2).getContent());
        // videoPathList.add(profile.getChild(3).getContent());
        thePopUp.videoPath.add(profile.getChild(3).getContent());
        latList.add(profile.getChild(4).getContent());
        longList.add(profile.getChild(5).getContent());

        pApp.println("Title= " + profile.getChild(0).getContent());
        pApp.println("Name= " + profile.getChild(1).getContent());
        pApp.println("Blurb= " + profile.getChild(2).getContent());
        // pApp.println("video = " +  profile.getChild(3).getContent());
        pApp.println("Address = " + profile.getChild(4).getContent());
        // pApp.println("long = " + profile.getChild(5).getContent());
        // pApp.println(" ");
        pApp.println(" ");
      } catch (Exception e) {
        println("XML init error: " + e);
      }
    }
    /// now that the popup video array has data, init the video
    thePopUp.initVideo();
    /// convert the lat and long string to floats
    initLocations();
  }
Exemplo n.º 4
0
 /** setVol(float) adjusts overall volume. Checks for min/max limits to avoid crashes. */
 public void setVol(float newvol) {
   if (newvol > -40.0f && newvol < 6.020f) {
     try {
       volCtrl.setValue(newvol);
     } catch (Exception e) {
       PApplet.println(e.getMessage());
     }
   } else {
     PApplet.println(
         "Error - volume '" + newvol + "' is out of range. Must be between -40.0f and 6.020f!");
   }
 }
Exemplo n.º 5
0
 /**
  * a Constructor, usually called in the setup() method in your sketch to initialize and start the
  * library.
  *
  * @example portaTest
  * @param p
  */
 public PortaMod(PApplet p) {
   this.p = p;
   IBXM.SetMC(this);
   try {
     noteArrived = p.getClass().getMethod("grabNewdata", new Class[] {PortaMod.class});
   } catch (Exception e) {
     PApplet.println(e.getMessage());
   }
   try {
     noteArrivedB = p.getClass().getMethod("grabNewdataB", new Class[] {PortaMod.class});
   } catch (Exception e) {
     PApplet.println(e.getMessage());
   }
 }
Exemplo n.º 6
0
 public int createLevel(int level, String[] lines) {
   String line;
   int count = 0;
   char c;
   for (int down = 0; down < nbrDown; down++) {
     line = lines[down];
     for (int across = 0; across < nbrAcross; across++) {
       c = line.charAt(across);
       switch (c) {
         case 'O':
         case 'o':
           cell[2 * across][2 * down][level].tileReqd = true;
           count++;
           break;
         case '>':
           cell[2 * across + 1][2 * down][level].tileReqd = true;
           count++;
           break;
         case 'v':
           cell[2 * across][2 * down + 1][level].tileReqd = true;
           count++;
           break;
         case 'x':
           cell[2 * across + 1][2 * down + 1][level].tileReqd = true;
           count++;
           break;
         case '+':
           break;
         default:
           PApplet.println("Illegal character '" + c + "' in line " + down + " on level " + level);
       }
     }
   }
   return count;
 }
Exemplo n.º 7
0
 /** Draw the shape into an arbitrary PGraphics. */
 void draw(PGraphics pg) {
   if (iFrame.isEyeFrame()) return;
   if (shift != null)
     if (pg.is3D()) pg.translate(shift.x(), shift.y(), shift.z());
     else pg.translate(shift.x(), shift.y());
   // The shape part took verbatim from Processing, see:
   // https://github.com/processing/processing/blob/master/core/src/processing/core/PGraphics.java
   if (shp != null) {
     // don't do expensive matrix ops if invisible
     if (shp.isVisible() && !iFrame.isEyeFrame()) {
       pg.flush();
       if (pg.shapeMode == PApplet.CENTER) {
         pg.pushMatrix();
         pg.translate(-shp.getWidth() / 2, -shp.getHeight() / 2);
       }
       shp.draw(pg); // needs to handle recorder too
       if (pg.shapeMode == PApplet.CENTER) {
         pg.popMatrix();
       }
     }
   } else if (mth != null && obj != null) {
     try {
       mth.invoke(obj, new Object[] {pg});
     } catch (Exception e1) {
       try {
         mth.invoke(obj, new Object[] {iFrame, pg});
       } catch (Exception e2) {
         PApplet.println("Something went wrong when invoking your " + mth.getName() + " method");
       }
     }
   }
 }
  void readFile(String fName) {
    ArrayList<Vec3D> importPts = new ArrayList<Vec3D>();

    File f = new File("");
    try {

      f = new File(p.dataPath(fName));
      p.println(fName);

    } catch (NullPointerException ex) {
      PApplet.println("File: " + " could not be found.");
    }

    String[] strLines = p.loadStrings(f.getAbsolutePath());

    for (int i = 0; i < strLines.length; i++) {
      String clean = strLines[i].substring(1, strLines[i].length() - 1);

      String[] splitToken = clean.split(", ");

      float xx = PApplet.parseFloat(splitToken[0]);
      float yy = PApplet.parseFloat(splitToken[1]);
      float zz = PApplet.parseFloat(splitToken[2]);
      Vec3D ptt = new Vec3D(xx, yy, zz);
      importPts.add(ptt);
    }
    this.populate(importPts);
    p.dotTree.addAll(importPts);
  }
Exemplo n.º 9
0
  void mousePressed() {
    if (currentLarge != null) {
      if (parent.mouseEvent.getClickCount() == 2) {
        // shrink it back down!
        // generate thumbnail
        currentLarge.setSize((int) (smallVizSize.x), (int) (smallVizSize.y));
        moveToPosition(currentLarge);
        currentLarge
            .checkComponents(); // work out if we've double-clicked on the map, the cloud or the
                                // streamgraph!
        currentLarge.currentTransitionState = MovementState.SHRINKING;
        currentLarge = null;
      } else {
        currentLarge.mousePressed();
      }
    } else {
      for (TwitterFilteringComponent a : timePoints) {
        if (parent.mouseEvent.getClickCount() == 2 && a.hasMouseOver()) {
          PApplet.println("<double click> on " + a);
          previousPos = new PVector(a.x, a.y);
          a.moveTo(0, 0);
          a.setSize(width, height);
          currentLarge = a;
          a.currentTransitionState = MovementState.GROWING;
          break;
        } else if (a.hasMouseOver() && parent.keyPressed && parent.keyCode == PConstants.SHIFT) {
          // move middle to where the mouse is?
          PApplet.println("Dragging start" + a);
          currentDragging = a;
          draggingOffsetX = parent.mouseX - a.x;
          draggingOffsetY = parent.mouseY - a.y;
          currentDragging.currentTransitionState = MovementState.MOVING;
          // a.mousePressed();
        }

        if (parent.mouseButton == PConstants.RIGHT) {
          // aha! we're doing captioning!
          if (a.hasMouseOver() && !a.hasCaption()) {
            a.addCaption();
          } else if (a.hasCaption() && a.caption.mouseOver()) {
            PApplet.println("We want to edit the caption!");
            a.caption.createNote();
          }
        }
      }
    }
  }
Exemplo n.º 10
0
 /////////////////////////////////////////////
 // //init the location array
 ///// with ip addresses from the DB
 /////////////////////////////////////////////
 /////// PARSE XML DATA /////////////
 ///////////////////////////////////////
 public void loadXML() {
   try {
     xmlFeed = new XMLElement(this, xmlPath);
     initXMLObject();
   } catch (Exception e) {
     pApp.println("unable to parse xml: " + e);
   }
 }
  public LinearInterpolationDistorter(float radius0, float radius1) {
    this.r0 = radius0;
    this.r1 = radius1;

    if (radius1 < (radius0 / s1)) {
      PApplet.println("Distortion may look weird. Radius 1 should be greater.");
    }
  }
Exemplo n.º 12
0
 /** Mute audio (playback continues) */
 public void mute() {
   if (!muted) {
     try {
       muteCtrl.setValue(true);
       muted = true;
     } catch (Exception e) {
       PApplet.println(e.getMessage());
     }
   } else {
     try {
       muteCtrl.setValue(false);
       muted = false;
     } catch (Exception e) {
       PApplet.println(e.getMessage());
     }
   }
 }
Exemplo n.º 13
0
  public void setup(PApplet p) {
    // size(600,600);
    // background(20);
    // frameRate(10);

    this.parent = p;

    // try to make a connection to the LumoServer
    try {
      isConnected = true;
      lumoClient = new Client(parent, "localhost", 7070);
      parent.println("Server Connection acquired");

    } catch (Exception e) {
      isConnected = false;
      parent.println("Server Connection failed");
    }
  }
Exemplo n.º 14
0
 /**
  * コンストラクタです。 コンフィギュレーション値を格納したインスタンスを作成します。
  *
  * @param i_cs 座標系を選択します。
  *     <ul>
  *       <li>{@link #CS_RIGHT_HAND}
  *       <li>{@link #CS_LEFT_HAND}
  *     </ul>
  *
  * @param i_tm 姿勢計算アルゴリズムを選択します。
  *     <ul>
  *       <li>{@link #TM_NYARTK} - NyARToolKitの姿勢推定を使用します。
  *       <li>{@link #TM_ARTK} - ARToolKitの姿勢推定を使用します。
  *     </ul>
  */
 public NyAR4PsgConfig(int i_cs, int i_tm) {
   switch (i_cs) {
     case CS_LEFT_HAND:
     case CS_RIGHT_HAND:
       break;
     default:
       PApplet.println("Invalid CS param. select CS_LEFT_HAND or CS_RIGHT_HAND.");
   }
   switch (i_tm) {
     case TM_NYARTK:
     case TM_ARTK:
       break;
     default:
       PApplet.println("Invalid TM param. select TM_NYARTK or TM_ARTK.");
   }
   this._coordinate_system = i_cs;
   this.env_transmat_mode = i_tm;
 }
Exemplo n.º 15
0
 public static void send_MIDI(MIDI_Msg[] midi_msgs) {
   if (midi_msgs.length > 0) {
     if (debug_code) PApplet.println("******* MIDI Messages Sent ********* ");
     for (int i = 0; i < midi_msgs.length; i++) {
       Controller control_msg = new Controller(midi_msgs[i].message, midi_msgs[i].value);
       midiOut[midi_msgs[i].channel - 1].sendController(control_msg);
       if (debug_code)
         PApplet.println(
             "msg "
                 + i
                 + " channel: "
                 + midi_msgs[i].channel
                 + " msg: "
                 + midi_msgs[i].message
                 + " value: "
                 + midi_msgs[i].value);
       updateMessageStatus(
           midi_msgs[i].channel + ", " + midi_msgs[i].message + ", " + midi_msgs[i].value + "\n");
     }
   }
 }
Exemplo n.º 16
0
 void mouseReleased() {
   if (currentDragging != null) {
     currentDragging.currentTransitionState = MovementState.SMALL;
     currentDragging = null;
     PApplet.println("Stopped dragging");
   }
   for (TwitterFilteringComponent a : timePoints) {
     if (a.hasMouseOver()) {
       a.mouseReleased();
     }
   }
 }
Exemplo n.º 17
0
 /** Initilize the platformer with the defaults. Will tell your log you're using it! */
 public Platformer() {
   super();
   PApplet.println("Using the default Platformer class. Extend this class to override defaults!");
 }
Exemplo n.º 18
0
  /**
   * Load the MOD/XM/S3M module by filepath string. If the second parameter is false, the module
   * will not automatically start to play. The third parameter is the starting volume as a float
   * value between -40.0f and 6.020f. Start at the bottom if you want to fade a module in.
   *
   * @return int
   */
  public int doModLoad(String tune, boolean autostart, int startVol) {
    filepath = tune;
    modpath = tune;
    headerCheck(tune);
    PApplet.println("Header checked: " + modtype);

    if (loadSuccess > 0) {
      loadSuccess = 0;
    }

    InputStream file_input_stream = p.createInput(tune);

    try {
      if (playing == true) {
        player.stop();
        PApplet.println("stopped");
      }
      player = new Player(interpolation);

      player.set_module(Player.load_module(file_input_stream));
      file_input_stream.close();
      player.set_loop(true);
      player.receivebuffer(buffersize);
      if (autostart) {
        player.play();
        songStart = p.millis();
      }
      this.setGlobvol(startVol);
      PApplet.println(player.get_title());
      PApplet.println(player.song_duration);

      songLength = player.song_duration / 48000;
      infotext = new String[player.get_num_instruments()];

      for (int i = 0; i < (player.get_num_instruments()); i++) {
        infotext[i] = "";
        // store copies of all the instruments for changeSample
        Instrument tempinst_old = player.module.instruments[i];
        oldsamples.add(i, tempinst_old);
        if (player.ins_name(i) != null) {
          PApplet.println(player.ins_name(i));
          infotext[i] = player.ins_name(i);
        }
      }

      chantranspose = new int[player.get_num_channels()];
      for (int c = 0; c < player.get_num_channels(); c++) {
        chantranspose[c] = 0;
      }
      loopstart = new int[player.get_num_instruments()];
      looplength = new int[player.get_num_instruments()];
      origloopstart = new int[player.get_num_instruments()];
      origlooplength = new int[player.get_num_instruments()];
      sampledatalength = new int[player.get_num_instruments()];
      for (int ins = 0; ins < player.get_num_instruments(); ins++) {
        // initialise loopinfo arrays
        origloopstart[ins] = 0;
        origlooplength[ins] = 0;
        sampledatalength[ins] = player.module.instruments[ins].samples[0].sample_data_length;
        // store initial loop info for loopReset
        // System.out.println("Orig start: " +
        // player.module.instruments[ins].samples[0].loop_start);
        // System.out.println("Orig length: "
        // +player.module.instruments[ins].samples[0].loop_length);
        origloopstart[ins] = player.module.instruments[ins].samples[0].loop_start;
        origlooplength[ins] = player.module.instruments[ins].samples[0].loop_length;
      }

      PApplet.println("Channels:" + player.get_num_channels());
      // PApplet.println(player.output_line.getControls());

      try {
        // volCtrl = (FloatControl) player.output_line.getControl(FloatControl.Type.MASTER_GAIN);
        // volCtrl.setValue(startVol);
      } catch (Exception e) {
        PApplet.println(
            "Mystery javasound failure lucky dip! This week's prize: " + e.getMessage());
      }

      try {
        muteCtrl = (BooleanControl) player.output_line.getControl(BooleanControl.Type.MUTE);
      } catch (Exception e) {
        PApplet.println(e.getMessage());
      }
      /*			for (int i=0; i < numchannels; i++){
      	globvol = startVol;
      	try {
      		player.ibxm.channels[i].chanvol_override = startVol;
      	} catch (Exception e) {
      		// TODO Auto-generated catch block
      		e.printStackTrace();
      	}
      }*/

      title = player.get_title();
      numchannels = player.get_num_channels();
      jamnote = new int[player.get_num_channels()];
      jaminst = new int[player.get_num_channels()];
      for (int c = 0; c < player.get_num_channels(); c++) {
        jamnote[c] = 0;
        jaminst[c] = 0;
      }
      numinstruments = player.get_num_instruments();
      numpatterns = player.ibxm.module.get_sequence_length();
      playing = true;
      loadSuccess = 1;
      initialtempo = player.get_bpm();
      bpmvalue = player.get_bpm();
      currentrowcount = player.ibxm.total_rows;
      endcount = 0;
      //		if (player.get_num_channels() > 0) {
      //			sequencecounter = 0;
      //			refreshpattern();
      //			displayCurrentpattern();
      //		}
    } catch (Exception e) {
      PApplet.println(e.getMessage());
      PApplet.println("Printing stack trace... ");
      e.printStackTrace();
    }
    return loadSuccess;
  }
Exemplo n.º 19
0
 public void print() {
   PApplet.println(format(2));
 }
Exemplo n.º 20
0
  public void setup() {
    size(1200, 800, OPENGL);
    smooth();
    cam = new PeasyCam(this, 500);
    gfx = new ToxiclibsSupport(this);
    float range = maxX - minX;
    myHolder = new holder(this);
    dotTree = new dotTree(new Vec3D(minX, minY, minZ), range * 5, this);
    obsTree = new ObstacleTree(new Vec3D(minX, minY, minZ), range * 5, this);
    tTree = new terrainTree(new Vec3D(minX, minY, minZ), range * 5, this);

    PP = new ProgPoints(this);
    PP.readFile(dataPath(fName));

    ArrayList<Vec3D> importPts = new ArrayList<Vec3D>();
    File f = new File("");
    try {
      f = new File(dataPath(fNameDest));
    } catch (NullPointerException ex) {
      PApplet.println("File: " + " could not be found.");
    }
    String[] strLines = loadStrings(f.getAbsolutePath());

    for (int i = 0; i < strLines.length; i++) {
      String clean = strLines[i].substring(1, strLines[i].length() - 1);
      String[] splitToken = clean.split(", ");
      float xx = PApplet.parseFloat(splitToken[0]);
      float yy = PApplet.parseFloat(splitToken[1]);
      float zz = PApplet.parseFloat(splitToken[2]);
      Vec3D ptt = new Vec3D(xx, yy, zz);
      importPts.add(ptt);
    }

    for (int i = 0; i < importPts.size(); i++) {
      if (i < importPts.size() - 1) {
        start.add(importPts.get(i));
        end.add(importPts.get(i + 1));
      } else {
        start.add(importPts.get(i));
        end.add(importPts.get(0));
      }
    }

    aMesh =
        (TriangleMesh)
            new STLReader().loadBinary(dataPath("final_obs.stl"), STLReader.TRIANGLEMESH);

    allVertx.addAll(aMesh.getVertices());
    obsTree.addAll(allVertx);
    allVertx.clear();

    importMesh =
        (TriangleMesh)
            new STLReader().loadBinary(dataPath("final_srf.stl"), STLReader.TRIANGLEMESH);
    allVertx.addAll(importMesh.getVertices());
    tTree.addAll(allVertx);
    terrain = importMesh;
    moved = importMesh.getTranslated(new Vec3D(0, 0, 36));

    for (int i = 0; i < 150; i++) {
      int groupId = (int) (random(0, start.size()));
      float test = random(0, 1);
      myHolder.addAgent(new Agent(i, groupId, test, this));
    }
  }