| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,7 +42,7 @@ public class Token { | |||
| 42 | 42 | */ | |
| 43 | 43 | public static final byte LABEL = 5; | |
| 44 | 44 | ||
| 45 | - /** Datatypes and keywords (void, int, boolean, etc.) */ | ||
| 45 | + /** Keywords (void, int, boolean, etc.) */ | ||
| 46 | 46 | public static final byte KEYWORD1 = 6; | |
| 47 | 47 | ||
| 48 | 48 | /** Fields [variables within a class] */ | |
@@ -51,8 +51,10 @@ public class Token { | |||
| 51 | 51 | /** Processing variables (width, height, focused, etc.) */ | |
| 52 | 52 | public static final byte KEYWORD3 = 8; | |
| 53 | 53 | ||
| 54 | + /** Flow structures (if, else, while, for, etc.) */ | ||
| 54 | 55 | public static final byte KEYWORD4 = 9; | |
| 55 | 56 | ||
| 57 | + /** Datatypes (int, boolean, etc.) */ | ||
| 56 | 58 | public static final byte KEYWORD5 = 10; | |
| 57 | 59 | ||
| 58 | 60 | /** Functions */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ | |||
| 16 | 16 | // The next line is needed if running in JavaScript Mode with Processing.js | |
| 17 | 17 | /* @pjs font="Georgia.ttf"; */ | |
| 18 | 18 | ||
| 19 | - HashMap words; // HashMap object | ||
| 19 | + HashMap<String, Word> words; // HashMap object | ||
| 20 | 20 | ||
| 21 | 21 | String[] tokens; // Array of all words from input file | |
| 22 | 22 | int counter; | |
@@ -46,7 +46,7 @@ void draw() { | |||
| 46 | 46 | if (words.containsKey(s)) { | |
| 47 | 47 | // Get the word object and increase the count | |
| 48 | 48 | // We access objects from a HashMap via its key, the String | |
| 49 | - Word w = (Word) words.get(s); | ||
| 49 | + Word w = words.get(s); | ||
| 50 | 50 | w.count(); | |
| 51 | 51 | } else { | |
| 52 | 52 | // Otherwise make a new word | |
@@ -57,16 +57,12 @@ void draw() { | |||
| 57 | 57 | words.put(s, w); | |
| 58 | 58 | } | |
| 59 | 59 | ||
| 60 | - // Make an iterator to look at all the things in the HashMap | ||
| 61 | - Iterator i = words.values().iterator(); | ||
| 62 | - | ||
| 63 | 60 | // x and y will be used to locate each word | |
| 64 | 61 | float x = 0; | |
| 65 | 62 | float y = height-10; | |
| 66 | 63 | ||
| 67 | - while (i.hasNext()) { | ||
| 68 | - // Look at each word | ||
| 69 | - Word w = (Word) i.next(); | ||
| 64 | + // Look at each word | ||
| 65 | + for (Word w : words.values()) { | ||
| 70 | 66 | ||
| 71 | 67 | // Only display words that appear 3 times | |
| 72 | 68 | if (w.count > 3) { | |
@@ -89,3 +85,4 @@ void draw() { | |||
| 89 | 85 | } | |
| 90 | 86 | } | |
| 91 | 87 | } | |
| 88 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,26 +9,27 @@ class Bubble { | |||
| 9 | 9 | ||
| 10 | 10 | float x,y; | |
| 11 | 11 | float diameter; | |
| 12 | - color c; | ||
| 12 | + color c; | ||
| 13 | + | ||
| 13 | 14 | Bubble(float r,float g, float b, float d) { | |
| 14 | 15 | x = width/2; | |
| 15 | 16 | y = height/2; | |
| 16 | - c = color(r,g,b,150); | ||
| 17 | + c = color(r, g, b, 204); | ||
| 17 | 18 | diameter = d; | |
| 18 | 19 | } | |
| 19 | 20 | ||
| 20 | 21 | // Display Bubble | |
| 21 | 22 | void display() { | |
| 22 | - stroke(0); | ||
| 23 | + noStroke(); | ||
| 23 | 24 | fill(c); | |
| 24 | - ellipse(x,y,diameter,diameter); | ||
| 25 | + ellipse(x, y, diameter, diameter); | ||
| 25 | 26 | } | |
| 26 | 27 | ||
| 27 | 28 | // Bubble drifts upwards | |
| 28 | 29 | void drift() { | |
| 29 | - x += random(-1,1); | ||
| 30 | - y += random(-1,1); | ||
| 31 | - x = constrain(x,0,width); | ||
| 32 | - y = constrain(y,0,height); | ||
| 30 | + x += random(-1, 1); | ||
| 31 | + y += random(-1, 1); | ||
| 32 | + x = constrain(x, 0, width); | ||
| 33 | + y = constrain(y, 0, height); | ||
| 33 | 34 | } | |
| 34 | 35 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,7 +21,7 @@ Bubble[] bubbles; | |||
| 21 | 21 | ||
| 22 | 22 | void setup() { | |
| 23 | 23 | size(640, 360); | |
| 24 | - smooth(); | ||
| 24 | + | ||
| 25 | 25 | // Load an XML document | |
| 26 | 26 | XML xml = loadXML("bubbles.xml"); | |
| 27 | 27 | ||
@@ -31,7 +31,7 @@ void setup() { | |||
| 31 | 31 | // Make an array of objects the same size | |
| 32 | 32 | bubbles = new Bubble[children.length]; | |
| 33 | 33 | ||
| 34 | - for (int i = 0; i < children.length; i ++ ) { | ||
| 34 | + for (int i = 0; i < children.length; i++ ) { | ||
| 35 | 35 | ||
| 36 | 36 | // The diameter is the content of the child named "Diamater" | |
| 37 | 37 | XML diameterElement = children[i].getChild("diameter"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,8 +14,13 @@ String weather = ""; | |||
| 14 | 14 | // The zip code we'll check for | |
| 15 | 15 | String zip = "10003"; | |
| 16 | 16 | ||
| 17 | + PFont font; | ||
| 18 | + | ||
| 17 | 19 | void setup() { | |
| 18 | - size(200, 200); | ||
| 20 | + size(600, 360); | ||
| 21 | + | ||
| 22 | + font = createFont("Merriweather-Light.ttf", 28); | ||
| 23 | + textFont(font); | ||
| 19 | 24 | ||
| 20 | 25 | // The URL for the XML document | |
| 21 | 26 | String url = "http://xml.weather.yahoo.com/forecastrss?p=" + zip; | |
@@ -36,12 +41,8 @@ void draw() { | |||
| 36 | 41 | fill(0); | |
| 37 | 42 | ||
| 38 | 43 | // Display all the stuff we want to display | |
| 39 | - text("Zip code: " + zip, 10, 160); | ||
| 40 | - text("Today's high: " + temperature, 10, 40); | ||
| 41 | - text("Forecast: " + weather, 10, 90); | ||
| 42 | - | ||
| 43 | - // Draw a little thermometer based on the temperature | ||
| 44 | - stroke(0); | ||
| 45 | - fill(175); | ||
| 46 | - rect(10, 50, temperature*2, 20); | ||
| 44 | + text("Zip code: " + zip, width*0.15, height*0.33); | ||
| 45 | + text("Today’s high: " + temperature, width*0.15, height*0.5); | ||
| 46 | + text("Forecast: " + weather, width*0.15, height*0.66); | ||
| 47 | + | ||
| 47 | 48 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,25 +15,21 @@ void setup() { | |||
| 15 | 15 | s.stroke(255); | |
| 16 | 16 | s.strokeWeight(2); | |
| 17 | 17 | // Exterior part of shape | |
| 18 | - s.beginContour(); | ||
| 19 | 18 | s.vertex(-100,-100); | |
| 20 | 19 | s.vertex(100,-100); | |
| 21 | 20 | s.vertex(100,100); | |
| 22 | 21 | s.vertex(-100,100); | |
| 23 | - s.vertex(-100,-100); | ||
| 24 | - s.endContour(); | ||
| 25 | 22 | ||
| 26 | 23 | // Interior part of shape | |
| 27 | 24 | s.beginContour(); | |
| 28 | 25 | s.vertex(-10,-10); | |
| 29 | 26 | s.vertex(10,-10); | |
| 30 | 27 | s.vertex(10,10); | |
| 31 | 28 | s.vertex(-10,10); | |
| 32 | - s.vertex(-10,-10); | ||
| 33 | 29 | s.endContour(); | |
| 34 | 30 | ||
| 35 | 31 | // Finishing off shape | |
| 36 | - s.end(); | ||
| 32 | + s.end(CLOSE); | ||
| 37 | 33 | } | |
| 38 | 34 | ||
| 39 | 35 | void draw() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,21 +6,25 @@ | |||
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | 8 | // A Star object | |
| 9 | - Star s; | ||
| 9 | + Star s1, s2; | ||
| 10 | 10 | ||
| 11 | 11 | void setup() { | |
| 12 | 12 | size(640, 360, P2D); | |
| 13 | 13 | smooth(); | |
| 14 | 14 | // Make a new Star | |
| 15 | - s = new Star(); | ||
| 15 | + s1 = new Star(); | ||
| 16 | + s2 = new Star(); | ||
| 16 | 17 | ||
| 17 | 18 | } | |
| 18 | 19 | ||
| 19 | 20 | void draw() { | |
| 20 | 21 | background(51); | |
| 21 | - // Display the star | ||
| 22 | - s.display(); | ||
| 23 | - // Move the star | ||
| 24 | - s.move(); | ||
| 22 | + | ||
| 23 | + s1.display(); // Display the first star | ||
| 24 | + s1.move(); // Move the first star | ||
| 25 | + | ||
| 26 | + s2.display(); // Display the second star | ||
| 27 | + s2.move(); // Move the second star | ||
| 28 | + | ||
| 25 | 29 | } | |
| 26 | 30 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,16 +6,17 @@ class Star { | |||
| 6 | 6 | PShape s; | |
| 7 | 7 | // The location where we will draw the shape | |
| 8 | 8 | float x, y; | |
| 9 | + float speed; | ||
| 9 | 10 | ||
| 10 | 11 | Star() { | |
| 11 | - x = 0; | ||
| 12 | - y = height/2; | ||
| 12 | + x = random(100, width-100); | ||
| 13 | + y = random(100, height-100); | ||
| 14 | + speed = random(0.5, 3); | ||
| 13 | 15 | // First create the shape | |
| 14 | 16 | s = createShape(); | |
| 15 | 17 | // You can set fill and stroke | |
| 16 | - s.fill(102); | ||
| 17 | - s.stroke(255); | ||
| 18 | - s.strokeWeight(2); | ||
| 18 | + s.fill(255, 204); | ||
| 19 | + s.noStroke(); | ||
| 19 | 20 | // Here, we are hardcoding a series of vertices | |
| 20 | 21 | s.vertex(0, -50); | |
| 21 | 22 | s.vertex(14, -20); | |
@@ -33,7 +34,7 @@ class Star { | |||
| 33 | 34 | ||
| 34 | 35 | void move() { | |
| 35 | 36 | // Demonstrating some simple motion | |
| 36 | - x++; | ||
| 37 | + x += speed; | ||
| 37 | 38 | if (x > width+100) { | |
| 38 | 39 | x = -100; | |
| 39 | 40 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ class Polygon { | |||
| 17 | 17 | ||
| 18 | 18 | // Simple motion | |
| 19 | 19 | void move() { | |
| 20 | - y+=speed; | ||
| 20 | + y += speed; | ||
| 21 | 21 | if (y > height+100) { | |
| 22 | 22 | y = -100; | |
| 23 | 23 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,8 +15,8 @@ void setup() { | |||
| 15 | 15 | smooth(); | |
| 16 | 16 | // Make a PShape | |
| 17 | 17 | PShape star = createShape(); | |
| 18 | + star.noStroke(); | ||
| 18 | 19 | star.fill(0,127); | |
| 19 | - star.stroke(0); | ||
| 20 | 20 | star.vertex(0, -50); | |
| 21 | 21 | star.vertex(14, -20); | |
| 22 | 22 | star.vertex(47, -15); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments