xxxxxxxxxx
117
var angle = 0
var d
var cx
var cy
var points
var connectPoints
var slider
var showCircle
var showTrace
var showShape
var showDriver
var speed
let paper
function preload(){
paper = loadImage("background.jpg")
}
function setup() {
var canvas = createCanvas(windowWidth, windowHeight - 100)
canvas.parent("canvas")
slider = createSlider(2, 30, 2)
slider.parent("slider")
showCircle = createCheckbox("Show Circle:", false)
showCircle.parent("showCircle")
showTrace = createCheckbox("Show Traces:", false)
showTrace.parent("showTrace")
showShape = createCheckbox("Connect Points:", false)
showShape.parent("connectPoints")
showDriver = createCheckbox("Show Driver Point:", false)
showDriver.parent("showDriver")
speed = createSlider(0, 0.1, 0.05, 0.001)
speed.parent("speed")
d = 0.95 * min(height,width)
cx = width / 2
cy = height / 2
}
function draw() {
translate(cx, cy)
//background(200, 144, 111)
background(paper)
points = slider.value()
connectPoints = showShape.checked()
if(showDriver.checked())
traceDriver()
if (showCircle.checked())
drawCircle()
if (connectPoints)
beginShape()
if (showTrace.checked())
drawTrack()
for (var i = 0; i < points; i++) {
var t = i * PI / points
var r = d / 2 * cos(angle - t)
drawPoint(r, t)
}
if (connectPoints) {
strokeWeight(1)
noFill()
stroke(255, 0, 0)
endShape(CLOSE)
}
angle -= speed.value()
}
function drawPoint(r, t) {
stroke(255, 255, 0)
strokeWeight(10)
var x = r * cos(t)
var y = r * sin(t)
point(x, y)
if (connectPoints) {
vertex(x, y)
}
}
function drawTrack() {
stroke(0, 0, 255)
strokeWeight(1)
for (var i = 0; i < points; i++) {
var t = i * PI / points
var x = d / 2 * cos(t)
var y = d / 2 * sin(t)
line(x, y, -x, -y)
}
}
function drawCircle() {
stroke(0)
strokeWeight(1)
noFill()
ellipse(0, 0, d, d)
}
function traceDriver(){
stroke(0,0,255)
strokeWeight(10)
point(d/2*cos(angle), d/2*sin(angle))
}