Public
Edited
Oct 23, 2024
Insert cell
Insert cell
p5(sketch => {
sketch.setup = function() {
sketch.createCanvas(400, 500);
};
sketch.draw = function() {
sketch.push();
sketch.background(255);
//desenhaPonto(sketch,A);
//desenhaPonto(sketch,B);
//desenhaPonto(sketch,C);
sierpinski(sketch,A,B,C,4);
sketch.pop();
}
})
Insert cell
function sierpinski(sketch, A, B, C, nivel) {
if(nivel == 0) {
sketch.fill(0,0,255);
sketch.triangle(A[0],A[1],B[0],B[1],C[0],C[1]);
} else {
let D = [];
let E = [];
let F = [];
pontoNoSegmento(A,C,D,0.5);
pontoNoSegmento(C,B,E,0.5);
pontoNoSegmento(B,A,F,0.5);
sierpinski(sketch,A,D,F,nivel-1);
sierpinski(sketch,D,C,E,nivel-1);
sierpinski(sketch,F,E,B,nivel-1);

}
}
Insert cell
// function desenhaPonto(sketch, P) {
// sketch.circle(P[0],P[1],10);
// }
Insert cell
// function roda(A,B,C,angulo) {
// C[0] = ( (B[0]-A[0])*Math.cos(angulo) - (B[1]-A[1])*Math.sin(angulo) ) + A[0];
// C[1] = ( (B[0]-A[0])*Math.sin(angulo) + (B[1]-A[1])*Math.cos(angulo) ) + A[1];
// }
Insert cell
function pontoNoSegmento(A,B,C,t) {
C[0] = A[0] + t*(B[0]-A[0]);
C[1] = A[1] + t*(B[1]-A[1]);
}
Insert cell
A = [100, 300]
Insert cell
B = [300, 300]
Insert cell
C = [200, 200]
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more