Sei sulla pagina 1di 6

PRACTICAS EN PROCESSING

TRAZOS DE LINEAS Y POLIGONOS


LINEA line()

line(30, 20, 85, 75);

line(30, 20, 85, 20);


stroke(126);
line(85, 20, 85, 75);
stroke(255);
line(85, 75, 30, 75);
// Drawing lines in 3D requires
P3D
// as a parameter to size()
size(100, 100, P3D);
line(30, 20, 0, 85, 20, 15);
stroke(126);
line(85, 20, 15, 85, 75, 0);
stroke(255);
line(85, 75, 0, 30, 75, -50);
PUNTO Point()
noSmooth();
point(30, 20);
point(85, 20);
point(85, 75);
point(30, 75);
size(100, 100, P3D);
noSmooth();
point(30, 20, -50);
point(85, 20, -50);
point(85, 75, -50);
point(30, 75, -50);

CUADRILATERO quad()
quad(38, 31, 86, 20, 69, 63, 30,
76);

RECTANGULO rect()
rect(30, 20, 55, 55);

rect(30, 20, 55, 55, 7);

rect(30, 20, 55, 55, 3, 6, 12,


18);
CUADRADO square()
square(30, 20, 55);

TRIANGULO triangle()
triangle(30, 75, 58, 20, 86, 75);

ELIPCE ellipse()
ellipse(56, 46, 55, 55);

CIRCULO circle()
circle(56, 46, 55);

POLÍGONOS REGULARES
void setup() {
size(640, 360);
}
void draw() {
background(102);
pushMatrix();
translate(width*0.2, height*0.5);
rotate(frameCount / 200.0);
polygon(0, 0, 82, 3); // Triangle
popMatrix();
pushMatrix();
translate(width*0.5, height*0.5);
rotate(frameCount / 50.0);
polygon(0, 0, 80, 20); // Icosahedron
popMatrix();
pushMatrix();
translate(width*0.8, height*0.5);
rotate(frameCount / -100.0);
polygon(0, 0, 70, 7); // Heptagon
popMatrix();
}
void polygon(float x, float y, float
radius, int npoints) {
float angle = TWO_PI / npoints;
beginShape();
for (float a = 0; a < TWO_PI; a += angle)
{
float sx = x + cos(a) * radius;
float sy = y + sin(a) * radius;
vertex(sx, sy);
}
endShape(CLOSE);
}
TRANSFORMACIONES BIDIMENSIONALES
La función translate () permite que los
objetos se muevan a cualquier ubicación
TRASLACION dentro de la ventana. El primer parámetro
establece el desplazamiento del eje x y el
segundo parámetro establece el
desplazamiento del eje y.
void setup()
{
size(200, 200);
background(255);
noStroke();
// dibuja la posición original en gris
fill(192);
rect(20, 20, 40, 40);
// dibuja un rectángulo rojo translúcido
cambiando las coordenadas
fill(255, 0, 0, 128);
rect(20 + 60, 20 + 80, 40, 40);
// dibuja un rectángulo azul translúcido
traduciendo la cuadrícula
fill(0, 0, 255, 128);
pushMatrix();
translate(60, 80);
rect(20, 20, 40, 40);
popMatrix();
}
float x, y;
float dim = 80.0;

void setup() {
size(640, 360);
noStroke();
}
void draw() {
background(102);
x = x + 0.8;
if (x > width + dim) {
x = -dim;
}
translate(x, height/2-dim/2);
fill(255);
rect(-dim/2, -dim/2, dim, dim);

// Las transformaciones se acumulan.


Observe cómo se mueve este rect
// dos veces más rápido que el otro, pero
tiene el mismo
// parámetro para el valor del eje x
translate(x, dim);
fill(0);
rect(-dim/2, -dim/2, dim, dim);
}

Rotación de la manera correcta. La forma


correcta de rotar el cuadrado es: Traslade
el origen del sistema de coordenadas (0, 0)
a donde desea que esté la esquina superior
izquierda del cuadrado.
Gire la cuadrícula π / 4 radianes (45 °)
ROTACION Dibuja el cuadrado en el origen.
void setup()
{
size(200, 200);
background(255);
smooth();
fill(192);
noStroke();
rect(40, 40, 40, 40);

pushMatrix();
// move the origin to the pivot point
translate(40, 40);

// then pivot the grid


rotate(radians(45));
// and draw the square at the origin
fill(0);
rect(0, 0, 40, 40);
popMatrix();
}
void setup() { Y aquí hay un programa que genera una rueda
size(200, 200); de colores usando la rotación. La captura
background(255); de pantalla se reduce para ahorrar espacio.
smooth();
noStroke();
}
void draw(){
if (frameCount % 10 == 0) {
fill(frameCount * 3 % 255, frameCount *
5 % 255,
frameCount * 7 % 255);
pushMatrix();
translate(100, 100);
rotate(radians(frameCount * 2 % 360));
rect(0, 0, 80, 20);
popMatrix();
}
}
Los parámetros para la función scale ()
son valores especificados como
porcentajes decimales. Por ejemplo, la
ESCALA escala de llamada al método (2.0)
aumentará la dimensión de la forma en
un 200 por ciento. Los objetos siempre
se escalan desde el origen.
void setup()
{
size(200,200);
background(255);

stroke(128);
rect(20, 20, 40, 40);

stroke(0);
pushMatrix();
scale(2.0);
rect(20, 20, 40, 40);
popMatrix()
void setup()
{
size(200,200);
background(255);

stroke(128);
rect(20, 20, 40, 40);

stroke(0);
pushMatrix();
scale(3.0, 0.5);
rect(20, 20, 40, 40);
popMatrix();
}
TRASLACION, ROTACION Y ESCALA
float a = 0.0;
float s = 0.0;

void setup() {
size(640, 360);
noStroke();
rectMode(CENTER);
frameRate(30);
}

void draw() {

background(102);

a = a + 0.04;
s = cos(a)*2;

translate(width/2, height/2);
scale(s);
fill(51);
rect(0, 0, 50, 50);

translate(75, 0);
fill(255);
scale(s);
rect(0, 0, 50, 50);
}
float angle;
float jitter;

void setup() {
size(640, 360);
noStroke();
fill(255);
rectMode(CENTER);
}

void draw() {
background(51);

// during even-numbered seconds (0, 2, 4,


6...)
if (second() % 2 == 0) {
jitter = random(-0.1, 0.1);
}
angle = angle + jitter;
float c = cos(angle);
translate(width/2, height/2);
rotate(c);
rect(0, 0, 180, 180);
}

Potrebbero piacerti anche