windings-example-raw.js

total 0
used 0
limit 0
/* categories: angles files: head stroke ../point_src/point-content.js pointlist point mouse ../point_src/bisector.js ../point_src/random.js dragging ../point_src/l.js ../point_src/protractor.js ../point_src/text/beta.js stage --- Calculate _windings_ of a point. Detect the point rotation and diff against the previous value. The value is independant of the point and accounts for rotation through the 0 degree, and the _initial_ rotation of the point. */ addWidget('diff', { fields: { diff: { value: 0 } , total: { value: 0 } , total_mod: { value: 0 } } }) function calculateAngleDiffWrapped(primaryPoint, secondaryPoint) { let rads = radiansDiff2(primaryPoint.radians, secondaryPoint.radians); return radiansToDegrees(rads); } function radiansDiff2(primaryRads, secondaryRads) { let diff = (primaryRads - secondaryRads + Math.PI) % (Math.PI * 2) - Math.PI; if (diff < -Math.PI) diff += Math.PI * 2; return diff; } class MainStage extends Stage { canvas='playspace' // live=false live = true mounted(){ console.log('drag-point') this.spot = this.center.copy() this.spot.radius = 300 this.spot.rotation = random.int(360) this.dragging.addPoints(this.spot) this.total = 0 this.last_rot = 0 } firstDraw(ctx) { ctx.strokeStyle = 'yellow' ctx.fillStyle = '#EEE' ctx.font = `400 16px inter`; ctx.textAlign = 'center' ctx.textBaseline = 'middle' } draw(ctx){ this.clear(ctx) // this.fps.drawFPS(ctx) this.updateRadians() this.drawCircles(ctx) ctx.fillStyle = '#EEE' this.drawIris(ctx) } updateRadians() { let last_radians = this.last_radians if(last_radians == undefined) { last_radians = this.spot.radians }; let rotW = calculateAngleDiffWrapped({radians:last_radians}, this.spot) let rot = calculateAngleDiff({radians:last_radians}, this.spot) if(rot != this.last_rot) { // console.log(rot, rotW) let diff = (this.last_rot - rot) if (diff < -180 || diff > 180) { // skip it. diff = ((this.last_rot - 360) % 360 ) + rot } else { this.total += diff; // console.log(diff) updateWidgetValues('diff', { diff: diff.toFixed(2) , total: this.total.toFixed(0) , total_mod: (this.total % 360).toFixed(0) }) } } this.last_rot = rot this.last_radians = last_radians } drawCircles(ctx) { this.spot.pen.fill(ctx, '#333') this.spot.pen.indicator(ctx, { color: '#111'}) } drawIris(ctx) { /* The dynamic highlighter. */ this.dragging.drawAll(ctx) } } ;stage = MainStage.go();
Run
Meta Data
imports ()
files ('head', 'stroke', '../point_src/point-content.js', 'pointlist', 'point', 'mouse', '../point_src/bisector.js', '../point_src/random.js', 'dragging', '../point_src/l.js', '../point_src/protractor.js', '../point_src/text/beta.js', 'stage')
unused_keys ('title',)
unknown_keys ('categories',)
categories ['', 'angles']
filepath_exists True
path windings-example-raw.js
filepath windings-example-raw.js
clean_files ('../point_src/core/head.js', '../point_src/setunset.js', '../point_src/stroke.js', '../point_src/compass.js', '../point_src/center.js', '../point_src/point-content.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/pointdraw.js', '../point_src/relative-xy.js', '../point_src/pointcast.js', '../point_src/point.js', '../point_src/events.js', '../point_src/automouse.js', '../point_src/bisector.js', '../point_src/random.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/l.js', '../point_src/stage-resize.js', '../point_src/functions/resolve.js', '../point_src/stage.js')
markdown {'html': '<hr />\n<p>Calculate <em>windings</em> of a point. Detect the point rotation and diff against\nthe previous value.</p>\n<p>The value is independant of the point and accounts for rotation through the\n0 degree, and the <em>initial</em> rotation of the point.</p>', 'content': 'categories:\n angles\nfiles:\n head\n stroke\n ../point_src/point-content.js\n pointlist\n point\n mouse\n ../point_src/bisector.js\n ../point_src/random.js\n dragging\n ../point_src/l.js\n ../point_src/protractor.js\n ../point_src/text/beta.js\n stage\n\n---\n\nCalculate _windings_ of a point. Detect the point rotation and diff against\nthe previous value.\n\nThe value is independant of the point and accounts for rotation through the\n0 degree, and the _initial_ rotation of the point.'}