Public
Edited
Feb 11, 2024
Insert cell
Insert cell
p5(sketch => {

sketch.setup = () => {
// Create the canvas
sketch.createCanvas(400, 400);
sketch.noLoop();
};

sketch.draw = () => {
// Set the background color
sketch.background(150, 0, 150, 150);

// Draw the main shape
sketch.noFill();
sketch.strokeWeight(4);
sketch.beginShape();
// Draw the main shape with a new fill color
sketch.fill(150, 0, 150, 150); // Purple color
sketch.strokeWeight(2);
sketch.stroke(100, 0, 100); // Darker purple for the border
sketch.beginShape();
sketch.endShape(sketch.CLOSE);
// Draw stars
drawStars();
};

function drawStar(x, y, radius1, radius2, npoints) {
let angle = sketch.TWO_PI / npoints;
let halfAngle = angle / 2.0;
let startAngle = sketch.HALF_PI;
sketch.beginShape();
for (let i = 0; i < npoints; i++) {
// Outer point
let outerX = x + sketch.cos(startAngle - i * angle) * radius1;
let outerY = y - sketch.sin(startAngle - i * angle) * radius1;
sketch.vertex(outerX, outerY);
// Inner point
let innerX = x + sketch.cos(startAngle - (i + 0.5) * angle) * radius2;
let innerY = y - sketch.sin(startAngle - (i + 0.5) * angle) * radius2;
sketch.vertex(innerX, innerY);
}
sketch.endShape(sketch.CLOSE);
}

function drawStars() {
let starCount = 50; // Change this to the number of stars you want
sketch.fill(150, 0, 150, 150); // White color for stars
for (let i = 0; i < starCount; i++) {
// Random position within the bounds of the shape
let x = sketch.random(sketch.width);
let y = sketch.random(sketch.height);
let npoints = i % 2 === 0 ? 4 : 5; // Alternate between 4 and 5 points
// Randomize the size of the stars
let radius1 = sketch.random(5, 10); // Outer radius between 5 and 15
let radius2 = radius1 * sketch.random(0.5, 0.6); // Inner radius between 50% and 90% of the outer radius

drawStar(x, y, radius1, radius2, npoints); // You can play with these values to get different star shapes
}
}
})
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