brownian-walker-raw.js

total 0
used 0
limit 0
/* title: Brownian Within a Point categories: brownian random files: head point stage mouse dragging stroke ../point_src/random.js ../point_src/relative.js --- A tiny walker to move towards a browian point. */ class MainStage extends Stage { canvas = 'playspace' updateSpeed = 50 lookSpeedUpdateSpeed = 10 touchSpaceUpdateSpeed = 10 forwardSpeed = 1 turnSpeed = .1 maxTouchDistance = 10 viewSpaceOffset = -20 viewSpaceMultiplerSize = 10 mounted(){ this.modu = 0 let bodySize = 5 this.point = this.center.copy().update({radius:bodySize, rotation: random.int(360)}) this.updateLookSpace() this.viewPoint = this.center.copy() this.updateWalker() this.dragging.add(this.point) } draw(ctx) { this.clear(ctx) this.updateAll() this.viewSpace.pen.circle(ctx, '#222255') this.viewPoint.pen.fill(ctx, 'red', 1) this.point.pen.indicator(ctx, '#ddd') } updateAll(){ this.modu += 1 this.modu % this.updateSpeed == 0 && this.updateWalker() this.modu % this.lookSpeedUpdateSpeed == 0 && this.updateLookSpace() this.modu % this.touchSpaceUpdateSpeed == 0 && this.updateTouchSpace() this.point.turnTo(this.viewPoint, this.turnSpeed) this.point.relative.forward(this.forwardSpeed) let didChange = this.screenWrap(this.point) if(didChange) { this.updateWalker(.5) } } screenWrap(p, topLeft=[100, 100], bottomRight=[400, 400]) { /* wrap */ let didChange = false; let px, opx = p.x let py, opy = p.y if(opx < topLeft[0]) { px = bottomRight[0] } if(opy < topLeft[1]) { py = bottomRight[1] } if(opx > bottomRight[0]) { px = topLeft[0] } if(opy > bottomRight[1]) { py = topLeft[1] } if(px != undefined) { p.x = px didChange = true } if(py != undefined) { p.y = py didChange = true } return didChange } updateTouchSpace(){ if(this.point.distanceTo(this.viewPoint) < this.maxTouchDistance) { this.updateWalker() } } updateLookSpace() { let eyeballSpace = this.viewSpaceOffset let viewSpaceSize = this.viewSpaceMultiplerSize let r = this.point.radius * viewSpaceSize this.viewSpace = this.point.project( r + this.point.radius + eyeballSpace ).update({radius: r}) } updateWalker(max=.5) { this.updateLookSpace() this.viewPoint.xy = random.within(this.viewSpace, max) } } stage = MainStage.go(/*{ loop: true }*/)
Run
Meta Data
title Brownian Within a Point
imports ()
files ('head', 'point', 'stage', 'mouse', 'dragging', 'stroke', '../point_src/random.js', '../point_src/relative.js')
unused_keys ()
unknown_keys ('categories',)
categories ['brownian', 'random']
filepath_exists True
path brownian-walker-raw.js
filepath brownian-walker-raw.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', '../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/setunset.js', '../point_src/stroke.js', '../point_src/random.js', '../point_src/relative.js')
markdown {'html': '<hr />\n<p>A tiny walker to move towards a browian point.</p>', 'content': 'title: Brownian Within a Point\ncategories: brownian\n random\nfiles:\n head\n point\n stage\n mouse\n dragging\n stroke\n ../point_src/random.js\n ../point_src/relative.js\n\n---\n\nA tiny walker to move towards a browian point.'}