miércoles, 9 de marzo de 2011

EJERCICIO DE PROCESSING

EJRCICIO 1:

void setup() {
size (600,400);
background (0, 150, 255);
}
void draw () {
stroke (0);
fill (random(150),random(150));
rectMode (CENTER);
rect (random(600),random(240),random(300),random(300));
fill (255, 100, 0);
ellipse (mouseX,mouseY,60,60);
}



EJERCICIO 2
// 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(0);
// ball speed
xspeed=80;
yspeed=80;
// ball size
wdth = 90;
ht=900;
// 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 (250)),(random (250, 255)),(random (250)));
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;
}
}


EJERCICIO 3


// declare global variables
int xspeed, yspeed;
int xpos,ypos,wdth,ht;
// initialize sketch
void setup() {
// set sketch window size + background color
size(1000,900);
background(0);
// ball speed
xspeed=10;
yspeed=10;
// ball size
wdth = 150;
ht=150;
// 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 (250)),(random (250, 255)),(random (250)));
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;
}
}

No hay comentarios:

Publicar un comentario