Added new P3D examples

This commit is contained in:
codeanticode
2011-12-12 04:20:41 +00:00
parent 63e688f79a
commit ffbf9af5ed
74 changed files with 4885 additions and 0 deletions
@@ -0,0 +1,64 @@
/**
* Kinetic Type
* by Zach Lieberman.
*
* Using push() and pop() to define the curves of the lines of type.
*/
Line ln;
Line lns[];
String words[] = {
"sometimes it's like", "the lines of text", "are so happy", "that they want to dance",
"or leave the page or jump", "can you blame them?", "living on the page like that",
"waiting to be read..."
};
void setup() {
size(640, 360, P3D);
// Array of line objects
lns = new Line[8];
// Load the font from the sketch's data directory
textFont(loadFont("Univers-66.vlw"), 1.0);
// White type
fill(255);
// Creating the line objects
for(int i = 0; i < 8; i++) {
// For every line in the array, create a Line object to animate
// i * 70 is the spacing
ln = new Line(words[i], 0, i * 70);
lns[i] = ln;
}
}
void draw() {
background(0);
translate(-200, -50, -450);
rotateY(0.3);
// Now animate every line object & draw it...
for(int i = 0; i < 8; i++) {
float f1 = sin((i + 1.0) * (millis() / 10000.0) * TWO_PI);
float f2 = sin((8.0 - i) * (millis() / 10000.0) * TWO_PI);
Line line = lns[i];
pushMatrix();
translate(0.0, line.yPosition, 0.0);
for(int j = 0; j < line.myLetters.length; j++) {
if(j != 0) {
translate(textWidth(line.myLetters[j - 1].myChar) * 75, 0.0, 0.0);
}
rotateY(f1 * 0.005 * f2);
pushMatrix();
scale(75.0);
text(line.myLetters[j].myChar, 0.0, 0.0);
popMatrix();
}
popMatrix();
}
}
@@ -0,0 +1,13 @@
class Letter
{
char myChar;
float x;
float y;
Letter(char c, float f, float f1)
{
myChar = c;
x = f;
y = f1;
}
}
@@ -0,0 +1,28 @@
class Line
{
String myString;
int xPosition;
int yPosition;
int highlightNum;
float speed;
float curlInX;
Letter myLetters[];
Line(String s, int i, int j)
{
myString = s;
xPosition = i;
yPosition = j;
myLetters = new Letter[s.length()];
float f1 = 0.0;
for(int k = 0; k < s.length(); k++)
{
char c = s.charAt(k);
f1 += textWidth(c);
Letter letter = new Letter(c, f1, 0.0);
myLetters[k] = letter;
}
curlInX = 0.1;
}
}
@@ -0,0 +1,10 @@
class Word
{
String myName;
int x;
Word(String s)
{
myName = s;
}
}
@@ -0,0 +1,125 @@
/**
* Letter K
* by Peter Cho.
*
* Move the mouse across the screen to fold the "K".
*/
color backgroundColor;
color foregroundColor;
color foregroundColor2;
float px, py;
float pfx, pfy;
float pv2, pvx, pvy;
float pa2, pax, pay;
float pMass, pDrag;
void setup() {
size(640, 360, P3D);
noStroke();
backgroundColor = color(134, 144, 154);
foregroundColor = color(235, 235, 30);
foregroundColor2 = color(240, 130, 20);
initParticle(0.6, 0.9, width/2, height/2);
}
void draw() {
background(backgroundColor);
pushMatrix();
iterateParticle(0.15*(-px+mouseX), 0.15*(-py+(height-mouseY)));
translate(width/2, height/2, 0);
fill(foregroundColor);
drawK();
pushMatrix();
translate(0, 0, 1);
translate(0.75 * (px-width/2), -0.75 * (py-height/2), 0);
translate(0.75 * (px-width/2), -0.75 * (py-height/2), 0);
rotateZ(atan2(-(py-height/2), (px-width/2)) + PI/2);
rotateX(PI);
rotateZ(-(atan2(-(py-height/2), (px-width/2)) + PI/2));
fill(foregroundColor2);
drawK();
popMatrix();
translate(0.75 * (px-width/2), -0.75 * (py-height/2), 2);
rotateZ(atan2(-(py-height/2), (px-width/2)) + PI/2);
fill(backgroundColor);
beginShape(QUADS);
vertex(-640, 0);
vertex( 640, 0);
vertex( 640, -360);
vertex(-640, -360);
endShape();
popMatrix();
}
void initParticle(float _mass, float _drag, float ox, float oy) {
px = ox;
py = oy;
pv2 = 0.0;
pvx = 0.0;
pvy = 0.0;
pa2 = 0.0;
pax = 0.0;
pay = 0.0;
pMass = _mass;
pDrag = _drag;
}
void iterateParticle(float fkx, float fky) {
// iterate for a single force acting on the particle
pfx = fkx;
pfy = fky;
pa2 = pfx*pfx + pfy*pfy;
if (pa2 < 0.0000001) {
return;
}
pax = pfx/pMass;
pay = pfy/pMass;
pvx += pax;
pvy += pay;
pv2 = pvx*pvx + pvy*pvy;
if (pv2 < 0.0000001) {
return;
}
pvx *= (1.0 - pDrag);
pvy *= (1.0 - pDrag);
px += pvx;
py += pvy;
}
void drawK() {
pushMatrix();
scale(1.5);
translate(-63, 71);
beginShape(QUADS);
vertex(0, 0, 0);
vertex(0, -142.7979, 0);
vertex(37.1992, -142.7979, 0);
vertex(37.1992, 0, 0);
vertex(37.1992, -87.9990, 0);
vertex(84.1987, -142.7979, 0);
vertex(130.3979, -142.7979, 0);
vertex(37.1992, -43.999, 0);
vertex(77.5986-.2, -86.5986-.3, 0);
vertex(136.998, 0, 0);
vertex(90.7988, 0, 0);
vertex(52.3994-.2, -59.999-.3, 0);
endShape();
//translate(63, -71);
popMatrix();
}
@@ -0,0 +1,82 @@
/**
* Typing (Excerpt from the piece Textension)
* by Josh Nimoy.
*
* Click in the window to give it focus.
* Type to add letters and press backspace or delete to remove them.
*/
int leftmargin = 10;
int rightmargin = 20;
String buff = "";
boolean didntTypeYet = true;
void setup()
{
size(640, 360, P3D);
textFont(loadFont("Univers45.vlw"), 25);
}
void draw()
{
background(176);
if((millis() % 500) < 250){ // Only fill cursor half the time
noFill();
}
else {
fill(255);
stroke(0);
}
float rPos;
// Store the cursor rectangle's position
rPos = textWidth(buff) + leftmargin;
rect(rPos+1, 19, 10, 21);
// Some instructions at first
if(didntTypeYet) {
fill(0);
//text("Use the keyboard.", 22, 40);
}
fill(0);
pushMatrix();
translate(rPos,10+25);
char k;
for(int i = 0;i < buff.length(); i++) {
k = buff.charAt(i);
translate(-textWidth(k),0);
rotateY(-textWidth(k)/70.0);
rotateX(textWidth(k)/70.0);
scale(1.1);
text(k,0,0);
}
popMatrix();
}
void keyPressed()
{
char k;
k = (char)key;
switch(k){
case 8:
if(buff.length()>0){
buff = buff.substring(1);
}
break;
case 13: // Avoid special keys
case 10:
case 65535:
case 127:
case 27:
break;
default:
if(textWidth(buff+k)+leftmargin < width-rightmargin){
didntTypeYet = false;
buff=k+buff;
}
break;
}
}
Binary file not shown.