Created
April 22, 2019 13:26
-
-
Save yutannihilation/27a17099155d6b65d6f08ad310567432 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let steps = 100; | |
let offset = 0; | |
function drawStripeCircle(steps) { | |
clear(); | |
let r = min(width, height); | |
let a = 2 * PI / steps; | |
for (let i = 0; i < steps; i++) { | |
// black | |
stroke(0); | |
fill(0); | |
arc(width / 2, height / 2, r, r, a * i + offset, a * (i + 0.5) + offset); | |
// white | |
noStroke(); | |
fill(255); | |
arc(width / 2, height / 2, r, r, a * (i + 0.5) + offset, a * (i + 1) + offset); | |
} | |
} | |
function setup() { | |
createCanvas(windowWidth, windowHeight); | |
background(255); | |
} | |
function draw() { | |
drawStripeCircle(round(steps)); | |
} | |
function mouseDragged() { | |
// change of the distance to the center | |
let cdist = dist(width / 2, height / 2, mouseX, mouseY); | |
let pdist = dist(width / 2, height / 2, pmouseX, pmouseY); | |
steps = constrain(steps + (cdist - pdist), 1, 255); | |
// change of the rotation | |
let crot = atan2(mouseY - height / 2, mouseX - width / 2); | |
let prot = atan2(pmouseY - height / 2, pmouseX - width / 2); | |
offset = offset + (crot - prot); | |
} | |
function windowResized() { | |
resizeCanvas(windowWidth, windowHeight); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://codepen.io/anon/pen/axjwLe