xxxxxxxxxx
/*
* Reproduction of an alternate movie poster for Vertigo
* haschdl, 28/04/2018
* https://haschdl.github.io/generative
*/
var s0 = 450.;
var a0 = 0.08;
var a_coef = 1.00005;
var s, a,aTotal,mainColor;
function setup() {
createCanvas(450, 450);
rectMode(CENTER);
smooth(8);
noStroke();
mainColor = color(195,55,33);
init();
}
function init() {
background(mainColor);
s = s0;
a = a0;
aTotal=0;
}
function draw() {
if (s<=5)
return;
translate(width/2, height / 2);
rotate(aTotal);
//alternate colors
//between main and black
if(frameCount % 2 == 0)
fill(mainColor);
else fill(0);
rect(0, 0, s, s );
//new size of the square
//according to rotation angle.
//See Github for examplanation:
s = s / (sin(a) + cos(a));
//increases the rotation angle by a small amount
//and accumulates the rotationg angle
a *= a_coef;
aTotal+=a;
}
function mouseMoved() {
a0 = map(mouseX, 0, height, .1, .9);
init();
}
function keyPressed() {
switch(key) {
case 's':case'S':
save(String.format("vertigoIII_a0=%.2f_a_coef=%.2f.png",a0,a_coef));
println("File saved!");
break;
}
}