How to use the @mathigon/boost.$ 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.ts View on Github external
map.addPoint(p);
      map.stop();
      map.p = undefined;
      $ut.effect('pulse-down');
      if (startUtility.data.type === dataType) {
        last(map.paths).css('stroke', '#C00');
        errors.push(last(map.paths));
        if (dataType === 'house') {
          $section.addHint('housesToEachOther');
        } else {
          $section.addHint('factoriesToEachOther');
        }
      } else {
        let sector = (startUtility.data.type === 'house') ?
                     $('.' + $ut.data.utility, currentUtility)! :
                     $('.' + currentUtility.data.utility, $ut)!;
        sector.css('opacity', 1);
        sectors.set(last(map.paths), sector);
      }
      // TODO Error on connect twice
    });
  }
github mathigon / textbooks / content / graph-theory / functions.ts View on Github external
if (!map.drawing || currentUtility === $ut) return;
      map.addPoint(p);
      map.stop();
      map.p = undefined;
      $ut.effect('pulse-down');
      if (startUtility.data.type === dataType) {
        last(map.paths).css('stroke', '#C00');
        errors.push(last(map.paths));
        if (dataType === 'house') {
          $section.addHint('housesToEachOther');
        } else {
          $section.addHint('factoriesToEachOther');
        }
      } else {
        let sector = (startUtility.data.type === 'house') ?
                     $('.' + $ut.data.utility, currentUtility)! :
                     $('.' + currentUtility.data.utility, $ut)!;
        sector.css('opacity', 1);
        sectors.set(last(map.paths), sector);
      }
      // TODO Error on connect twice
    });
  }
github mathigon / textbooks / probability / functions.js View on Github external
function rollDice() {
    let d = $section.model.d;
    let x = random.weighted(probabilities[d]);

    scores[x] += 1;
    let maxScore = Math.max(...scores);

    for(let i = d; i <= 6 * d; ++i) {
      $('#dc1'+i).text = scores[i];
      $('#dc2'+i).css('height', (scores[i]/maxScore*95)+'%');
    }
  }
github mathigon / textbooks / content / graph-theory / functions.js View on Github external
$section.$$('.tab').forEach(($el, i) => {
    const $svg = $el.$('svg.frame');
    const $paths = $('.paths', $svg);
    const $water = $('.water', $svg);
    const $bridges = $$('.bridge', $svg);
    const $error = $('.error', $svg);
    const $solveds = $section.$$('x-solved');

    let success = false;
    let attempts = 0;
    let totalCrossed = 0;

    $error.hide();

    let map = new Sketch($svg, { paths: $paths });
    map.on('start', () => {
      map.clear();
      attempts += 1;
    });
github mathigon / textbooks / content / graph-theory / functions.ts View on Github external
export function utilities($section: Step) {
  let currentUtility: SVGView;
  let startUtility: SVGView;
  let errors: SVGView[] = [];

  const $svg = $('#map-utilities') as SVGParentView;
  const map = new Sketch($svg, {
    noStart: true,
    paths: $('#utility-paths') as SVGView,
    intersect: true
  });

  let attempts = 0;

  function resolve(hint?: string) {
    attempts += 1;
    if (attempts === 3) {
      $section.score('try-three-times');
      $section.addHint('utilitiesImpossible');
    } else if (hint) {
      $section.addHint(hint);
    }
  }

  setTimeout(() => {
github mathigon / textbooks / content / shared / components / code-editor.js View on Github external
function loadCSS(href) {
  if (PROMISES[href]) return;
  PROMISES[href] = Promise.resolve();
  $N('link', {rel: 'stylesheet', type: 'text/css', href}, $(document.head));
}
github mathigon / textbooks / content / graph-theory / functions.ts View on Github external
export function bridges1($section: Step) {
  let $svg = $section.$('svg');

  let $water = $('.water', $svg)!;
  let $bg = $('.background', $svg)!;
  let $bridges = $$('.bridge', $svg);

  let $edges = $$('.edge', $svg);
  let $vertices = $$('.vertex', $svg);
  let $trace = $('.trace', $svg)!;

  $edges.forEach($e => { $e.hide(); });
  $vertices.forEach($e => { $e.hide(); });
  $trace.hide();

  $section.onScore('blank-0', () => {
    $vertices.forEach($v => $v.enter('pop', 400));
  });

  $section.onScore('blank-1', () => {
github mathigon / textbooks / content / graph-theory / functions.js View on Github external
$section.$$('.tab').forEach(($el, i) => {
    const $svg = $el.$('svg.frame');
    const $paths = $('.paths', $svg);
    const $water = $('.water', $svg);
    const $bridges = $$('.bridge', $svg);
    const $error = $('.error', $svg);
    const $solveds = $section.$$('x-solved');

    let success = false;
    let attempts = 0;
    let totalCrossed = 0;

    $error.hide();

    let map = new Sketch($svg, { paths: $paths });
    map.on('start', () => {
      map.clear();
      attempts += 1;
    });
github mathigon / textbooks / content / graph-theory / functions.ts View on Github external
export function bridges4($section: Step) {
  const $svg = $('svg', $section)!;
  const $g = $('g', $section)!;
  const $edges = $$('line', $svg);
  const $vertex = $('circle', $svg)!;
  const $text = $('text', $svg)!;
  const $trace = $('path', $svg)!;
  const $slideshow = $section.$('x-slideshow')!;

  for (let i = 0; i < 6; ++i) $edges[i].hide();
  $trace.hide();

  $slideshow.on('next', async (x: number) => {
    if (x < 4) {
      await $edges[2 * x - 2].enter('draw', 600).promise;
      $text.textStr = 2 * x - 1;
      $vertex.css('fill', RED);
      await $edges[2 * x - 1].enter('draw', 600).promise;
      $text.textStr = 2 * x;
      $vertex.css('fill', GREEN);

    } else if (x === 5) {
github mathigon / textbooks / content / graph-theory / functions.js View on Github external
export function bridges4($section) {
  let $svg    = $('svg', $section);
  let $g      = $('g', $section);
  let $edges  = $$('line', $svg);
  let $vertex = $('circle', $svg);
  let $text   = $('text', $svg);
  let $trace  = $('path', $svg);

  for (let i=0; i<6; ++i) $edges[i].hide();
  $trace.hide();

  $section.$slides.on('next', function(x) {
    if (x < 4) {
      $edges[2 * x - 2].enter('draw', 600).then(function() {
        $text.text = 2 * x - 1;
        $vertex.css('fill', RED);
      }).then(function() {
        return $edges[2 * x - 1].enter('draw', 600)
      }).then(function() {