mirror of
https://github.com/processing/processing4.git
synced 2026-02-02 13:21:07 +01:00
some fixes for HashMap class examples thanks to @REAS
This commit is contained in:
@@ -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()) {
|
||||
|
||||
6
java/examples/Topics/Advanced Data/HashMapClass/Word.pde
Normal file → Executable file
6
java/examples/Topics/Advanced Data/HashMapClass/Word.pde
Normal file → Executable 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);
|
||||
|
||||
0
java/examples/Topics/Advanced Data/HashMapClass/data/Georgia.ttf
Normal file → Executable file
0
java/examples/Topics/Advanced Data/HashMapClass/data/Georgia.ttf
Normal file → Executable file
0
java/examples/Topics/Advanced Data/HashMapClass/data/dracula.txt
Normal file → Executable file
0
java/examples/Topics/Advanced Data/HashMapClass/data/dracula.txt
Normal file → Executable file
0
java/examples/Topics/Advanced Data/HashMapClass/data/frankenstein.txt
Normal file → Executable file
0
java/examples/Topics/Advanced Data/HashMapClass/data/frankenstein.txt
Normal file → Executable file
Reference in New Issue
Block a user