constructing dreams
feuillesnFeuillescolorAfeuilleAfeuilleBfeuilleCfeuilleDspiral1Arabesque
let r
let feuilles = [];
let nFeuilles
let colorA =[
"#e4c074",
"#deb256",
"#d49d61",
"#ca7d2e",
"#7e746e",
"#8f5f26",
"#a83f14",
"#802e0e",
"#501f0f",
"#2d130e"
]
function setup() {
createCanvas(windowWidth, windowHeight);
r=width/5;//size of leafs
nFeuilles =int(random(10,15))
background(200,200,180);
angleMode(DEGREES);
stroke(0);
noFill()
push()
d1=width/(nFeuilles )
for(let i=1;i<nFeuilles ;i++){
for(let j=1;j<nFeuilles ;j++){
feuilles.push(new Arabesque());
}
}
pop()
}
function draw() {
background(69,83,88)
translate(width/2,height/2);
scale(0.9,0.9)
rotate(frameCount/10)
for(let i=0;i<feuilles.length;i++){
feuilles[i].move();
push()
feuilles[i].display();
pop()
}
}
function feuilleA(){
beginShape()
for(let i=42;i<138;i++){
x=-r/3+r/2*sin(i);
y=r/2*cos(i);
vertex(x,y)
}
for(let i=138;i>42;i--){
x=r/3-r/2*sin(i);
y=r/2*cos(i);
vertex(x,y)
}
endShape()
}
function feuilleB(){
stroke(255)
beginShape()
for(let i=42;i<90;i++){
x=-r/3+r/2*sin(i);
y=r/2*cos(i);
vertex(x,y)
}
for(let i=-90;i>-120;i--){
x=r/3+r/6*sin(i);
y=r/6*cos(i);
vertex(x,y)
}
for(let i=-190;i<-120;i++){
x=r/3-r/6+r/12*sin(i);
y=r/12*cos(i);
vertex(x,y)
}
for(let i=-120;i>-180;i--){
x=r/3-r/6+r/12*sin(i);
y=r/12*cos(i);
vertex(x,y)
}
for(let i=100;i<139;i++){
x=-r/3+r/2*sin(i);
y=r/2*cos(i);
vertex(x,y)
}
for(let i=138;i>99;i--){
x=r/3-r/2*sin(i);
y=r/2*cos(i);
vertex(x,y)
}
for(let i=160;i>120;i--){
x=-r/3+r/6+r/12*sin(i);
y=r/12*cos(i);
vertex(x,y)
}
for(let i=120;i<197;i++){
x=-r/3+r/6+r/12*sin(i);
y=r/12*cos(i);
vertex(x,y)
}
for(let i=118;i>90;i--){
x=-r/3+r/6*sin(i);
y=r/6*cos(i);
vertex(x,y)
}
for(let i=-90;i<-41;i++){
x=r/3+r/2*sin(i);
y=r/2*cos(i);
vertex(x,y)
}
endShape()
}
function feuilleC(){
beginShape()
for(let i=42;i<138;i++){
x=-r/2.5+r/3*sin(i);
y=r/3*cos(i);
vertex(x,y)
}
for(let i=112;i>77;i--){
x=-r/3-r/6.5+r/3*sin(i);
y=-r/8+r/3*cos(i);
vertex(x,y)
}
for(let i=-90;i<-77;i++){
x=r/3+r/2*sin(i);
y=r/2*cos(i);
vertex(x,y)
}
for(let i=95;i>70;i--){
x=-r/3-r/6.5+r/3*sin(i);
y=r/8+r/3*cos(i);
vertex(x,y)
}
endShape()
}
function feuilleD(){
beginShape()
for(let i=81;i<160;i++){
x=-r/2.5+r/2*sin(i);
y=r/2*cos(i);
vertex(x,y)
}
for(let i=135;i>80;i--){
x=-r/2.5-r/10+r/2.4*sin(i);
y=-r/6+r/2.4*cos(i);
vertex(x,y)
}
for(let i=-95;i<-20;i++){
x=r/2.5+r/2*sin(i);
y=r/2*cos(i);
vertex(x,y)
}
for(let i=312;i>257;i--){
x=r/2.5+r/10+r/2.4*sin(i);
y=r/6+r/2.4*cos(i);
vertex(x,y)
}
endShape()
}
function spiral1(){
noFill()
beginShape()
for(let i=0;i<180;i++){
x=r/8*sin(i);
y=r/8*cos(i);
vertex(x,y)
}
for(let i=180;i<360;i++){
x=r/4*sin(i);
y=r/8+r/4*cos(i);
vertex(x,y)
}
for(let i=0;i<180;i++){
x=r/2*sin(i);
y=-r/8+r/2*cos(i);
vertex(x,y)
}
endShape()
}
class Arabesque{
constructor(){
this.x1=random(-width/2,width/2);
this.y1=random(-height/2,height/2);
this.vx = random(1,4);
this.vy = random(1,4);
this.x=this.x1;
this.y=this.y1;
this.r=random(width/5,width/2);
this.t=0;
this.feuille=random(-2,2.5);
this.scale=(random(-0.8,0.8))
this.color = int(random(0,9.9))
this.color2 = int(random(0,9.9))
}
move(){
this.t+=0.2
this.x = this.x1+this.r*sin(this.t*this.vy);
this.y = this.y1+this.r*cos(this.t*this.vx);
}
display(){
translate(this.x1,this.y1)
stroke(colorA[this.color2])
fill(colorA[this.color])
scale(this.scale,this.scale)
rotate(this.t*this.scale+this.y1)
if(this.feuille<=-1){
if(this.vx>3){
for(let i=0;i<this.color;i++){
push()
translate(r/12,0)
rotate(360/this.color*i);
feuilleA()
pop()
}
fill(colorA[this.color2])
translate(r/12,0)
circle(0,0,20)
}else{feuilleA()}
}
if(this.feuille>-1&&this.feuille<=0){
if(this.vx>3){
for(let i=0;i<int(this.color/2+2);i++){
push()
stroke(colorA[this.color2])
fill(colorA[this.color])
rotate(360/int(this.color/2+2)*i);
translate(0,r/2)
feuilleB()
pop()
}
if(this.vx>3.5){
for(let i=0;i<int(this.color/2+2)*2;i++){
push()
stroke(colorA[this.color])
fill(colorA[this.color2])
rotate(360/int(this.color/2+2)*i/2);
translate(0,r/2)
feuilleC()
pop()
}
}
}else{feuilleB()}
}
if(this.feuille>0&&this.feuille<=1){
feuilleC()
if(this.vx>2){
rotate(20)
stroke(colorA[this.color])
fill(colorA[this.color2])
feuilleC()
if(this.vx>3){
rotate(20)
stroke(colorA[this.color2])
fill(colorA[this.color])
feuilleC()
}
}
}
if(this.feuille>1&&this.feuille<=2){
feuilleD()
if(this.vx>2){
rotate(30)
translate(r/6,-r/6)
stroke(colorA[this.color])
fill(colorA[this.color2])
feuilleD()
if(this.vx>1){
rotate(30)
translate(r/6,-r/6)
stroke(colorA[this.color2])
fill(colorA[this.color])
feuilleD()
}
}
}
if(this.feuille>2){
spiral1()
}
}
}
function mousePressed(){
feuilles = [];
setup()
draw()
}