Keywords changes, currently not entirely working

This commit is contained in:
Casey Reas
2012-12-09 15:35:57 +00:00
parent 46e3f44d1f
commit b9d9505827
15 changed files with 441 additions and 460 deletions

View File

@@ -16,7 +16,7 @@
// The next line is needed if running in JavaScript Mode with Processing.js
/* @pjs font="Georgia.ttf"; */
HashMap words; // HashMap object
HashMap<String, Word> words; // HashMap object
String[] tokens; // Array of all words from input file
int counter;
@@ -46,7 +46,7 @@ void draw() {
if (words.containsKey(s)) {
// Get the word object and increase the count
// We access objects from a HashMap via its key, the String
Word w = (Word) words.get(s);
Word w = words.get(s);
w.count();
} else {
// Otherwise make a new word
@@ -57,16 +57,12 @@ void draw() {
words.put(s, w);
}
// Make an iterator to look at all the things in the HashMap
Iterator i = words.values().iterator();
// x and y will be used to locate each word
float x = 0;
float y = height-10;
while (i.hasNext()) {
// Look at each word
Word w = (Word) i.next();
// Look at each word
for (Word w : words.values()) {
// Only display words that appear 3 times
if (w.count > 3) {
@@ -89,3 +85,4 @@ void draw() {
}
}
}

View File

@@ -9,26 +9,27 @@ class Bubble {
float x,y;
float diameter;
color c;
color c;
Bubble(float r,float g, float b, float d) {
x = width/2;
y = height/2;
c = color(r,g,b,150);
c = color(r, g, b, 204);
diameter = d;
}
// Display Bubble
void display() {
stroke(0);
noStroke();
fill(c);
ellipse(x,y,diameter,diameter);
ellipse(x, y, diameter, diameter);
}
// Bubble drifts upwards
void drift() {
x += random(-1,1);
y += random(-1,1);
x = constrain(x,0,width);
y = constrain(y,0,height);
x += random(-1, 1);
y += random(-1, 1);
x = constrain(x, 0, width);
y = constrain(y, 0, height);
}
}

View File

@@ -21,7 +21,7 @@ Bubble[] bubbles;
void setup() {
size(640, 360);
smooth();
// Load an XML document
XML xml = loadXML("bubbles.xml");
@@ -31,7 +31,7 @@ void setup() {
// Make an array of objects the same size
bubbles = new Bubble[children.length];
for (int i = 0; i < children.length; i ++ ) {
for (int i = 0; i < children.length; i++ ) {
// The diameter is the content of the child named "Diamater"
XML diameterElement = children[i].getChild("diameter");

View File

@@ -14,8 +14,13 @@ String weather = "";
// The zip code we'll check for
String zip = "10003";
PFont font;
void setup() {
size(200, 200);
size(600, 360);
font = createFont("Merriweather-Light.ttf", 28);
textFont(font);
// The URL for the XML document
String url = "http://xml.weather.yahoo.com/forecastrss?p=" + zip;
@@ -36,12 +41,8 @@ void draw() {
fill(0);
// Display all the stuff we want to display
text("Zip code: " + zip, 10, 160);
text("Today's high: " + temperature, 10, 40);
text("Forecast: " + weather, 10, 90);
text("Zip code: " + zip, width*0.15, height*0.33);
text("Todays high: " + temperature, width*0.15, height*0.5);
text("Forecast: " + weather, width*0.15, height*0.66);
// Draw a little thermometer based on the temperature
stroke(0);
fill(175);
rect(10, 50, temperature*2, 20);
}

View File

@@ -15,13 +15,10 @@ void setup() {
s.stroke(255);
s.strokeWeight(2);
// Exterior part of shape
s.beginContour();
s.vertex(-100,-100);
s.vertex(100,-100);
s.vertex(100,100);
s.vertex(-100,100);
s.vertex(-100,-100);
s.endContour();
// Interior part of shape
s.beginContour();
@@ -29,11 +26,10 @@ void setup() {
s.vertex(10,-10);
s.vertex(10,10);
s.vertex(-10,10);
s.vertex(-10,-10);
s.endContour();
// Finishing off shape
s.end();
s.end(CLOSE);
}
void draw() {

View File

@@ -6,21 +6,25 @@
// A Star object
Star s;
Star s1, s2;
void setup() {
size(640, 360, P2D);
smooth();
// Make a new Star
s = new Star();
s1 = new Star();
s2 = new Star();
}
void draw() {
background(51);
// Display the star
s.display();
// Move the star
s.move();
s1.display(); // Display the first star
s1.move(); // Move the first star
s2.display(); // Display the second star
s2.move(); // Move the second star
}

View File

@@ -6,16 +6,17 @@ class Star {
PShape s;
// The location where we will draw the shape
float x, y;
float speed;
Star() {
x = 0;
y = height/2;
x = random(100, width-100);
y = random(100, height-100);
speed = random(0.5, 3);
// First create the shape
s = createShape();
// You can set fill and stroke
s.fill(102);
s.stroke(255);
s.strokeWeight(2);
s.fill(255, 204);
s.noStroke();
// Here, we are hardcoding a series of vertices
s.vertex(0, -50);
s.vertex(14, -20);
@@ -33,7 +34,7 @@ class Star {
void move() {
// Demonstrating some simple motion
x++;
x += speed;
if (x > width+100) {
x = -100;
}

View File

@@ -17,7 +17,7 @@ class Polygon {
// Simple motion
void move() {
y+=speed;
y += speed;
if (y > height+100) {
y = -100;
}

View File

@@ -15,8 +15,8 @@ void setup() {
smooth();
// Make a PShape
PShape star = createShape();
star.noStroke();
star.fill(0,127);
star.stroke(0);
star.vertex(0, -50);
star.vertex(14, -20);
star.vertex(47, -15);

View File

@@ -19,13 +19,13 @@ void setup() {
shapes[0] = createShape(ELLIPSE,0,0,100,100);
shapes[0].fill(255,127);
shapes[0].stroke(0);
shapes[0].noStroke();
shapes[1] = createShape(RECT,0,0,100,100);
shapes[1].fill(255,127);
shapes[1].stroke(0);
shapes[1].noStroke();
shapes[2] = createShape();
shapes[2].fill(0,127);
shapes[2].stroke(0);
shapes[2].noStroke();
shapes[2].vertex(0, -50);
shapes[2].vertex(14, -20);
shapes[2].vertex(47, -15);
@@ -38,7 +38,6 @@ void setup() {
shapes[2].vertex(-14, -20);
shapes[2].end(CLOSE);
// Make an ArrayList
polygons = new ArrayList<Polygon>();
@@ -52,7 +51,7 @@ void setup() {
}
void draw() {
background(51);
background(102);
// Display and move them all
for (Polygon poly : polygons) {

View File

@@ -55,7 +55,6 @@ void draw() {
}
// This function returns all the files in a directory as an array of Strings
String[] listFileNames(String dir) {
File file = new File(dir);
@@ -81,7 +80,7 @@ File[] listFiles(String dir) {
}
}
// Function to get a list ofall files in a directory and all subdirectories
// Function to get a list of all files in a directory and all subdirectories
ArrayList listFilesRecursive(String dir) {
ArrayList fileList = new ArrayList();
recurseDir(fileList,dir);

View File

@@ -8,13 +8,13 @@
*/
// Used for oveall rotation
float ang;
float angle;
// Cube count-lower/raise to test performance
int limit = 500;
// Array for all cubes
Cube[]cubes = new Cube[limit];
Cube[] cubes = new Cube[limit];
void setup() {
size(640, 360, P3D);
@@ -22,7 +22,7 @@ void setup() {
noStroke();
// Instantiate cubes, passing in random vals for size and postion
for (int i = 0; i< cubes.length; i++){
for (int i = 0; i < cubes.length; i++){
cubes[i] = new Cube(int(random(-10, 10)), int(random(-10, 10)),
int(random(-10, 10)), int(random(-140, 140)),
int(random(-140, 140)), int(random(-140, 140)));
@@ -41,13 +41,13 @@ void draw(){
ambientLight(70, 70, 10);
// Center geometry in display windwow.
// you can change 3rd argument ('0')
// to move block group closer(+)/further(-)
// you can changlee 3rd argument ('0')
// to move block group closer(+) / further(-)
translate(width/2, height/2, -200 + mouseX * 0.65);
// Rotate around y and x axes
rotateY(radians(ang));
rotateX(radians(ang));
rotateY(radians(angle));
rotateX(radians(angle));
// Draw cubes
for (int i = 0; i < cubes.length; i++){
@@ -55,7 +55,7 @@ void draw(){
}
// Used in rotate function calls above
ang += 0.2;
angle += 0.2;
}