How to use the @mathigon/core.repeat2D function in @mathigon/core

To help you get started, we’ve selected a few @mathigon/core 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 / chaos / components / water-ripples.ts View on Github external
ready() {
    this.sx = +this.attr('width');
    this.sy = +this.attr('height') || this.sx;

    const r = +this.attr('resolution') || 2;
    this.rx = this.sx * r;
    this.ry = this.sy * r;

    this.$canvas =
        $N('canvas', {width: this.rx, height: this.ry}, this) as CanvasView;
    this.$canvas.css({width: this.sx + 'px', height: this.sy + 'px'});

    this.loadBackground(this.attr('src'));

    this.depthMap1 = repeat2D(0, this.sx, this.sy);
    this.depthMap2 = repeat2D(0, this.sx, this.sy);

    this.damping = +this.attr('damping') || 0.994;
    this.clipping = +this.attr('clipping') || 5;
    this.refraction = +this.attr('refraction') || 8;
    this.reflection = +this.attr('reflection') || 1;

    // The touch pattern is a 2D array containing numbers between -1 and 1.
    this.touchPattern = this.createDropPattern(this.touchSize * 2);

    slide(this.$canvas, {
      start: (p) => this.touchWater(p.scale(1 / r), 0.5),
      move: (p) => this.touchWater(p.scale(1 / r), 0.1)
    });
  }
github mathigon / textbooks / content / chaos / components / water-ripples.ts View on Github external
ready() {
    this.sx = +this.attr('width');
    this.sy = +this.attr('height') || this.sx;

    const r = +this.attr('resolution') || 2;
    this.rx = this.sx * r;
    this.ry = this.sy * r;

    this.$canvas =
        $N('canvas', {width: this.rx, height: this.ry}, this) as CanvasView;
    this.$canvas.css({width: this.sx + 'px', height: this.sy + 'px'});

    this.loadBackground(this.attr('src'));

    this.depthMap1 = repeat2D(0, this.sx, this.sy);
    this.depthMap2 = repeat2D(0, this.sx, this.sy);

    this.damping = +this.attr('damping') || 0.994;
    this.clipping = +this.attr('clipping') || 5;
    this.refraction = +this.attr('refraction') || 8;
    this.reflection = +this.attr('reflection') || 1;

    // The touch pattern is a 2D array containing numbers between -1 and 1.
    this.touchPattern = this.createDropPattern(this.touchSize * 2);

    slide(this.$canvas, {
      start: (p) => this.touchWater(p.scale(1 / r), 0.5),
      move: (p) => this.touchWater(p.scale(1 / r), 0.1)
    });
  }
github mathigon / textbooks / content / graph-theory / functions.ts View on Github external
function redraw() {
    if (points.length < 2) return $path.points = [];

    let matrix = repeat2D(0, points.length, points.length);
    for (let i = 0; i < points.length; ++i) {
      for (let j = 0; j < i; ++j) {
        matrix[i][j] = matrix[j][i] = Point.distance(points[i], points[j]);
      }
    }
    const tsm = travellingSalesman(matrix);
    $path.points = tsm.path!.map(i => points[i]);
  }
github mathigon / fermat.js / src / matrix.ts View on Github external
export function fill(value: number, x: number, y: number) {
    return repeat2D(value, x, y);
  }