Skip to content

Commit 23bbf3b

Browse files
committed
Keywords changes, currently not entirely working
1 parent 93549c8 commit 23bbf3b

File tree

15 files changed

+442
-461
lines changed

15 files changed

+442
-461
lines changed

app/src/processing/app/syntax/Token.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class Token {
4242
*/
4343
public static final byte LABEL = 5;
4444

45-
/** Datatypes and keywords (void, int, boolean, etc.) */
45+
/** Keywords (void, int, boolean, etc.) */
4646
public static final byte KEYWORD1 = 6;
4747

4848
/** Fields [variables within a class] */
@@ -51,8 +51,10 @@ public class Token {
5151
/** Processing variables (width, height, focused, etc.) */
5252
public static final byte KEYWORD3 = 8;
5353

54+
/** Flow structures (if, else, while, for, etc.) */
5455
public static final byte KEYWORD4 = 9;
5556

57+
/** Datatypes (int, boolean, etc.) */
5658
public static final byte KEYWORD5 = 10;
5759

5860
/** Functions */

java/examples/Topics/Advanced Data/HashMapClass/HashMapClass.pde

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// The next line is needed if running in JavaScript Mode with Processing.js
1717
/* @pjs font="Georgia.ttf"; */
1818

19-
HashMap words; // HashMap object
19+
HashMap<String, Word> words; // HashMap object
2020

2121
String[] tokens; // Array of all words from input file
2222
int counter;
@@ -46,7 +46,7 @@ void draw() {
4646
if (words.containsKey(s)) {
4747
// Get the word object and increase the count
4848
// We access objects from a HashMap via its key, the String
49-
Word w = (Word) words.get(s);
49+
Word w = words.get(s);
5050
w.count();
5151
} else {
5252
// Otherwise make a new word
@@ -57,16 +57,12 @@ void draw() {
5757
words.put(s, w);
5858
}
5959

60-
// Make an iterator to look at all the things in the HashMap
61-
Iterator i = words.values().iterator();
62-
6360
// x and y will be used to locate each word
6461
float x = 0;
6562
float y = height-10;
6663

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()) {
7066

7167
// Only display words that appear 3 times
7268
if (w.count > 3) {
@@ -89,3 +85,4 @@ void draw() {
8985
}
9086
}
9187
}
88+

java/examples/Topics/Advanced Data/LoadingXMLObjects/Bubble.pde

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,27 @@ class Bubble {
99

1010
float x,y;
1111
float diameter;
12-
color c;
12+
color c;
13+
1314
Bubble(float r,float g, float b, float d) {
1415
x = width/2;
1516
y = height/2;
16-
c = color(r,g,b,150);
17+
c = color(r, g, b, 204);
1718
diameter = d;
1819
}
1920

2021
// Display Bubble
2122
void display() {
22-
stroke(0);
23+
noStroke();
2324
fill(c);
24-
ellipse(x,y,diameter,diameter);
25+
ellipse(x, y, diameter, diameter);
2526
}
2627

2728
// Bubble drifts upwards
2829
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);
3334
}
3435
}

java/examples/Topics/Advanced Data/LoadingXMLObjects/LoadingXMLObjects.pde

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Bubble[] bubbles;
2121

2222
void setup() {
2323
size(640, 360);
24-
smooth();
24+
2525
// Load an XML document
2626
XML xml = loadXML("bubbles.xml");
2727

@@ -31,7 +31,7 @@ void setup() {
3131
// Make an array of objects the same size
3232
bubbles = new Bubble[children.length];
3333

34-
for (int i = 0; i < children.length; i ++ ) {
34+
for (int i = 0; i < children.length; i++ ) {
3535

3636
// The diameter is the content of the child named "Diamater"
3737
XML diameterElement = children[i].getChild("diameter");

java/examples/Topics/Advanced Data/XMLYahooWeather/XMLYahooWeather.pde

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ String weather = "";
1414
// The zip code we'll check for
1515
String zip = "10003";
1616

17+
PFont font;
18+
1719
void setup() {
18-
size(200, 200);
20+
size(600, 360);
21+
22+
font = createFont("Merriweather-Light.ttf", 28);
23+
textFont(font);
1924

2025
// The URL for the XML document
2126
String url = "http://xml.weather.yahoo.com/forecastrss?p=" + zip;
@@ -36,12 +41,8 @@ void draw() {
3641
fill(0);
3742

3843
// 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+
4748
}

java/examples/Topics/Create Shapes/BeginEndContour/BeginEndContour.pde

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,21 @@ void setup() {
1515
s.stroke(255);
1616
s.strokeWeight(2);
1717
// Exterior part of shape
18-
s.beginContour();
1918
s.vertex(-100,-100);
2019
s.vertex(100,-100);
2120
s.vertex(100,100);
2221
s.vertex(-100,100);
23-
s.vertex(-100,-100);
24-
s.endContour();
2522

2623
// Interior part of shape
2724
s.beginContour();
2825
s.vertex(-10,-10);
2926
s.vertex(10,-10);
3027
s.vertex(10,10);
3128
s.vertex(-10,10);
32-
s.vertex(-10,-10);
3329
s.endContour();
3430

3531
// Finishing off shape
36-
s.end();
32+
s.end(CLOSE);
3733
}
3834

3935
void draw() {

java/examples/Topics/Create Shapes/PolygonPShapeOOP/PolygonPShapeOOP.pde

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@
66

77

88
// A Star object
9-
Star s;
9+
Star s1, s2;
1010

1111
void setup() {
1212
size(640, 360, P2D);
1313
smooth();
1414
// Make a new Star
15-
s = new Star();
15+
s1 = new Star();
16+
s2 = new Star();
1617

1718
}
1819

1920
void draw() {
2021
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+
2529
}
2630

java/examples/Topics/Create Shapes/PolygonPShapeOOP/Star.pde

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ class Star {
66
PShape s;
77
// The location where we will draw the shape
88
float x, y;
9+
float speed;
910

1011
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);
1315
// First create the shape
1416
s = createShape();
1517
// 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();
1920
// Here, we are hardcoding a series of vertices
2021
s.vertex(0, -50);
2122
s.vertex(14, -20);
@@ -33,7 +34,7 @@ class Star {
3334

3435
void move() {
3536
// Demonstrating some simple motion
36-
x++;
37+
x += speed;
3738
if (x > width+100) {
3839
x = -100;
3940
}

java/examples/Topics/Create Shapes/PolygonPShapeOOP2/Polygon.pde

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Polygon {
1717

1818
// Simple motion
1919
void move() {
20-
y+=speed;
20+
y += speed;
2121
if (y > height+100) {
2222
y = -100;
2323
}

java/examples/Topics/Create Shapes/PolygonPShapeOOP2/PolygonPShapeOOP2.pde

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ void setup() {
1515
smooth();
1616
// Make a PShape
1717
PShape star = createShape();
18+
star.noStroke();
1819
star.fill(0,127);
19-
star.stroke(0);
2020
star.vertex(0, -50);
2121
star.vertex(14, -20);
2222
star.vertex(47, -15);

0 commit comments

Comments
 (0)