brownian.js

total 0
used 0
limit 0
/* title: Brownian Position (Raw) categories: brownian raw files: head point stage --- This (raw) example shows a _random_ position but relative to a home location. Allowing a randomisation without drifting from a preferred point. */ class MainStage extends Stage { canvas = 'playspace' updateSpeed = 10 mounted(){ this.point = new Point(this.center) this.modu = 0 addControl('updateSpeed', { field: 'range' , label: 'update speed' , step: 1 , max: 200 , stage: this , onchange(ev) { /*slider changed. */ // debugger; let sval = ev.currentTarget.value this.stage.updateSpeed = parseInt(Math.sqrt(sval)*2) } }) } draw(ctx) { this.clear(ctx) this.modu += 1 this.modu % this.updateSpeed == 0 && this.updateWalker(1, .5) this.point.pen.fill(ctx, '#ddd') } updateWalker(limit=1, max=1) { let width = 1024 let height = 512 let margin = 10 let maxMove = width * 0.1 * max let x = width * .5 let y = height * .5 let precision = 0 let halfPi = Math.PI / 180 for (let i = 0; i < limit; i++) { let distance = Math.random() * maxMove let angle = Math.random() * 360 let tx = x + distance * Math.sin(halfPi * angle); let ty = y + distance * Math.cos(halfPi * angle); if( tx > margin && tx < (width - margin) && ty > margin && ty < (height - margin) ) { x = +tx.toFixed(precision) y = +ty.toFixed(precision) } } this.point.xy = [x,y] } } stage = MainStage.go(/*{ loop: true }*/)
Run
Meta Data
title Brownian Position (Raw)
imports ()
files ('head', 'point', 'stage')
unused_keys ()
unknown_keys ('categories',)
categories ['brownian', 'raw']
filepath_exists True
path brownian.js
filepath brownian.js
clean_files ('../point_src/core/head.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')
markdown {'html': '<p>This (raw) example shows a <em>random</em> position but relative to a home location.\nAllowing a randomisation without drifting from a preferred point.</p>', 'content': 'title: Brownian Position (Raw)\ncategories: brownian\n raw\nfiles:\n head\n point\n stage\n---\n\nThis (raw) example shows a _random_ position but relative to a home location.\nAllowing a randomisation without drifting from a preferred point.'}