» codelab : http://codelab.fr/accueil » Forum : Processing : http://codelab.fr/processing » Effet de croissance : http://codelab.fr/1774 Ceci est la version imprimable d'un sujet du forum, pour retourner à la version complète : Effet de croissance |
Ars Robota — 2010-07-03 18:12:21 |
Salut à tou(te)s, |
emoc — 2010-07-05 11:57:34 |
Salut, Code (p5) :// 5 juillet 2010 / emoc / http://codelab.fr/1774 ArrayList tendrils; float ang = 0; void setup() { size(400,400); frameRate(30); smooth(); tendrils = new ArrayList(); } void draw() { background(255); ang += random(-60, 60); tendrils.add( new Tendril(width / 2, height / 2)); if (tendrils.size() > 50) tendrils.remove(0); for (int i = 0; i < tendrils.size(); i++) { Tendril t = (Tendril) tendrils.get(i); t.update(ang); t.ink(); } } /* ****************************** */ class Tendril { PVector pos; float col = 0; Tendril(float _x, float _y) { pos = new PVector(_x, _y); } void update(float ang) { col = (col + 3)%255; pos.set(pos.x + 3 * cos(radians(ang)), pos.y + 3 * sin(radians(ang)), 0); } void ink() { colorMode(HSB); fill(col,255,240); noStroke(); ellipse(pos.x, pos.y, 3, 3); } } Sur openprocessing, tu devrais trouver des trucs intéressants sur le sujet, comme Tendrils : http://www.openprocessing.org/visuals/?visualID=1341 |
Ars Robota — 2010-07-05 15:57:32 |
Par Jimorrison, merci beaucoup Emoc!!! Je me penche là-dessus tout de suite. |
Staross — 2010-07-05 22:09:13 |
Intéressant ouaip, pour le déplacement j'utiliserai plutôt les équations du mouvement de newton, une sorte de mouvement aléatoire avec des frottements et de l'inertie. Code (p5) :float pi = 3.1415; int w = 800; float x = 0; float y = 0; float vx = 0; float vy = 0; float ax = 0; float ay = 0; float dt=1; void setup(){ size(w,w); smooth(); } void draw(){ fill(250, 2); rectMode(CORNER); rect(0,0,width,height); ax = ax + dt*( 1*random(-1,1) - 0.05*ax); ay = ay + dt*( 1*random(-1,1) - 0.05*ay); vx = vx + dt*(2*ax - 0.05*vx); vy = vy + dt*(2*ay - 0.05*vy); x = x + 0.05*dt*vx; y = y + 0.05*dt*vy; fill(0); ellipse(x + width/2.0, y+height/2.0, 5, 5); } void mouseReleased() { x = 0; y = 0; vx = 0; vy = 0; ax = 0; ay = 0; } |
emoc — 2010-07-06 21:53:55 |
En dessinant dans un buffer d'image, tu peux éviter de redessiner, dans ces cas là, il faut juste afficher correctement le buffer à chaque boucle draw(). Un exemple moche : Code (p5) :En commentaire, il y a une version avec une rotation, mais c'est très gourmand... |
Staross — 2010-07-09 00:00:24 |
C'est exactement ça ouaip, j'avais cherché un moment dans la doc mais sans succès, merci ! |