My apologies for that. It seems like the issue is caused by the windowWidth and windowHeight not being defined when creating the canvas. Here's an updated version of the code that should work properly:
Update your HTML file to add the p5.js WebGL library:
html
User
I need a cone with a flat tip bottom, instead of a sharp tip
Assistant
To create a cone with a flat tip bottom, we'll essentially create two cones and position them to form a frustum (the shape of a cone with the top cut off). Here's how you can modify the draw() function in the sketch.js file:
javascript
Then create a file called sketch.js and add the following code:
This code snippet defines a cup and a cylinder shape using p5.js WEBGL mode. The cup is a cone shape, and the cylinder is right below the cup. The dimensions of the cylinder follow your requirements - it has a height that is a quarter of the cup height and a width three times the cup width. The shapes rotate simultaneously in the 3D space for better visualization. Adjust the values of cupHeight and cupWidth to change the size of the cup and cylinder.
This should now display the rotating cup on top of the cylinder. The canvas will adjust its size to fit the window dimensions, and the right-click context menu has been disabled to avoid accidentally triggering it while rotating the shapes.
function draw() {
let cupHeight = 100;
let cupWidth = 50;
let cylinderHeight = cupHeight / 4;
let cylinderWidth = cupWidth * 3;
let flatTipHeight = 10; // Control the height of the flat tip
background(200);
ambientLight(100);
pointLight(255, 255, 255, mouseX - width / 2, mouseY - height / 2, 200);
rotateX(frameCount * 0.01);
rotateY(frameCount * 0.01);
// Draw cylinder
push();
fill(150, 0, 0);
translate(0, (cylinderHeight + (cupHeight - flatTipHeight)) / 2, 0);
cylinder(cylinderWidth, cylinderHeight);
pop();
// Draw top cone
push();
fill(0, 0, 150);
translate(0, -(cupHeight - flatTipHeight) / 2, 0);
rotateX(PI);
cone(cupWidth, cupHeight - flatTipHeight); // Reduce cone height by flatTipHeight
pop();
// Draw bottom cone (flat tip)
push();
fill(0, 0, 150);
translate(0, flatTipHeight, 0);
rotateX(PI);
cone(cupWidth - (flatTipHeight * 2), flatTipHeight * 2); // Make bottom cone smaller
pop();
}
You can adjust the flatTipHeight variable to control the height of the flat tip at the bottom of the cone. In this example, I've set it to 10 units.