mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Keywords changes, currently not entirely working
This commit is contained in:
@@ -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() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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("Today’s 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user