xxxxxxxxxx
67
/*
Adapted from source:
Aesthetic Programming by Winnie Soon & Geoff Cox
https://www.aesthetic-programming.net/pages/3-infinite-loops.html#setup-70191
LICENSE
[Aesthetic Programming] is an open access book, licensed under the Creative Commons Attribution By Attribution Share Alike License. Under this license, authors allow anyone to download, reuse, reprint, modify, distribute, and/or copy their work so long as the authors and source are cited and resulting derivative works are licensed under the same or similar license. No permission is required from the authors or the publisher. Statutory fair use and other rights are in no way affected by the above. Read more about the license at https://creativecommons.org/licenses/by-sa/4.0/
See Creative Commons License and MIT License here: https://creativecommons.org/licenses/by/4.0/ and https://opensource.org/licenses/MIT
*/
//define position variables
let totalPositions = 15;
let positionIndex = 0;
//initiate setup
function setup() {
//set canvas to window size
createCanvas(windowWidth, windowHeight);
//let angle be set in degrees
angleMode(DEGREES);
//fill shapes with white
fill(0);
//no outline
noStroke();
}
//initiate draw loop
function draw() {
//set background to black with an alpha of 5 for circle animation
background(255, 5);
//move shapes to center of canvas
translate(width / 2, height / 2);
//define positionIndex as a rounding of frameCount divided by 9
positionIndex = round(frameCount / totalPositions);
console.log(frameCount);
console.log(positionIndex);
//define angle to 40 times remander of positionIndex / 9
let angle = (360 / totalPositions) * (positionIndex % totalPositions);
console.log(angle);
//rotate by angle
rotate(angle);
//define minimum dimension to window width or height, whichever is smaller
let minDimension = min(width, height);
//define diameter to 5$ of minumum dimension
let diam = minDimension * 0.05;
//create circle with a position of 50, 0, and the defined diameter
rect(50, 0, 50, 50);
}
//function to resize window
function windowResized() {
//resize canvas if window is resized
resizeCanvas(windowWidth, windowHeight);
//set background to black
background(0);
}