xxxxxxxxxx
129
/*
* Sketch: DPMOsc_002
* Parent Sketch: none
* Type: static
*
* Summary : Harmonic Motion
*
* GIT:
* Author: mark webster 2020
* https://dpmanual.bitbucket.io
* https://designingprograms.bitbucket.io
*
* LICENCE
* This software is part of a package of pedagogical tools used
* with the online website, Computational Graphic Design Manual :
* https://dpmanual.bitbucket.io
*
* Copyright ©2020 mark webster
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.html.
*
*/
let m; // motion value
let mode = 0;
let gridStep = 40;
let myFont;
let isBlur;
function preload() {
myFont = loadFont('IBMPlexMono-Light.ttf');
}
function setup() {
createCanvas(500, 500);
noStroke();
textFont(myFont);
textSize(12);
}
function draw() {
if (isBlur) {
fill(0, 33);
rect(0, 0, width, height);
} else {
background(0);
}
fill(255);
let f = map(mouseX, 0, width, 0.025, 0.065);
let amp = map(mouseY, 0, height, 10, 50);
for (let y = 50; y < height - 25; y += gridStep) {
for (let x = 50; x < width - 25; x += gridStep) {
switch (mode) {
case 0:
m = sin((x + y) + frameCount * f) * amp;
ellipse(x, y, m, m);
break;
case 1:
m = sin((x * y) + frameCount * f) * amp;
ellipse(x, y, m, m);
break;
case 2:
m = sin((x * f) + frameCount * f) * amp;
ellipse(x, y, m, m);
break;
case 3:
m = sin((x * f) + frameCount * f) * amp;
ellipse(x + m, y, m, m);
break;
case 4:
m = sin((x * f) + frameCount * f) * amp;
ellipse(x, y + m, m, m);
break;
case 5:
m = sin((y * f) + frameCount * f) * amp;
ellipse(x + m, y, m, m);
break;
case 6:
m = sin((y * f) + frameCount * f) * amp;
let m2 = sin((x * f) + frameCount * f) * amp;
ellipse(x + m + m2, y, m, m);
break;
}
}
}
text("Motion Mode: " + mode, 15, height - 20);
}
function keyPressed() {
if (key == 'b') {
isBlur = !isBlur;
}
if (key == '+') {
if (mode < 6) {
mode++;
}
}
if (key == '-') {
if (mode > 0) {
mode--;
}
}
if (key == 'l') {
gridStep += 5;
}
if (key == 'm') {
if (gridStep > 5)
gridStep -= 5;
}
}