Skip to content

A short brain.js workshop, where you can play with ml, colors and midi in the browser

Notifications You must be signed in to change notification settings

torgeir/brainjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

brainjs workshop

Intro

Task suggestions

  • Task-1.js: Change the neural net to prefer red and green colors
  • Task-1.js: Extend the network to handle 3 colors, remember to add the third preferred color to score()
  • Task-2.js: Write a lstm neural network to forecast sequences of notes, based on midi input
  • Task-3.js: Given the set of palettes in colors.js, use brain.js to generate new, pretty palettes

Tips

Pretty color palettes available

palettes.slice(0, 2)
[[
  [249,193,206],
  [253,212,189],
  [120,205,208]],
 [
  [249,193,206],
  [165,200,209],
  [0,147,165]]]

Play midi in the browser

You can play notes using Tone.js, e.g. like

let synth = new Tone.Synth().toMaster();

let toNote = midiValue => Tone.Frequency(midiValue, "midi").toNote()

function play () {
  const startOfFurElise = [76, 75, 76, 75, 76]; // next is 71
  startOfFurElise
    .map(toNote)
    .forEach((note, i) => {
      console.log(note);
      synth.triggerAttackRelease(note, "8n", Tone.context.currentTime + i * 0.5);
    });
}

document.addEventListener('click', play);

p5.js is available

new p5(function (p) {

  p.setup = function () {
    p.createCanvas(100, 100);
    p.frameRate(1)
  };

  p.draw = function () {
    p.fill(10, 10, Math.random() * 255)
    p.rect(0, 0, 100, 100)
  };
});

Resources

About

A short brain.js workshop, where you can play with ml, colors and midi in the browser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published