Ya entrando a usar processing, estuve haciendo otros de los ejercicios de la página, cambiándolos un poquito. Aún me siento insegura respecto a la animación.
ejercicio de mouse: círculos morados, rectángulos grises.
void setup(){
size(600,400);
background(225);
}
void draw (){
stroke(0);
fill(43);
rectMode(CENTER);
rect (mouseX, mouseY,30,56);
fill(100,12,87);
ellipse((random(600)),(random(400)),60,60);
}
Movimiento de mouse:
//declare global variables
int xspeed,yspeed;
int xpos,ypos,wdth,ht;
//initialize sketch
void setup(){
//set sketck window size+background color
size(600,600);
background(50);
//ball speed
xspeed=3;
yspeed=4;
// ball size
wdth=50;
ht=50;
//turn off shapestroke rendering
noStroke();
//initial ball placement
xpos=width/3;
ypos=height/3;
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 collision 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;
}
}
y asi se ve, la esfera rebota en los límites de la pantalla, recorriendo una y otra vez.
Presión del mouse:
en este al presionar el mouse, se genera una elipse cuyo color cambia cada vez.
void setup(){
size(400,400);
background(230);
}
void draw(){
}
void mousePressed(){
strokeWeight(6);
smooth();
fill(112,random(216),random(256));
ellipse(mouseX,mouseY,88,56);
}
void keyPressed(){
background(200);
}



No hay comentarios:
Publicar un comentario