Diferencia entre revisiones de «Eber Sáez proyecto Luz»
De Casiopea
Sin resumen de edición |
Sin resumen de edición |
||
Línea 15: | Línea 15: | ||
Identificación de partes o componentes: objetos | Identificación de partes o componentes: objetos | ||
[[Archivo:Hazluz0747.png|200px|thumb|left|Comportamiento de la luz al colisionar con un objeto]] [[Archivo:Hazluz0748.png|200px|thumb|center|Imagen desde processing]] | [[Archivo:Hazluz0747.png|200px|thumb|left|Comportamiento de la luz al colisionar con un objeto]] [[Archivo:Hazluz0748.png|200px|thumb|center|Imagen desde processing]] | ||
===Código Processing=== | |||
<pre> | |||
Particle part; | |||
muro[] muro = new muro[5]; //defino la cantidad de muros | |||
luz[] luz = new luz[360]; | |||
void setup() { | |||
size(800, 600); | |||
background(0); | |||
part = new Particle(width/2, height/2); | |||
for (int i = 0; i<muro.length; i++) { | |||
muro[i] = new muro(random(width), random(height), random(width), random(height)); | |||
} | |||
for (int i = 0; i<luz.length; i++) { | |||
luz[i] = new luz( i*TWO_PI/luz.length); | |||
} | |||
} | |||
void draw() { | |||
background(0); | |||
// control with Mouse | |||
part.MouseMove(); | |||
//part.move(); | |||
part.show(); | |||
for (int i = 0; i<muro.length; i++) { | |||
muro[i].show(); | |||
} | |||
} | |||
class Particle { | |||
float x, y, nx, ny, t1, t2, xSpeed, ySpeed; | |||
PVector pos; | |||
Particle(float _x, float _y) { | |||
x = _x; | |||
y = _y; | |||
} | |||
void MouseMove() { // posición del mouse | |||
x = mouseX; | |||
y = mouseY; | |||
pos = new PVector(x, y); | |||
point(pos.x, pos.y); | |||
} | |||
void show() { | |||
for (int i = 0; i<luz.length; i++) { | |||
PVector closest = new PVector (0, 0); | |||
float rec = 100000; | |||
for (int j = 0; j<muro.length; j++) { | |||
luz[i].CollisionCheck(muro[j].p1.x, muro[j].p1.y, muro[j].p2.x, muro[j].p2.y); | |||
if (0 <= luz[i].t && luz[i].t <= 1 && 0 <= luz[i].u) { | |||
float d = dist(luz[i].pos.x, luz[i].pos.y, luz[i].poi.x, luz[i].poi.y); | |||
if (d < rec) { | |||
rec = d; | |||
closest = luz[i].poi; | |||
} | |||
} | |||
} | |||
stroke(255, 255, 90); // color y espesor haz de luz | |||
strokeWeight(1); | |||
if (closest.x == 0 & closest.y == 0) { | |||
luz[i].show(); | |||
} else { | |||
line(luz[i].pos.x, luz[i].pos.y, closest.x, closest.y); | |||
} | |||
} | |||
} | |||
} | |||
class luz { | |||
float angle, x1, x2, y1, y2, x3, y3, x4, y4, t, u; | |||
PVector dir, pos, poi; | |||
luz(float _angle) { | |||
angle = _angle; | |||
} | |||
void CollisionCheck(float _x1, float _y1, float _x2, float _y2 ) { | |||
pos = part.pos; | |||
dir = PVector.fromAngle(angle); | |||
dir.add(pos); | |||
x1 = _x1; | |||
y1 = _y1; | |||
x2 = _x2; | |||
y2 = _y2; | |||
x3 = pos.x; | |||
y3 = pos.y; | |||
x4 = dir.x; | |||
y4 = dir.y; | |||
float dom = ((x1-x2)*(y3-y4))-((y1-y2)*(x3-x4)); | |||
if (dom == 0) { | |||
t = -1; | |||
} else { | |||
t = (((x1-x3)*(y3-y4))-((y1-y3)*(x3-x4)))/dom; | |||
u = -((((x1-x2)*(y1-y3))-((y1-y2)*(x1-x3)))/dom); | |||
poi = new PVector(0, 0); | |||
if (0 <= t && t <= 1 && 0 <= u) { | |||
float px = x1 + (t * (x2 - x1)); | |||
float py = y1 + (t * (y2 - y1)); | |||
poi = new PVector(px, py); | |||
} | |||
} | |||
} | |||
void show() { | |||
pos = part.pos; | |||
dir = PVector.fromAngle(angle); | |||
dir.mult(100000); | |||
dir.add(pos); | |||
line(pos.x, pos.y, dir.x, dir.y); | |||
} | |||
} | |||
class muro { | |||
PVector p1, p2; | |||
muro(float x1, float y1, float x2, float y2) { | |||
p1 = new PVector(x1, y1); | |||
p2 = new PVector(x2, y2); | |||
} | |||
void show() { | |||
stroke(255, 50, 98); | |||
strokeWeight(8); | |||
line(p1.x, p1.y, p2.x, p2.y); | |||
} | |||
} | |||
</pre> |
Revisión del 21:41 20 may 2019
Título | Eber Sáez - Proyecto Luz |
---|---|
Asignatura | Imagen Escrita |
Del Curso | Imagen Escrita 2019 T1 |
Carreras | Arquitectura, Diseño |
Alumno(s) | Eber Sáez |
El proyecto consiste la puesta en práctica del pensamiento sistemático del algoritmo a la definición de una imagen, una animación o una herramienta o aplicación interactiva. Para cada se tipo se propone un formato específico: Una imagen estática: formato PDF Una animación: formato GIF animado Una aplicación: app exportada desde Processing El proyecto debe considerar, a grandes trazos, la siguiente estructura: Imagen objetivo: idea y visualización de lo que se quiere lograr, idealmente un dibujo propio a mano alzada. Definición de una partida procedimental Identificación de partes o componentes: objetos
Código Processing
Particle part; muro[] muro = new muro[5]; //defino la cantidad de muros luz[] luz = new luz[360]; void setup() { size(800, 600); background(0); part = new Particle(width/2, height/2); for (int i = 0; i<muro.length; i++) { muro[i] = new muro(random(width), random(height), random(width), random(height)); } for (int i = 0; i<luz.length; i++) { luz[i] = new luz( i*TWO_PI/luz.length); } } void draw() { background(0); // control with Mouse part.MouseMove(); //part.move(); part.show(); for (int i = 0; i<muro.length; i++) { muro[i].show(); } } class Particle { float x, y, nx, ny, t1, t2, xSpeed, ySpeed; PVector pos; Particle(float _x, float _y) { x = _x; y = _y; } void MouseMove() { // posición del mouse x = mouseX; y = mouseY; pos = new PVector(x, y); point(pos.x, pos.y); } void show() { for (int i = 0; i<luz.length; i++) { PVector closest = new PVector (0, 0); float rec = 100000; for (int j = 0; j<muro.length; j++) { luz[i].CollisionCheck(muro[j].p1.x, muro[j].p1.y, muro[j].p2.x, muro[j].p2.y); if (0 <= luz[i].t && luz[i].t <= 1 && 0 <= luz[i].u) { float d = dist(luz[i].pos.x, luz[i].pos.y, luz[i].poi.x, luz[i].poi.y); if (d < rec) { rec = d; closest = luz[i].poi; } } } stroke(255, 255, 90); // color y espesor haz de luz strokeWeight(1); if (closest.x == 0 & closest.y == 0) { luz[i].show(); } else { line(luz[i].pos.x, luz[i].pos.y, closest.x, closest.y); } } } } class luz { float angle, x1, x2, y1, y2, x3, y3, x4, y4, t, u; PVector dir, pos, poi; luz(float _angle) { angle = _angle; } void CollisionCheck(float _x1, float _y1, float _x2, float _y2 ) { pos = part.pos; dir = PVector.fromAngle(angle); dir.add(pos); x1 = _x1; y1 = _y1; x2 = _x2; y2 = _y2; x3 = pos.x; y3 = pos.y; x4 = dir.x; y4 = dir.y; float dom = ((x1-x2)*(y3-y4))-((y1-y2)*(x3-x4)); if (dom == 0) { t = -1; } else { t = (((x1-x3)*(y3-y4))-((y1-y3)*(x3-x4)))/dom; u = -((((x1-x2)*(y1-y3))-((y1-y2)*(x1-x3)))/dom); poi = new PVector(0, 0); if (0 <= t && t <= 1 && 0 <= u) { float px = x1 + (t * (x2 - x1)); float py = y1 + (t * (y2 - y1)); poi = new PVector(px, py); } } } void show() { pos = part.pos; dir = PVector.fromAngle(angle); dir.mult(100000); dir.add(pos); line(pos.x, pos.y, dir.x, dir.y); } } class muro { PVector p1, p2; muro(float x1, float y1, float x2, float y2) { p1 = new PVector(x1, y1); p2 = new PVector(x2, y2); } void show() { stroke(255, 50, 98); strokeWeight(8); line(p1.x, p1.y, p2.x, p2.y); } }