xxxxxxxxxx
83
/*
برنامه ی شبیه سازی جفت طوسی
درونچرخهزاد
یونا طالبی مقدم
مدرسه احسان
1403-1404
2025-2026
ارائه ی فارسی
دبیر: استاد غیپ پرور
*/
/*
YOUNA TALEBI MOGHADDAM
ORIGINALLY MADE FOR MY LITERATURE PRESENTATION
NOW FOR THE PASSENGER SHOW CASE
TUSI COUPLE/CYCLOID SIMULATION
*/
let t = 0;
let d = 5;
let r1, r2;
let x1, y1;
let px, py;
let centerX, centerY;
let trail = []; // Array to store the trail points
function setup() {
createCanvas(400, 400);
}
function draw() {
background(0);
translate(width / 2, height / 2);
noFill();
strokeWeight(3);
stroke(255);
// Draw the larger circle
r1 = 100;
circle(0, 0, r1 * 2);
// Draw the smaller circle
stroke(255, 0, 0);
strokeWeight(3);
//CHANGE THE DIVISOR TO GET DIFFERENT SHAPES!
r2 = r1 / 3;
x1 = (r1 - r2) * cos(t);
y1 = (r1 - r2) * sin(t);
stroke(0, 255, 0);
strokeWeight(3);
circle(x1, y1, r2 * 2);
centerX = x1;
centerY = y1;
px = (r1 - r2) * cos(t) + r2 * cos(((r1 - r2) / r2) * t);
py = (r1 - r2) * sin(t) - r2 * sin(((r1 - r2) / r2) * t);
// Add the current point to the trail
trail.push(createVector(px, py));
// Draw the trail
stroke(255, 0, 0);
strokeWeight(4);
noFill();
beginShape();
for (let i = 0; i < trail.length; i++) {
vertex(trail[i].x, trail[i].y);
}
endShape();
// Draw the current point
stroke(100, 0, 155);
strokeWeight(15);
point(px, py);
// Increment t (angle) for the next frame
t += 0.01;
if (trail.length > 10000) {
trail.splice(0, 1); // Remove the oldest point
}
}