Constanza Johnson: Ejemplo pelotas
De Casiopea
Título | Cuadrados |
---|---|
Tipo de Proyecto | Proyecto de Curso |
Del Curso | Imagen Escrita, |
Carreras | Diseño Gráfico"Diseño Gráfico" is not in the list (Arquitectura, Diseño, Magíster, Otra) of allowed values for the "Carreras Relacionadas" property., Diseño Industrial"Diseño Industrial" is not in the list (Arquitectura, Diseño, Magíster, Otra) of allowed values for the "Carreras Relacionadas" property. |
Alumno(s) | Constanza Johnson |
Profesor | Herbert Spencer |
int nClicks; // contador de clicks Pelota[] P = new Pelota[30]; // arreglo 'P' de 100 Pelotas void setup(){ size(300, 300); rectMode(CENTER); smooth(); nClicks = 0; // reseteo el contador a 0 float c = random (50,100); float cl = random (150, 200); float co = random (200, 250); float borde = random (1, 250); fill(co,cl,c, c); stroke(borde, borde,borde, borde); } void draw(){ for(int i = 0; i < nClicks; i++){ P[i].render(); } } void mouseReleased(){ P[nClicks] = new Pelota(mouseX, mouseY, pmouseX, pmouseY); nClicks++; if(nClicks == 100){ nClicks = 0; } } //--------------------------- class Pelota{ float x, y, velX, velY, r, masa; Pelota(float _x, float _y, float _px, float _py){ x = _x; y = _y; velX = (x - _px)+ random (2, 4); velY = (y - _py)+ random (2, 4); r = random(5,9); } void render(){ x += velX; y += velY; if ((x < r) || (x > width - r)){ velX = 0 - velX; } if ((y < r) || (y > height - r)){ velY = 0 - velY; } rect(x,y, 8*r, 8*r); } }