Permalink
Browse files

Make Text inherit from Shape, necessitated some update manuvering

  • Loading branch information...
1 parent ebe994c commit 116d5c80eaa498b1bc4546e9feeb92a4d39dd152 @qrush committed May 10, 2010
Showing with 63 additions and 48 deletions.
  1. +63 −48 kidsmash.pjs
View
@@ -5,10 +5,36 @@ int yellowFill = 0, redFill = 121;
boolean move = true;
var shapes = [];
+class Shape {
+ int x, y, alpha;
+ color c;
+
+ Shape(int xin, int yin) {
+ x = xin;
+ y = yin;
+ alpha = 255;
+ c = color(random(255), random(255), random(255));
+ }
+
+ void update(fade) {
+ alpha -= fade;
+ return alpha > 0;
+ }
+
+ void draw(custom) {
+ noStroke();
+ fill(c, alpha);
+ custom.call();
+ }
+}
+
class Help extends Shape {
Help() {
super(0,0)
- alpha = 2000
+ }
+
+ void update() {
+ return update(5);
}
void draw() {
@@ -24,70 +50,43 @@ class Help extends Shape {
}
}
-class Text {
- int f1, f2, f3, x, y, alpha;
+class Text extends Shape {
string s;
- int fade = 3;
int rotation;
float rotationAmount;
- Text(xin, yin, sin, f1in, f2in, f3in) {
+ Text(xin, yin, sin) {
+ super(xin, yin);
x = xin;
y = yin;
s = sin;
- f1 = f1in;
- f2 = f2in;
- f3 = f3in;
- alpha = 255;
rotation = random(40, 200);
rotationAmount = Math.random() / 2;
}
- function update() {
- alpha -= fade;
+ void update() {
if(rotation > 0) {
rotation -= (rotation * rotationAmount);
} else {
rotation = 0;
}
- return alpha > 0;
- }
-
- function draw() {
- pushMatrix();
- translate(x, y);
- rotate(radians(rotation));
- translate(-x,-y);
- stroke(0);
- textSize(200);
- fill(f1, f2, f3, alpha);
- text(s, x, y);
- popMatrix();
-
- rotation += 5;
+ return update(3);
}
-}
-class Shape {
- int x, y, alpha;
- color c;
-
- Shape(int xin, int yin) {
- x = xin;
- y = yin;
- alpha = 255;
- c = color(random(255), random(255), random(255));
- }
-
- void update() {
- alpha -= 15;
- return alpha > 0;
- }
-
- void draw(custom) {
- noStroke();
- fill(c, alpha);
- custom.call();
+ void draw() {
+ draw(function() {
+ pushMatrix();
+ translate(x, y);
+ rotate(radians(rotation));
+ translate(-x,-y);
+ stroke(0);
+ textSize(200);
+ fill(c, alpha);
+ text(s, x, y);
+ popMatrix();
+
+ rotation += 5;
+ });
}
}
@@ -106,6 +105,10 @@ class Circle extends Shape {
circleHeight = h;
}
+ void update() {
+ return update(10);
+ }
+
void draw() {
draw(function() {
ellipse(x, y, circleWidth, circleHeight);
@@ -130,6 +133,10 @@ class Triangle extends Shape {
super(random(width), random(height));
}
+ void update() {
+ return update(10);
+ }
+
void draw() {
draw(function() {
triangle(x-100, y+100,
@@ -144,6 +151,10 @@ class Trapezoid extends Shape {
super(random(width), random(height));
}
+ void update() {
+ return update(10);
+ }
+
void draw() {
draw(function() {
quad(x-75, y-100,
@@ -159,6 +170,10 @@ class Star extends Shape {
super(random(width), random(height));
}
+ void update() {
+ return update(10);
+ }
+
void draw() {
draw(function() {
beginShape();
@@ -259,7 +274,7 @@ void keyPressed() {
var keyStr = String.fromCharCode(key);
if(/^[A-Za-z0-9]$/.test(keyStr)) {
- shapes.unshift(new Text(random(width), random(height), keyStr, random(255), random(255), random(255)));
+ shapes.unshift(new Text(random(width), random(height), keyStr));
}
}
}

0 comments on commit 116d5c8

Please sign in to comment.