You are on page 1of 3

FRACTAL H

LINK: https://editor.p5js.org/pecondoriyu/sketches/4TLx5fRG2

function setup() {
createCanvas(400, 400);
}

function draw() {
background(220);

fractalH(150,100,150,300);
}
function hache(x,y,x1,y1) {
line(x, y, x1, y1);
line(x, (y1+y)/2 , x1+(y1/3), (y1+y)/2);
line(x+(y1/3), y, x1+(y1/3), y1);
}
function fractalH(x,y,x1,y1) {

if(y1>12.5){
fractalH(x-(y/4),y/2,x1-(y/4),y1/2);
fractalH(x+(y1/4),y/2,x1+(y1/4),y1/2);

hache(x,y,x1,y1);
}

if(y1>12.5){
push();
translate(0,y1+(y/2));
fractalH(x%x,y1+(y/2),y%y,y1/2);
hache(x,y,x1,y1);
pop();

}
FRACTAL ARBOL 3D

LINK: https://editor.p5js.org/pecondoriyu/sketches/EnYGvDLsq

t = 0
w = 700

setup =_=> {
createCanvas(w, w)
c = w/2
stroke(c)
}

draw =_=> {
background(0)
t += 0.009
c=w/2
for (i = 0; i <6; i+=PI/4)
f(c, c, i, w/7)

//if(t>2*PI){
// noLoop()
//}
}

f = (x, y, r, d) => {
strokeWeight(d/20);
if (d > 3) {
line(x, y, x += cos(r) * d, y -= sin(r) * d)
f(x, y, r + y / 99 + t, d / 1.5)
f(x, y, r - y / 99 - t, d / 1.5)
}
}
FRACTAL ARBOL 2D

LINK: https://editor.p5js.org/pecondoriyu/sketches/6LCfbcjWO

var angulo
var principal

function setup() {
createCanvas(500, 500);
principal = createSlider(0, 2 * PI, PI / 4, 0.01)
principal.position(10, height);
}

function draw() {
background(220);
angulo = principal.value();
translate(width/2, height);
hoja(100);

function hoja(len) {
line(0, 0, 0, -len);
translate(0, -len);
if (len > 10) {
push();
rotate(angulo);
hoja(len * 0.75)
pop();
push();
rotate(-angulo);
hoja(len * 0.75)
pop();
}
}

You might also like