Something went wrong. Try again.
Monorepo for Aesthetic.Computer aesthetic.computer
Something went wrong. Try again.
4.3 kB ยท 156 lines
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157// ucla-3, 24.07.09.07.52// Essential sonics and data types.
/* ๐ Notes - Today we will be synthesizing sound using primitive wave types, and learning about structured data in JavaScript. ๐ basic data types: `string`, `boolean`, `number` composite types: `array`, `object` ๐ช๏ธ `act`, `event`, `synth` - Exercises - 1. [๐ก] Writing text and basic math. 2. [๐ก] Keyboard input as a trigger. ๐ฉ๐ฆ 3. [๐ก] Synthesizing sound. ๐น 4. [] Growing visually and sonically. ๐ชฑ
โจ๏ธ Useful `Visual Studio Code` shortcuts. ๐ + Shift + P -> Format Document ๐ + / -> Toggle Comments*/
let myNumber = 0;let myOtherNumber = 0;
function paint({ wipe, ink, write }) { wipe(myNumber, 128, 200); // clears the screen to blue // calls the function 'wipe' and sends it a string "blue" ink("yellow"); // Combining strings. // ARRAYS ["J", "e", "f", "f"] // 0 1 2 3 // To get "e", you write first[1]; const first = "Jeffrey"; // 0123456 const space = ", "; const second = "says..."; write(first + space + second, 16, 16); // text, x, y ink("lime"); write(`${first} ${second}`, 16, 32); // ${ ... any javascript ... } ink("cyan"); write(first[1], 16, 48); // 2nd char of the 'first' string. // ๐ช Slice up from first (0) character (J) to 4th character, (f) write(first.slice(0, 4), 16, 64); write(first.toUpperCase(), 16, 80); // Transformations on a string. ink("red");
// myNumber = myNumber + 1; // Add one to myNumber.
let result = myNumber; // Math.min(1, 1, 3, 4, 1, 1, 10) // (13 + 2) * 10; // Why is this 33? // Multiplation always happens before arithmetic. // Change order, using parenthesis.
write(result, 16, 96); // reference
ink("lime"); write(myOtherNumber, 16, 128);}
// โญ CC GG AA G FF EE DD C// GG FF EE D// GG FF EE D
// Mary had a little lamb. ๐ฆ// EDCDEEE// DDD EGG// EDCD EEEE// DD EDC
const notes = ["c", "d", "e", "f", "g", "a", "b"];const tones = [260, 293, 329, 349, 392, 440, 493];// 0, 1, 2, 3, 4, 5, 6const sounds = {}; // starts empty...
function act({ event: e, sound, help }) { // ๐ฉ Array Iteration notes.forEach((note, index) => { if (e.is("keyboard:down:" + note) && e.repeat === false) { myNumber = tones[index]; // index will be 0, 1, 2, 3 const wavetype = help.choose("sine", "square", "triangle"); // ๐ฒ myOtherNumber = wavetype; sounds[note] = sound.synth({ type: wavetype, tone: myNumber, duration: Infinity }); // "sine", "square" (default), "triangle", "sawtooth", "noise-white" // { c: synth, a: synth, b: synth } }
if (e.is("keyboard:up:" + note)) { sounds[note]?.kill(0.2); } });
// if (e.is("keyboard:down:c") && e.repeat === false) { // myNumber = 260; // cSound = sound.synth({ tone: myNumber, duration: Infinity }); // }
// if (e.is("keyboard:up:c") && cSound) { // // Stop the sound.... // myNumber = 0; // cSound.kill(0.1); // Add an optional fade out duration... // cSound = undefined; // Clear out the reference. // }
// if (e.is("keyboard:down:d")) { // sound.synth({ tone: 293 }); // }
// if (e.is("keyboard:down:e")) { // sound.synth({ tone: 329 }); // }
// if (e.is("keyboard:down:f")) { // sound.synth({ tone: 349 }); // }
// if (e.is("keyboard:down:g")) { // sound.synth({ tone: 392 }); // }
// if (e.is("keyboard:down:a")) { // sound.synth({ tone: 440 }); // }
// if (e.is("keyboard:down:b")) { // sound.synth({ tone: 493 }); // }}
// ๐ Library
// function boot() {// Runs once at the start.// }
// function sim() {// // Runs once per logic frame. (120fps locked.)// }
// function beat() {// // Runs once per metronomic BPM.// }
// function leave() {// // Runs once before the piece is unloaded.// }
// function preview({ ink, wipe }) {// Render a custom thumbnail image.// }
// function icon() {// Render an application icon, aka favicon.// }
// โ ๏ธ Also available: `brush` and `filter`.