EJERCICIOS DE PROGRAMACIÓN EN PROCESSING


SEGUNDO  BLOQUE DE EJERCICIOS



trayectoria

This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.

Source code: (Versión a partir del ejercicio de Ira Greenberg)

             // declare global variables
int xspeed, yspeed;
int xpos,ypos,wdth,ht;
            // initialize sketch
void setup() {
             // set sketch window size + background color
  size(600,400);
  background(50);
              // ball speed
  xspeed=3;
  yspeed=6;
              // ball size
  wdth = 60;
  ht=60;
              // turn off shapestroke rendering
  noStroke ();
              // initial ball placement
  xpos=width/2;
  ypos=height/2;
  frameRate(30);
}
            // begin animation loop
void draw(){
              // draw ball
  smooth ();
  fill ((random (256)),(random (256)),(random (256)));
  ellipse(xpos,ypos,wdth,ht);
             // upgrade position values
  xpos+=xspeed;
  ypos+=yspeed;
  /*conditionals  
   detects ball collission with sketch window edges
   also accounts for thickness of ball
   */
  if(xpos>=width-wdth/2 || xpos<=wdth/2){
    xspeed*=-1;
  }
  if (ypos>=height-ht/2 || ypos<=ht/2){
    yspeed*=-1;
  }
}


mouse click

This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.

void setup() {
  size (400,320);
  background (255);
}
void draw () {
}
void mousePressed() {
  strokeWeight (2);
  smooth ();
  fill (128, 128, random (256));
 rectMode (CENTER);
  rect (mouseX,mouseY,50,50);
}
void keyPressed () {
  background (255);
}



trazos a partir de la posición del mouse