multi-scale.js

total 0
used 0
limit 0
/* title: Multi-scale categories: scaling files: ../point_src/core/head.js ../point_src/pointpen.js ../point_src/pointdraw.js ../point_src/setunset.js ../point_src/stroke.js ../point_src/point-content.js ../point_src/pointlistpen.js ../point_src/pointlist.js ../point_src/point.js ../point_src/events.js ../point_src/automouse.js ../point_src/distances.js ../point_src/bisector.js ../point_src/dragging.js ../point_src/functions/clamp.js ../point_src/stage.js --- Multiscale assigns a map of relative sizes. Upon `update` the points are tested for their expected size. If the current size does not match the expected, a rescale of all points is performed. alpha: 1 , beta: 2 , charlie: 3 , delta: 8 , echo: 1.2 */ const ratios = { alpha: 1 , beta: 2 , charlie: 3 , delta: 8 , echo: 1.2 } class RatioMachine { constructor(points) { this.expected = {} this.points = points } update(points=this.points) { let ms = new Set() for(let p of points) { let expected = this.getExpected(p) if(p.radius != expected) { console.log('mismatch on', p.uuid) ms.add(p) } } if(ms.size > 1) { console.warn('size mismatch') } this.updateRatio(...ms) } updateRatio(...ms) { // Update the ratio given the // value of init P. let p = ms[0] if(p == undefined) {return} let ratio = p._ratioName let expected = ratios[ratio] let newBase = p.radius * .2 let mul = newBase / expected console.log(ratio, newBase, expected, mul) let i = 0 for(let name in ratios) { let value = ratios[name]; let p = this.points[i] this.expected[p.uuid] = p.radius = (value * mul) * 5 p._ratioName = name i++ } } getExpected(p) { return this.expected[p.uuid] } setRatios(ratios){ let i = 0 for(let name in ratios) { let value = ratios[name]; let p = this.points[i] this.expected[p.uuid] = p.radius = value * 5 p._ratioName = name i++ } } } class MainStage extends Stage { canvas='playspace' // live=false live = true mounted(){ let stage = this addButton('update', { onclick(){ stage.rm.update() } }) this.plotRadi() // this.points = PointList.generate.random(Object.values(ratios).length, 500) this.dragging.add(...this.points) this.clones = this.points.copy(true) // deep } plotRadi(){ // this.points = PointList.generate.random(Object.values(ratios).length, 500) this.points = PointList.generate.list(Object.values(ratios).length, 150, [100,100]) this.rm = new RatioMachine(this.points) this.rm.setRatios(ratios) } draw(ctx){ this.clear(ctx) this.clones.pen.indicators(ctx, {color: '#555'}) this.points.pen.indicators(ctx) } } ; stage = MainStage.go();
Run
Meta Data
title Multi-scale
imports ()
files ('../point_src/core/head.js', '../point_src/pointpen.js', '../point_src/pointdraw.js', '../point_src/setunset.js', '../point_src/stroke.js', '../point_src/point-content.js', '../point_src/pointlistpen.js', '../point_src/pointlist.js', '../point_src/point.js', '../point_src/events.js', '../point_src/automouse.js', '../point_src/distances.js', '../point_src/bisector.js', '../point_src/dragging.js', '../point_src/functions/clamp.js', '../point_src/stage.js')
unused_keys ()
unknown_keys ('categories',)
categories ['scaling']
filepath_exists True
path multi-scale.js
filepath multi-scale.js
clean_files ('../point_src/core/head.js', '../point_src/pointpen.js', '../point_src/pointdraw.js', '../point_src/setunset.js', '../point_src/stroke.js', '../point_src/compass.js', '../point_src/center.js', '../point_src/point-content.js', '../point_src/pointlistpen.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/relative-xy.js', '../point_src/pointcast.js', '../point_src/point.js', '../point_src/events.js', '../point_src/automouse.js', '../point_src/distances.js', '../point_src/bisector.js', '../point_src/protractor.js', '../point_src/text/beta.js', '../point_src/dragging.js', '../point_src/functions/clamp.js', '../point_src/stage-resize.js', '../point_src/functions/resolve.js', '../point_src/stage.js')
markdown {'html': '<p>Multiscale assigns a map of relative sizes. Upon <code>update</code> the points are tested\nfor their expected size. If the current size does not match the expected, a rescale\nof all points is performed.</p>\n<pre><code>alpha: 1\n, beta: 2\n, charlie: 3\n, delta: 8\n, echo: 1.2\n</code></pre>', 'content': 'title: Multi-scale\ncategories: scaling\nfiles:\n ../point_src/core/head.js\n ../point_src/pointpen.js\n ../point_src/pointdraw.js\n ../point_src/setunset.js\n ../point_src/stroke.js\n ../point_src/point-content.js\n ../point_src/pointlistpen.js\n ../point_src/pointlist.js\n ../point_src/point.js\n ../point_src/events.js\n ../point_src/automouse.js\n ../point_src/distances.js\n ../point_src/bisector.js\n ../point_src/dragging.js\n ../point_src/functions/clamp.js\n ../point_src/stage.js\n---\n\nMultiscale assigns a map of relative sizes. Upon `update` the points are tested\nfor their expected size. If the current size does not match the expected, a rescale\nof all points is performed.\n\n alpha: 1\n , beta: 2\n , charlie: 3\n , delta: 8\n , echo: 1.2'}