Skip to content
phaze9 edited this page May 28, 2011 · 15 revisions

ChangeLog || ToDo

About

napplet is a library for creating and managing NApplets, Processing sketches that can be embedded in other sketches and share their display space. NApplets can be written like any other Processing sketch and are managed by a NAppletManager object created in the setup() method of the “parent” sketch.

Pretty Demo

A demo featuring eight of the examples from the Processing distribution in one sketch can be found here.

News

(25 June 2010) Version 0.3.3 up for download. Added resize() method for napplets.

(9 June 2010) Version 0.3.2 now up for download. Fixed a couple of bugs from v0.3.0.

(24 May 2010) Version 0.30 now up for download. Mousewheel support, nested napplets, and other goodies. See ChangeLog for details.

Example

The following sketch (which you can see live here) manages four NApplet objects of two different kinds:

import napplet.*;

NAppletManager nappletManager;
  
void setup() {
  size(400, 400);
  
  nappletManager = new NAppletManager(this);  // Create the NAppletManager object.
  nappletManager.createNApplet("MouseBox", 25, 25); //   Add four NApplet objects to the manager.
  nappletManager.createNApplet("MouseBlob", 25, 225); // After this, everything is on autopilot.
  nappletManager.createNApplet("MouseBox", 225, 225);
  nappletManager.createNApplet("MouseBlob", 225, 25);
}

void draw() {
  background(50); // Don't need to do anything else.  The NAppletManager handles the rest.
}

public class MouseBox extends NApplet {
  
  // The contents of a NApplet object are exactly like the contents of a sketch.

  int x, y;
  
  void setup() {
    size(150, 150);
    stroke(255);
    fill(100);
    x = width/2;
    y = height/2;
  }
  
  void draw() {
    if (mousePressed) {
      x = mouseX;
      y = mouseY;
    }
    background(0);
    translate(x, y);
    rotate(frameCount*PI/180);
    rect(-10, -10, 20, 20);
  }
}

public class MouseBlob extends NApplet {

  void setup() {
    size(150, 150);
    noStroke();
  }
  
  void draw() {
    translate(width/2, height/2);
    background(0);
    fill(255*mouseX/width);
    ellipse(0, 0, mouseY, mouseY);
  }
  
}
Clone this wiki locally