Hi,
This code is working well in java mode but when I tried uploading it on openprocessing.org it doesn't show any thing other than background color so I tried tested it in javascript mode and but still it is not working.
help! I am missing anything ?
- int rectsize=50, up, down, right, left;
- Rectpush[] rect;
- void setup()
- {
- size(600, 300);
- rect = new Rectpush[8];
- for (int i=0;i<rect.length;i++) {
- float x = random(0, width-50);
- float y = random(0, height-50);
- rect[i] = new Rectpush(x, y, rectsize, i );
- }
- }
- void draw()
- {
- background(#00CAFF);
- noStroke();
- for (int i=0;i<rect.length;i++) {
- if ( rect[i].x< mouseX && mouseX < rect[i].x+rectsize && rect[i].y< mouseY && mouseY < rect[i].y+rectsize) {
- fill(#FFC800);
- if (right==1) rect[i].x++;
- if (left==1) rect[i].x--;
- if (down==1) rect[i].y++;
- if (up==1) rect[i].y--;
- }
- else {
- fill(255);
- }
- rect[i].update();
- }
- }
- void keyPressed() {
- if (key == CODED) {
- if (keyCode == UP) up=1;
- if (keyCode == DOWN) down=1;
- if (keyCode == LEFT) left=1;
- if (keyCode == RIGHT)right=1;
- }
- }
- void keyReleased()
- {
- up=0;
- down=0;
- right=0;
- left=0;
- }
class
- class Rectpush {
- float x, y;
- int rectsize;
- private int i;
- Rectpush(float _x, float _y, int _rectsize, int _i)
- {
- x = _x;
- y = _y;
- i = _i;
- rectsize = _rectsize;
- }
- void update()
- {
- rect(x, y, rectsize, rectsize);
- fill(#FF0077);
- textAlign(CENTER);
- text( i ,x+25,y+30);
- }
- }
1