How to use the @mathigon/boost.Colour.rainbow function in @mathigon/boost

To help you get started, we’ve selected a few @mathigon/boost examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mathigon / textbooks / content / graph-theory / functions.js View on Github external
export function bridges3($section) {
  let g = GREEN, r = RED, b = BLUE, o = ORANGE;
  let colours = {
    val: Colour.rainbow(8),
    eo: [g,r,g,r,g,r,g],
    prime: [g,g,r,g,r,g,r],
    size: [b,b,o,o,o,o,o]
  };

  let $circles = $section.$$('circle');

  function colour(x) {
    $circles.forEach(function($c) {
      let y = +$c.attr('data-value');
      $c.css('fill', colours[x][y-2]);  // -2 because no 0s and 1s
    });
    if (x === 'eo') $section.score('dropdown');
  }

  $section.$('select').change(colour);
github mathigon / textbooks / content / graph-theory / functions.js View on Github external
$step.model.set('handshakeTable', function(n) {
    let colours = Colour.rainbow($step.model.n);

    function makePerson(x, y) {
      let newX= (x>=y ? x+1 : x);
      return ['<span style="background: ',
        colours[y], '" class="person">', y+1, '</span> + <span style="background: ', colours[newX],
        '" class="person">', newX + 1, '</span>'].join('');
    }

    return '' +
      tabulate(makePerson, n-1, n).map(x =&gt; `${ x.join('') }`).join('') +
      '<table class="handshakes grid"><tbody><tr></tr></tbody></table>';
  });
}