Draw polygons & Wheels of Different Shapes/Sizes. This I found in khanacademy web, not my original code, just my angle, how I see it. Was looking for how to roll a cube.
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
None, just watch for fun. Rolling polygons, hmmm.
CC Attribution NonCommercial ShareAlike
Polygons & Wheels
xxxxxxxxxx
var sides = [3, 4, 5, 12]; // Drawing wheels of different shapes/sizes
var radius = 40; // Distance from center to corner of shape
var axleX = 300; // x-coordinate for the wheel
var speed = 1; // How fast the graph is drawn
var axlePositions = [[], [], [], []];
var BLUE = color(20, 100, 200);
var PINK = color(255, 0, 175);
var GREEN = color(28, 173, 123);
textSize(20);
textAlign(CENTER, CENTER);
var t = 0; // Time
void setup() {
size(800, 800);
}
void draw() {
background(250);
t += 2;
var angle = t % 360;
for (var i = 0; i < sides.length; i++) {
var numOfSides = sides[i];
var theta = 360 / numOfSides;
var halfTheta = theta / 2;
var groundY = (i + 1) * 100 - 10;
strokeWeight(3); // Ground
stroke(100);
line(0, groundY, width, groundY);
fill(0); // Label
text(numOfSides, width - 25, groundY - 40); // Pos of axle above ground
var y = groundY - radius * cos(((angle + halfTheta) % theta - halfTheta)*.0174);
axlePositions[i].push(y); // Save the position
if (axlePositions[i].length * speed > axleX) { // Rmv pos that are off screen
axlePositions[i].shift();
}
pushMatrix();
translate(axleX, y);
rotate(angle*.0174);
noFill(); // Draw shape
strokeWeight(3);
stroke(BLUE);
beginShape();
for (var j = 0; j < numOfSides; j++) {
vertex(radius * sin((j * theta)*.0174), radius * cos((j * theta)*.0174));
}
endShape(CLOSE);
stroke(GREEN); // Axel
strokeWeight(2);
ellipse(0, 0, 8, 8);
popMatrix();
beginShape(); // Draw axle positions
var x = axleX;
for (var j = axlePositions[i].length; j--;) {
vertex(x, axlePositions[i][j]);
x -= speed;
}
endShape();
}
};
See More Shortcuts
Please verify your email to comment
Verify Email