Tarea 9 Valentina Veliz
De Casiopea
Título | Tarea 9 |
---|---|
Tipo de Proyecto | Proyecto de Taller, Proyecto de Curso |
Palabras Clave | tarea 9 |
Período | 2012- |
Asignatura | Imagen Escrita 2012, Taller Inicial 1ª y 2ª Etapa, |
Del Curso | Taller Inicial 1ª y 2ª Etapa, Imagen Escrita 2012, |
Carreras | Arquitectura |
Alumno(s) | Valentina Véliz |
Profesor | Herbert Spencer |
/*Pestaña 1 */ int MAX = 60; Thing[] t = new Thing[MAX]; Attractor a; Attractor b; Attractor p; 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, 5.4); b = new Attractor(new PVector(width/8, height/6), 50, -3.2); p = new Attractor(new PVector(width/5, height/3), 20, 10);
}
color cualquiera() {
color c = color(#56D1B9); return c;
}
void draw() {
if (!velo)background(#646461);
a.rollover(mouseX, mouseY); b.rollover(mouseX, mouseY); p.rollover(mouseX, mouseY);// "escucha" al mouse para saber si hay rollover sobre el atractor
a.go(255); p.go(#7456D1); b.go(#56D1B9); // * atractor: sea!
for (int i = 0; i < t.length; i++) {
PVector f = a.calcGravForce(t[i]); PVector g = b.calcGravForce(t[i]); PVector j = p.calcGravForce(t[i]); t[i].applyForce(f); t[i].applyForce(g); t[i].applyForce(j); t[i].go(); }
if (keyPressed) { if (key == 'a') { a.G += 0.2; } if (key == 'z') { a.G -= 0.3; } if (key == 's') { a.mass += 6; } if (key == 'x') { a.mass -= 6; a.mass = constrain(a.mass, 0, 100); } if (key == 'd') { b.G += 0.1; } if (key == 'c') { b.G -= 0.1; } if (key == 'f') { b.mass += 7; } if (key == 'v') { b.mass -= 5; b.mass = constrain(b.mass, 0, 100); } if (key == 'g') { p.G += 0.1; } if (key == 'b') { p.G -= 0.1; } if (key == 'h') { p.mass += 5; } if (key == 'n') { p.mass -= 5; p.mass = constrain(p.mass, 0, 100); } } if (velo) { fill(255, 15); noStroke(); rect(0, 0, width, height); }
}
void mousePressed() {
a.clicked(mouseX, mouseY); b.clicked(mouseX, mouseY); p.clicked(mouseX, mouseY);
}
void mouseReleased() {
a.stopDragging(); b.stopDragging(); p.stopDragging();
}
void keyPressed() {
if (key == ' ') { showVectors = !showVectors; } if (key == 'q') { velo = !velo; }
}
void drawVector(PVector v, PVector loc, float scayl) {
strokeWeight(.5); if (v.mag() > 0.0) { pushMatrix(); float arrowsize = 25; translate(loc.x, loc.y); stroke(#56D1B9); rotate(v.heading2D()); float len = v.mag()*scayl; line(0, 0, len, 0); line(len, 0, len-arrowsize, +arrowsize/5); line(len, 0, len-arrowsize, -arrowsize/15); popMatrix(); }
}
/*Pestaña 2*/ 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 = m_; G = g_; drag = new PVector(0.0,0.0); }
void go(color colors) { random(colors); 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(color colorms) { strokeWeight(mass / 10); stroke(0, 45); ellipseMode(CENTER); if (dragging) fill (colorms, #56D1B9); else if (rollover) fill(colorms, #56D1B9); else fill(colorms, #56D1B9); ellipse(loc.x,loc.y,mass*2,mass*2); noStroke(); }
// The methods below are for mouse interaction 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; } }
}
/*Pestaña 3*/
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 = 30.0; } 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, 150); } }
void go() { update(); render(); } void update() { vel.add(acc); vel.limit(max_vel); loc.add(vel); acc.mult(0); col = color(0, 25*loc.mag(), 50, 100*vel.mag()); } void render() { ellipseMode(CENTER); fill(col); ellipse(loc.x,loc.y,40,40); if (showVectors) { drawVector(vel,loc,20); } }
}