CODING: Scripts e refs

Links:

Star pattern maker / exporter
https://codingtrain.github.io/StarPatterns/

// anotações

/**
Cria espaço para comentários que serão incluídos na página HTML quando em modo Javascript
*/
// definir tamanho da tela com proporção áurea

int larg = 800;
void setup() {
 size (larg, int (larg/1.618));

// GRAVAR FRAMES

void keyPressed() {
 if (key == 's' || key == 'S') {
 saveFrame("frames####.png");
 }}

com data

saveFrame("output/" +year()+month()+day()+minute()+second() 
+".png");
println("frame saved!");

_____________

// maquina escrever

x += 5;
 if (x >= width){ y += 50;  x=0; }
 if (y >= height){ y = 0; }

// MAP

// map( valor a mapear, start1, stop1, start2, stop2)
float imagemx = map(telax, 0, width, 0, imagem.width);
// cor de fundo
color cor = imagem.get((int)imagemx, (int)imagemy);

__

// extrai valores de cor
 float vermelho = red(cor);
 float verde = green(cor);
 float azul = blue(cor);
 float brilho = brightness(cor);

valor de luminância a partir de RGB ( calculo compensatório usado automaticamente pelo brightness [Y] )

Y = 0.2126 R + 0.7152 G + 0.0722 B

_____________________________________

CLASSES
// Matriz

Nomedaclasse parts[];

void setup() {

parts = new Nomedaclasse[100]; // pede memoria para 100 elementos

for (int i=0; i < 100; i++) { // constroi cada elemento
 parts[i] = new Nomedaclasse();
 } }

void draw() { // chama o desenhador

for (int i = 0; i < 100; i++) { // 
 parts[i].go();
 } }

// estrutura da classe:

class Nomedaclasse {

float x, y;
 color cor;
}

// construtor com argumento (d) – age como setup()

Nomedaclasse(float d) {
 x = width/2;
 y = height/2;
 size = d ;
 r=random(255);
 g=random(255);
 b=random(255);
 }

// desenha
void go() {

x += random(-dev, dev);
 y += random(-dev, dev);

constrange();

fill (cor);
 ellipse(x, y, size, size);
 }
}

// constrange ao interior do ecra por teleporte

void constrange() {
if (x < 0) {x += width;}
 if (x > width) {x -= width;}
 if (y < 0) {y += height;}
 if (y > height) {y -= height;} 
}

// ou limita ao interior do ecra (com vector)

PVector pos;
pos = new PVector(velx, vely);

if (pos.x < 0) {pos.x = 0;}
if (pos.x > width - 1) {pos.x = width;}
if (pos.y < 0) {pos.y = 0;}
if (pos.y > height - 1) {pos.y = height;}

// verifica limites horizontais

if (x > width || x < 0) { xspeed *= - 1; }

// verifica limites verticais

if (y > height || y < 0) { yspeed *= - 1; }

_______________________________________________

MOVIMENTO BROWNIANO

float dev = random(-a, a);
x += dev;
y += dev;

_______________________________________________

aceleração: integração à base de EULER

Força = massa x aceleraçao ( F = m x a )

___

// limita os valores da variável (var, min, máx)

constrain (x, 0, width);
constrain (r, 0, 255);

_____________________________________

CURVA DE LISSAJOUS

x= width/2 + width/2 * sin (vx*frameCount);
y= height/2 + height/2 * sin (vy*frameCount);

_____________________________________

MOVIMENTO POLAR
COORDENADAS EM ANGULOS

PI = 180º

conversão de coordenadas cartesianas para sistema polar

x = raio x COS ang.
y = raio x SIN ang

_____________________________________

PLAYER

void keyPressed() {
 if (kleft) { ang -= 0.1; }
 if (kright) { ang += 0.1; }
 if (kdown) { raio -= 0.1; }
 if (kup) { raio += 0.1; }
}
void keyPressed() {
 if (key=='a' || keyCode == LEFT) { kleft=true; }
 if (key=='s' || keyCode == RIGHT) { kright=true; }
 if (key=='w' || keyCode == UP) { kup=true; }
 if (key=='s' || keyCode == DOWN) { kdown=true; }
}
void keyReleased() {
 if (key=='a' || keyCode == LEFT) { kleft=false; }
 if (key=='s' ||keyCode == RIGHT) { kright=false; }
 if (key=='w' ||keyCode == UP) { kup=false; }
 if (key=='s' ||keyCode == DOWN) { kdown=false; }
}

_____________________________________

VECTOR MAPPING

pushMatrix(); // faz com que as traducoes sejam só dentro da matrix

rotate(angulo); // em ( PI ) ou ( radians(graus) )

pushMatrix();
 beginShape();
 texture(img); // imprime a textura dentro da forma
 vertex(-10, -10 , 0, 0);
 vertex(20, 0 , 256, 128);
 vertex(-10, 10 , 0, 256);
 endShape(CLOSE); // close fecha a forma e dispensa a ultima coordenada popMatrix();
rotateX(millis() / 1000.0); // rotação através do tempo (milisecs)

_____________________________________

MOVIE E CAMERA

// para saber quais as dimensoes do filme

 println("movie w h:" + myMovie.width + " " + myMovie.height);
// ou camera
 println("movie w h:" + cam.width + " " + cam.height);