xxxxxxxxxx
98
// https://discourse.processing.org/t/gentle-jiggle-with-sine-wave/5291
let drawline = false;
let strong = 1.0;
let wind = 5.0;
let winddir = 0.0;
let Red = 100;
let Grn = 100;
let Blu = 100;
function print_help(){
print("click and drag to start draw lines ");
print("use mouse wheel for line width");
print("use Arrow UP DOWN for wind speed");
print("use Arrow LEFT RIGHT for wind direction");
print("use SHIFT for Eraser");
print("key [r] [g] [b] and mouse wheel for color");
print("use key [c] for clear, key [x] reset");
print("status:");
print(" wind:"+wind+" winddir: "+winddir+" line width: "+strong);
print(" Red: "+Red+" Green: "+Grn+" Blue: "+Blu);
}
function setup() {
createCanvas(500, 500);
colorMode(RGB, 100);
background(0);
stroke(255);
print_help();
}
function draw() {
strokeWeight(strong);
stroke(Red,Grn,Blu);
if ( keyIsPressed && keyCode === SHIFT ) stroke(0); // Eraser
if (drawline) line(mouseX, mouseY, mouseX + wind * sin(winddir / TWO_PI), mouseY + wind * cos(winddir / TWO_PI));
}
function mouseDragged() {
drawline = true;
}
function mouseReleased() {
drawline = false;
}
function mouseWheel(event) {
if (keyIsPressed) {
if (key === 'r') {
Red += event.delta; Red = constrain(Red,0,100);
print("Red: " + nf(Red, 1, 1));
} else
if (key === 'g') {
Grn += event.delta; Grn = constrain(Grn,0,100);
print("Green: " + nf(Grn, 1, 1));
} else
if (key === 'b') {
Blu += event.delta; Blu = constrain(Blu,0,100);
print("Blue: " + nf(Blu, 1, 1));
}
} else {
strong += event.delta / 10.0;
if (strong < 0) strong = 1.0;
print("line weight: " + nf(strong, 1, 1));
}
return false;
}
function keyReleased() {
if (keyCode === UP_ARROW) {
wind++;
print("new wind: " + wind);
}
if (keyCode === DOWN_ARROW) {
wind--;
print("new wind: " + wind);
}
if (keyCode === LEFT_ARROW) {
winddir--;
print("new winddir: " + winddir);
}
if (keyCode === RIGHT_ARROW) {
winddir++;
print("new winddir: " + winddir);
}
if (key === 'c') { // clear
background(0);
}
if (key === 'x') { // reset
Red = 100; Grn = 100; Blu = 100; wind = 5; winddir = 0; strong = 1;
print("reset");
}
}