some fixes for HashMap class examples thanks to @REAS

This commit is contained in:
Daniel Shiffman
2013-03-15 22:30:30 -04:00
parent 2e706976d0
commit 20e501eab0
5 changed files with 7 additions and 4 deletions

View File

@@ -13,6 +13,9 @@
* offer a simpler way of pairing Strings with numbers or other Strings.
* Here we use a HashMap because we want to pair a String with a custom
* object, in this case a "Word" object that stores two numbers.
*
* In this example, words that appear in one book (Dracula) only are colored white
* while words the other (Frankenstein) are colored black.
*/
// The next line is needed if running in JavaScript Mode with Processing.js
@@ -35,7 +38,7 @@ void setup() {
}
void draw() {
background(0);
background(126);
// Show words
for (Word w : words.values()) {

View File

@@ -43,7 +43,7 @@ class Word {
// The more often it appears, the faster it falls
void move() {
float speed = map(totalCount,5,25,0.1,3);
float speed = map(totalCount, 5, 25, 0.1, 0.4);
speed = constrain(speed,0,10);
position.y += speed;
@@ -56,10 +56,10 @@ class Word {
// Depending on which book it gets a color
void display() {
if (countDracula > 0) {
fill(121, 0, 31);
fill(255);
}
else if (countFranken > 0) {
fill(33, 72, 122);
fill(0);
}
// Its size is also tied to number of occurences
float fs = map(totalCount,5,25,2,24);

View File

View File

View File