hvianna/audioMotion-analyzer

Issues with registerGradient()

Closed this issue · 2 comments

I would love to add a custom gradient that is grayscale to my project, but when i try to call "audioMotion.registerGradient('test' {...options etc}) on my projects page and then run it, i get an AudioMotionError about "Unknown gradient: 'test'". Is there anything i have to look out for to make audioMotion recognize a gradient, or are there any examples of people implementing their own gradients? Of course i could just put the whole audioMotion-anayzer.js into my src/ folder, edit that, and then import it from there, but i would like to set the gradient in my script. I would appreciate any help :)

It looks like you're trying to set the gradient before registering it.

Try this:

import AudioMotionAnalyzer from 'https://cdn.skypack.dev/audiomotion-analyzer?min';

const audioMotion = new AudioMotionAnalyzer(
  document.getElementById('container'),
  {
    source: document.getElementById('audio'),
    mode: 3,
  }
);

audioMotion.registerGradient( 'grayscale', {
  colorStops: [ '#fff', '#000' ]
});

audioMotion.gradient = 'grayscale';

Moving this to Discussions...