• fullscreen
  • square_bump.pde
  • //spinning square
    
    int x;
    int y;
    int directionX;
    int directionY;
    
    void setup(){
      background(255);
      size(600,600);
      smooth();
      x = 50;
      y = 50;
      directionX = 1;
      directionY = 1;
    }
    
    void draw(){
      background(255);
      fill(0,220,0);
      rect(x,y,40,40);
      x+=directionX;
      y+=directionY;
      
      if (mouseX == x+25){
        directionX=-1;
      }
      if (mouseX == x-25){
        directionX=+1;
      }
      if (mouseY == y+25){
        directionY=-1;
      }
      if (mouseY == y-25){
        directionY=+1;
      }
    }
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Maximilian Uriarte

    Bump Square

    Add to Faves Me Likey@!
    You must login/register to add this sketch to your favorites.

    I wanted to make it rotate but couldn't figure it out to save my life.

    You need to login/register to comment.