This sketch is just a draft where the user can click to create a rectangle that then bounces around the screen. However, not only is my rectangle changing sizes but it is only bouncing off the top and left walls. Any advice?
Star[] stars = { };
void setup() { size(600, 600); background(255); }
void draw() { background(255); for (int i = 0; i < stars.length; i++) { stars[i].move(); stars[i].display(); } }
void mouseClicked() { Star newStar = new Star(mouseX, mouseY); stars = (Star[]) append (stars, newStar); }
class Star { float x = 0; float y = 0; float speed = 1; int xdir = -1; int ydir = 1; int w = 10; int h = 10;
Star(int x, int y) { this.x = x; this.y = y; this.speed = int(random(2, 10)); } void move() { x += (xdir * speed); if (x < 0 || x > width ) { xdir = xdir * -1; x =+ (xdir * speed); } w=50*xdir; y+= (ydir * speed); if (y < 0|| y > height){ ydir = ydir * -1; y =+ (ydir * speed); } h=50*ydir; }
Working on an assignment and seem to have hit a roadblock. The following code draws a number of triangles in hexagon shapes and are supposed to fade out randomly.
However, I am getting the error message: Syntax error, insert "AssignmentOperator Expression" to complete Expression
with relation to line 18 of the second tab. If I comment this line out one of my hexagons will display and run properly.
Suggestions?
Hexagon[] hs = { new Hexagon(175, 150), new Hexagon(175, 50), new Hexagon(250, 100), new Hexagon(325, 50), new Hexagon(325, 150), new Hexagon(250, 200), new Hexagon(175, 250), new Hexagon(250, 300), new Hexagon(325, 250), new Hexagon(325, 350), new Hexagon(175, 350), new Hexagon(100, 100), new Hexagon(100, 200), new Hexagon(100, 300), new Hexagon(250, 100) };