Tarea 10: Exploración en el ejemplo
De Casiopea
Título | Nicole Valdivia Tarea 10: Exploración en el ejemplo |
---|---|
Tipo de Proyecto | Proyecto de Curso |
Palabras Clave | tarea 10 |
Período | 2012- |
Asignatura | Taller Inicial Común 1ª y 2ª Etapa, |
Del Curso | Imagen Escrita 2012, |
Carreras | Arquitectura |
Alumno(s) | Nicole Valdivia Accardi |
Profesor | Herbert Spencer |
Mass indica el punto de “resorte” de los círculos, que generan movimientos controlados en torno a él. Mientras más chico es el número se dispersan más las partículas.
G = es un número grande positivo. Las partículas en este caso tienden CONCENTRARSE y en ausencia de un núcleo que las reúna (mass = 0.0) , dan vueltas como “en busca” de quien las albergue
Al ser mass > 0, las partículas se concentran en él de forma acelerada y permanecen.
(no se puede cargar imagen)
// *************************ATTRACTOR********************** class Attractor { float mass; float G; PVector loc; boolean dragging = false; boolean rollover = false; PVector drag; Attractor(PVector l_,float m_, float g_) { loc = l_.get(); mass = 2.0; //El núcleo es pequeño, pero "perceptible" para las partículas que dan vueltas G = 3000; //concentra partículas de colores drag = new PVector(0.0,0.0); } void go() { render(); drag(); } PVector calcGravForce(Thing t) { PVector dir = PVector.sub(loc,t.getLoc()); float d = dir.mag(); d = constrain(d, 1.0, 250.0); dir.normalize(); float force = (G * mass * t.getMass()) / (d * d); dir.mult(force); return dir; } void render() { strokeWeight(mass / 10); stroke(0, 100); ellipseMode(CENTER); if (dragging) fill (50); else if (rollover) fill(100); else fill(175,200); ellipse(loc.x,loc.y,mass*2,mass*2); noStroke(); } void clicked(int mx, int my) { float d = dist(mx,my,loc.x,loc.y); if (d < mass) { dragging = true; drag.x = loc.x-mx; drag.y = loc.y-my; } } void rollover(int mx, int my) { float d = dist(mx,my,loc.x,loc.y); if (d < mass) { rollover = true; } else { rollover = false; } } void stopDragging() { dragging = false; } void drag() { if (dragging) { loc.x = mouseX + drag.x; loc.y = mouseY + drag.y; } } } //**********************THING************************** class Thing { PVector loc; PVector vel; PVector acc; float mass; float max_vel; color col; Thing(PVector a, PVector v, PVector l, float m_) { acc = a.get(); vel = v.get(); loc = l.get(); mass = m_; max_vel = 20.0; col = color(random(180, 255), random(100, 175), random(30), 200); } PVector getLoc() { return loc; } PVector getVel() { return vel; } float getMass() { return mass; } void applyForce(PVector force) { force.div(mass); acc.add(force); if (showVectors) { drawVector(force,loc, 100); } } void go() { update(); render(); } void update() { vel.add(acc); vel.limit(max_vel); loc.add(vel); acc.mult(0); } void render() { ellipseMode(CENTER); fill(col); ellipse(loc.x,loc.y,mass,mass); if (showVectors) { drawVector(vel,loc,20); //algunas particulas rebotan pero vuelven al núcleo } } } //************************DRAW********************** int MAX = 30; Thing[] t = new Thing[MAX]; Attractor a; boolean showVectors = false; boolean velo = false; void setup() { size(1024, 768); smooth(); for (int i = 0; i < t.length; i++) { PVector ac = new PVector(0.0, 0.0); PVector ve = new PVector(random(-1, 1), random(-1, 1)); PVector lo = new PVector(random(width), random(height)); t[i] = new Thing(ac, ve, lo, random(2, 100)); } a = new Attractor(new PVector(width/2, height/2), 30, 1.4); PFont font; font = createFont("Monaco", 18); textFont(font); } color cualquiera() { color c = color(random(255), random(255), random(255)); return c; } void draw() { if (!velo)background(255); a.rollover(mouseX, mouseY); a.go(); for (int i = 0; i < t.length; i++) { PVector f = a.calcGravForce(t[i]); t[i].applyForce(f); t[i].go(); } if (keyPressed) { if (key == 'a') { a.G += 0.1; } if (key == 'z') { a.G -= 0.1; } if (key == 's') { a.mass += 5; } if (key == 'x') { a.mass -= 5; a.mass = constrain(a.mass, 0, 100); } } fill(0); text("G = "+a.G+",\t la masa del atractor = "+a.mass, 30, height-30); if (velo) { fill(255, 15); noStroke(); rect(0, 0, width, height); } } void mousePressed() { a.clicked(mouseX, mouseY); } void mouseReleased() { a.stopDragging(); } void keyPressed() { if (key == ' ') { showVectors = !showVectors; } if (key == 'v') { velo = !velo; } } void drawVector(PVector v, PVector loc, float scayl) { strokeWeight(.75); if (v.mag() > 0.0) { pushMatrix(); float arrowsize = 10; translate(loc.x, loc.y); stroke(255, 128, 0, 200); rotate(v.heading2D()); float len = v.mag()*scayl; line(0, 0, len, 0); line(len, 0, len-arrowsize, +arrowsize/2); line(len, 0, len-arrowsize, -arrowsize/2); popMatrix(); } }