• fullscreen
  • sketch52031.pde
  • int x=5, xdirection = 2,y=150; //left or right
    
    void setup(){
      size(500,400);
      smooth();
    }
    
    
    void draw(){
      background(255);
      x= x+xdirection;
      if (x>400 ||x<0){
        xdirection*=-1;
      }
      //Draw Monster Head
      strokeWeight(3);
      noFill();
      rect(x,y, 120,100);
      line(x,y,x-60,y-40);
      line(x+120,y,x+60,y-40);
      //Face
      rect(x+30,y+50,-20,-30);
      rect(x+80,y+50,-20,-30);
      ellipse(x+48,y+80,15,25);
      //Body
      triangle(x+60,y+100,x-60,y+150,x+120,y+180);
      triangle(x,y+160,x,y+240,x+40,y+170);
    }

    code

    tweaks (0)

    about this sketch

    This sketch is running in HTML5 using Processingjs.

    license

    advertisement

    Yuan Li plus+

    Feb10_HW1

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

    You may wish to simplify your creature.
    It should slowly move either from L-R or Top-Bottom;
    Before it gets completely out of the window, reverse direction.
    Do the same thing for the other side of the window.

    LOVE how elegant, how simple your code is. Don't forget that variable names ideally begin with lowercase but include uppercase, too: xDirection, myX, newX, etc. Just makes it easier to distinguish among variables and functions, especially.
    You need to login/register to comment.