xxxxxxxxxx
// make source code public
// schien@mail.ncku.edu.tw, Spring 2025
//
// start with drawing a circle in wiggle shapes
// then
// 1. replace the circumference with radius line
// 2. small adjustment in stroke
// 3. small adjustment in radius
// 4. small adjustment in angle rotation
// 5. small adjustment in center
//
// program for lectures on "The Wrong Way to Draw a Circle"
// from "Wave Clock" of Pearson (2011)
// schien@mail.ncku.edu.tw
// Fall 2018
//
// adjusting from var scoping to let scoping
// schien@mail.ncku.edu.tw, Spring 2023
//
// adjustment 2 (part 1)
let _strokeCol = 254;
let _strokeChange = -1;
// adjustment 3
let _noiseVal;
// adjustment 4 (part 1)
let ang = 0;
let _angNoise;
// adjustment 5 (part 1)
let _xnoise;
let _ynoise;
function setup() {
createCanvas(500, 300);
//noLoop();
background(255);
_noiseVal = random(10); // adjustment 3
_angNoise = random(1); // adjustment 4
_xnoise = random(10); // adjustment 5
_ynoise = random(10);
}
function draw() {
strokeWeight(0.3);
noFill();
var radius = 200;
//let centerX = width/2;
//let centerY = height/2;
// adjustment 5
_xnoise += 0.01;
_ynoise += 0.01;
let centerX = width/2 + noise(_xnoise)*100 - 50;
let centerY = height/2 + noise(_ynoise)*100 - 50;
// the easy way
//stroke(0, 30);
//ellipse(centerX, centerY, 2*radius, 2*radius);
// draw the filled circle using "shape"
//stroke(20, 50, 70);
// adjustment 2 (part 2)
_strokeCol += _strokeChange;
if (_strokeCol > 254) {
_strokeChange = -1;
}
if (_strokeCol < 0) {
_strokeChange = 1;
}
stroke(_strokeCol, 60);
let x, y;
//let noiseVal = random(10);
let radVariance, thisRadius, rad;
//beginShape();
//fill(20, 50, 50, 50);
//for (var ang=0; ang<360; ang+=1) {
_angNoise += 0.005;
ang += noise(_angNoise)*6 - 3;
if (ang > 360) {
ang -= 360;
}
if (ang < 0) {
ang += 360;
}
// adjustment 3
_noiseVal += 0.005;
thisRadius = 1 + noise(_noiseVal)*550;
//noiseVal += 0.1;
//radVariance = 30 * customNoise(noiseVal);
//thisRadius = radius + radVariance;
rad = radians(ang);
x = centerX + thisRadius*cos(rad);
y = centerY + thisRadius*sin(rad);
//curveVertex(x, y);
// adjustment 1
let opprad = rad + PI;
let x0 = centerX + thisRadius*cos(opprad);
let y0 = centerY + thisRadius*sin(opprad);
line(x, y, x0, y0);
//}
//endShape();
}
// another customed noise function
function customNoise(value) {
let count = int(value%12);
let retValue = pow(sin(value), count);
return retValue;
}