lerp-map-1.js

total 0
used 0
limit 0
/* title: Lerp Mapping. categories: lerp files: head pointlist point stage stroke mouse dragging ../point_src/random.js ../point_src/easing.js ../point_src/iter/lerp.js --- An example of _pure lerp mapping_ without any polypoint Lerp tools. The `StaticLerpMap` hosts its own set of values for all points. */ class LerpMap { constructor(conf) { this.conf = conf } start() { /* A _wake_ with a begin. allowing _Step_ to function */ } step() { /* iter all points in A, lerping B. */ } } class StaticLerpMap extends LerpMap { start() { /* Copy to the largest. */ let a = this.conf.start let b = this.conf.end let m = Math.max(this.conf.start.length, b.length) // this.lerps = new Array(m) this.lerps = Array.from({length:m}, (u,i) => { return { _from: a[i] , _to: b[i] , x: { _from: a[i].x, _to: b[i].x, step: 0 } , y: { _from: a[i].y, _to: b[i].y, step: 0 } , radius: { _from: a[i].radius, _to: b[i].radius, step: 0 } } }) // console.log(this.lerps) this.seconds = 5 this.currentTime = 0 } step() { let spl = 1 / (60 * this.seconds) this.currentTime += spl this.lerps.forEach((o, i)=>{ o.x.step = this.currentTime o.y.step = this.currentTime o.radius.step = this.currentTime }) } } /* A static lerp stores a _Value_ for all vars. */ class MainStage extends Stage { canvas='playspace' mounted(){ let count = 30 this.a = PointList.generate.random(count, [300,300, 10, 0], [100, 100, 1, 1]) this.b = PointList.generate.random(count, [400,400, 10, 0], [400, 100, 1, 1]) this.c = PointList.generate.random(count) let lm = this.lerpMap = new StaticLerpMap({ start: this.a , end: this.b }) lm.start() } draw(ctx) { this.clear(ctx) this.b.pen.fill(ctx, 'purple') this.a.pen.fill(ctx, 'green') this.lerpMap.step() const lerps = this.lerpMap.lerps let commonVal = new Value() commonVal.doneStop = true commonVal.setEasing(quarticEaseInOut) // let pa = this.a // let pb = this.b this.c.forEach((p,i)=>{ let l = lerps[i] // let a = pa[i] // let b = pb[i] p.x = commonVal.pluck(l.x._from, l.x._to, l.x.step ) p.y = commonVal.pluck(l.y._from, l.y._to, l.y.step ) p.radius = commonVal.pluck(l.radius._from, l.radius._to, l.radius.step ) // p.x = commonVal.pluck(lx.a) // lx.step() }) this.c.pen.fill(ctx, '#ddd') } } ;stage = MainStage.go();
Run
Meta Data
title Lerp Mapping.
imports ()
files ('head', 'pointlist', 'point', 'stage', 'stroke', 'mouse', 'dragging', '../point_src/random.js', '../point_src/easing.js', '../point_src/iter/lerp.js')
unused_keys ()
unknown_keys ('categories',)
categories ['lerp']
filepath_exists True
path lerp-map-1.js
filepath lerp-map-1.js
clean_files ('../point_src/core/head.js', '../point_src/pointlistdraw.js', '../point_src/pointlistgradient.js', '../point_src/pointlistshape.js', '../point_src/pointlistgenerator.js', '../point_src/unpack.js', '../point_src/pointlist.js', '../point_src/pointlistpen.js', '../point_src/pointpen.js', '../point_src/compass.js', '../point_src/center.js', '../point_src/point-content.js', '../point_src/pointdraw.js', '../point_src/relative-xy.js', '../point_src/pointcast.js', '../point_src/point.js', '../point_src/stage-resize.js', '../point_src/functions/resolve.js', '../point_src/stage.js', '../point_src/setunset.js', '../point_src/stroke.js', '../point_src/events.js', '../point_src/automouse.js', '../point_src/functions/clamp.js', '../point_src/distances.js', '../point_src/protractor.js', '../point_src/text/beta.js', '../point_src/dragging.js', '../point_src/random.js', '../point_src/easing.js', '../point_src/iter/lerp.js')
markdown {'html': '<p>An example of <em>pure lerp mapping</em> without any polypoint Lerp tools.\nThe <code>StaticLerpMap</code> hosts its own set of values for all points.</p>', 'content': 'title: Lerp Mapping.\ncategories: lerp\nfiles:\n head\n pointlist\n point\n stage\n stroke\n mouse\n dragging\n ../point_src/random.js\n ../point_src/easing.js\n ../point_src/iter/lerp.js\n---\n\nAn example of _pure lerp mapping_ without any polypoint Lerp tools.\nThe `StaticLerpMap` hosts its own set of values for all points.'}