Skip to content

Instantly share code, notes, and snippets.

@andrusenn
Created October 19, 2018 23:32
Show Gist options
  • Save andrusenn/3c3c88b29b1b3d50fbf5ee1718f37f08 to your computer and use it in GitHub Desktop.
Save andrusenn/3c3c88b29b1b3d50fbf5ee1718f37f08 to your computer and use it in GitHub Desktop.
Eclipses
/*
Algoritmo base para la serie Eclipses
Base algorithm for Eclipses series
2016-2018
*/
PGraphics ghost;
PImage img1;
Espiro e1;
boolean dis = false;
void setup()
{
size(1000, 1000);
// Imagen fantasma donde se obtiene el blanco y negro (negativo)
// Ghost image for get black and white (negative)
ghost = createGraphics(int(width), int(height));
ghost.beginDraw();
ghost.rectMode(CENTER);
ghost.noStroke();
ghost.background(255);
ghost.fill(0);
ghost.rect(width/2, height/2, 500, 500);
ghost.fill(255);
ghost.rect(width/2, height/2, 200, 200);
ghost.endDraw();
e1 = new Espiro();
e1.centrox = height/2;
e1.centroy = height/2;
rectMode(CENTER);
// Figuras / Shapes --------------------------
background(255);
noStroke();
fill(0);
rect(width/2, height/2, 750, 750);
fill(255);
rect(width/2, height/2, 100, 100);
// Get ghost image / Imagen fantasma
img1 = ghost.get();
}
void draw()
{
// Espiro
for (int i = 0; i < 25; i++) {
e1.render();
}
// Cortado / Cutting
if (dis) {
float r = random(10, 80);
for (int x = int(width*0.0); x < width*1.0; x+=r) {
for (int y = int(height*0.0); y < int(height*1); y+=r) {
r = random(10, 80);
// Empezar cortado desde la mitad / Begin cutting from half
if (y>height*0.6 && x > width * 0.2 && x < width*0.8) {
float r1 = random(10, 600);
float r2 = random(10, 600);
// Si el corte sobrepasa el margen / If cut overflow margin
if (x + r1 > width) {
r1 = width-x;
}
if (y + r2 > height) {
r2 = height-y;
}
// Nueva posicion / new position
int nx = int(map(noise(x*0.002, y*0.002), 0, 1, -10, 10)*cos(x*0.1));
int ny = int(map(noise(x*0.002, y*0.002), 0, 1, 20, -40)*sin(y*0.2));
PImage i = get(x, y, int(r1), int(r2));
// Pegar fragmento y estilizarlo / Paste fragment and stylize
strokeWeight(0.2);
set(int(x+nx), int(y+ny), i);
noFill();
stroke(255, 50);
rectMode(CORNER);
rect(x+nx, y+ny, i.width, i.height);
stroke(255, 50);
line(x+nx, y+ny, x+nx+1000, y+ny);
stroke(0, 100);
line(x+nx, y+ny, x+nx, y+ny+1000);
}
}
}
dis = false;
}
}
void keyPressed()
{
if (key=='s')
{
String n = year()+""+month()+""+day()+""+hour()+""+minute()+""+second();
save("save/" + n + "-c.jpg");
}
// Cortar con la tecla c / Cut with c key
if (key == 'd') {
dis = true;
}
}
/*
El código también es arte!! {o no?}
Code is art too!! {or not?}
*/
// Clase espirógrafo / Spirograph
/*
para hacer mucho ruido
to make a lot of noise
*/
class Espiro
{
float radio1 = 0.0;
float radio2 = 0.0;
float radio1a = 1000;
float radio2a = 1000;
// Modificadores de x,y
float theta = 0.0;
float phi = 0.0;
float vel_theta = radians(0.03);
float vel_phi = radians(0.05);
// Modificadores del radio
float theta1 = 0.0;
float phi1 = 0.0;
float vel_theta1 = radians(0.06);
float vel_phi1 = radians(0.3);
//
float posx = 0.0;
float posy = 0.0;
float centrox = 0.0;
float centroy = 0.0;
float vel_centrox = 0.00000;//0.0
float vel_centroy = 0.000000;//0.000005
float fricc = 0.99999998;
int c = 0;
String init_parametros;
String fin_parametros;
int num = 10000;
float str = 0.2;
boolean n = true; // noise
float zoomx = 0.008;//0.007
float zoomy = 0.01;//0.01
float offsetx = -10000;
float offsety = 1000;
Espiro() {
}
void update()
{
posx = centrox + cos(theta) * radio1;
posy = centroy + sin(phi) * radio2;
if (n)
{
radio1 = radio1a * noise((posx+offsetx) * zoomx, posy * zoomy) * cos(theta1);
radio2 = radio2a * noise((posx+offsety) * zoomx, posy * zoomy) * sin(phi1);
} else
{
radio1 = radio1a * cos(theta1);
radio2 = radio2a * sin(phi1);
}
radio1a *= fricc;
radio2a *= fricc;
theta += vel_theta;
phi += vel_phi;
theta1 += vel_theta1;
phi1 += vel_phi1;
centrox += vel_centrox;
centroy += vel_centroy;
}
void render()
{
for (int i = 0; i < num; i++)
{
update();
if (brightness(img1.get(int(posx), int(posy)))>167) {
stroke(0, 255);
} else {
stroke(255, 255);
}
// Dibuja
pushStyle();
beginShape(POINTS);
strokeWeight(str);
vertex(posx, posy);
endShape();
popStyle();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment