Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add bristles mode to Yellow Scream (2024) project #36

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions projects/yellow-scream/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ let mic;
let x;
let y;
let yellowColor;
let yellowColor2;
let bristleColors;
let bristleSeed;
let isPainting = false;
let currentbrushWidth;

Expand All @@ -15,6 +18,7 @@ const params = {
screamThreshold: 10,
brushWidth: 80,
maxBrushYJitter: 0.2,
numBristles: 5,
};

// Set up param gui
Expand All @@ -29,6 +33,7 @@ gui.add(params, 'screamThreshold', 0, 300, 5);
gui.add(params, 'brushSpeed', 0.1, 5, 1);
gui.add(params, 'brushWidth', 1, 100, 5);
gui.add(params, 'maxBrushYJitter', 0, .6, .1);
gui.add(params, 'numBristles', 1, 100, 1);

function setup() {
let availableHeight = 1 + windowHeight - document.getElementById("project-body").offsetTop;
Expand All @@ -55,6 +60,7 @@ function setup() {
function draw() {
// https://stackoverflow.com/questions/55026293/google-chrome-javascript-issue-in-getting-user-audio-the-audiocontext-was-not
getAudioContext().resume();
noStroke();

// Get the overall volume (between 0 and 1.0)
let vol = mic.getLevel() * 1000;
Expand All @@ -63,12 +69,19 @@ function draw() {
// Start a stroke
x = random(windowWidth);
y = random(height);
yellowColor = color(255, 204 + random(-10, 100), 0);

bristleColors = [];
let baseGreen = 204 + random(-10, 100);
for (let i=0; i < params.numBristles; i++) {
bristleColors.push(color(255, baseGreen + random(-5, 5), 0));
// yellowColor = color(255, 204 + random(-10, 100), 0);
// yellowColor2 = color(255, 204 + random(-10, 100), 0);
}
console.log(bristleColors);
isPainting = true;
currentbrushWidth = params.brushWidth + random(-1.0, 1.0);
currentbrushWidth = params.brushWidth + random(-1.0, 1.0); // TODO-future: tweak random amount
} else if (vol > params.screamThreshold && isPainting) {
// Continuing a stroke

x -= params.brushSpeed;
y += random(-params.maxBrushYJitter, params.maxBrushYJitter);
} else if (isPainting) {
Expand All @@ -77,12 +90,20 @@ function draw() {
}

if (isPainting) {
fill(yellowColor);
noStroke();
square(x, y, currentbrushWidth, 0);
drawBrushIncrement();
}
}

function drawBrushIncrement() {
let bristleWidth = currentbrushWidth / bristleColors.length;
for (let i=0; i < bristleColors.length; i++) {
fill(bristleColors[i]);
square(x, y + i * bristleWidth, bristleWidth, 0);
}
}

// TODO - Adjust individual bristle speed and/or starting point

function saveMasterpiece() {
let cnv = document.getElementById("p5-canvas");
let date = new Date().toISOString().split("T")[0];
Expand Down