/* Tutorial de Processing joan soler-adillon (www.joan.cat) El condicional ens permet fer rebotar la pilota als eixos X i Y Random() fa que cada cop les velocitats X i Y siguin diferents */ float posX, posY, velX, velY; int sz = 25; int obstacleX, obstacleY; void setup(){ size(300,200); posX = width/2; posY = height/2; velX = random(1,5); velY = random(1,5); fill(255,255,192); smooth(); stroke(255,192,192); } void draw(){ background(0); //actualitzem posicions posX = posX+velX; posY = posY+velY; //dibuixem ellipse(posX,posY,sz,sz); //comprobem posició X if((posX<0)||(posX>width)){ velX = -velX; } //comprobem posició Y if((posY<0)||(posY>height)){ velY = -velY; } //actulizamos obstáculo, según el mouse: obstacleX = mouseX; obstacleY = mouseY; //dibujamos obstaculo: line(obstacleX,0,obstacleX,height); //COMPROBAMOS OBSTÁCULO: if(abs(posX-obstacleX) < sz/2){ velX = -velX; } }