Published
Edited
Mar 8, 2020
Insert cell
Insert cell
Insert cell
Insert cell
function drawCircle(_x, _y, _radius, _fact, sketch) {
sketch.ellipse(_x, _y, _radius/2, _radius/2);

// Notice our condition to avoid an infinite loop!
// Try different values, comment out lines, try to understand
// the general construction
if (_radius > 7.3) {
_radius *= _fact;
drawCircle(_x+_radius/2, _y, _radius/2, 1, sketch);
drawCircle(_x-_radius/2, _y, _radius/2, 1, sketch);
drawCircle(_x, _y+_radius/2, _radius/2, 1, sketch);
drawCircle(_x, _y-_radius/2, _radius/2, 1, sketch);
}
}
Insert cell
Insert cell
p5(sketch => {
  sketch.setup = function() {
sketch.createCanvas(640, 420);
   sketch.background(255);
sketch.noFill();
};
sketch.draw = function() {
sketch.background(0,0,33);
sketch.stroke(255);
sketch.strokeWeight(1);

// we call our function here passing in values for our arguments
// Try different values for the radius & factorial arguments
drawCircle(320, 210, 750, 0.65, sketch);
 };
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more