Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
CUADRILATERO quad()
quad(38, 31, 86, 20, 69, 63, 30,
76);
RECTANGULO rect()
rect(30, 20, 55, 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);
pushMatrix();
// move the origin to the pivot point
translate(40, 40);
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);