click-create-line-length-present-2.js

total 0
used 0
limit 0
/* --- title: Line Length files: head point pointlist mouse stage stroke dragging ../point_src/random.js ../point_src/stage-clock.js ../point_src/easing.js ../point_src/functions/quantize.js ../point_src/iter/lerp.js ../point_src/text/beta.js ../point_src/arc.js Click-hold to draw a line. Apply the length as a label orientated along the line. --- */ class MainStage extends Stage { canvas='playspace' // live=false mounted(){ this.drawing = false; this.startPoint = undefined this.line = [] } onMousedown(e){ /* Grab Point Animate To size. Then the new background color, */ this.drawing = true this.startPoint = Point.from(e).quantize(20) } onMouseup(ev) { this.drawing = false this.upPoint = Point.from(ev).quantize(20) this.line = [this.startPoint, this.upPoint] } switchOut() { console.log('doneHandler') let p = this.p this.v = undefined; } firstDraw(ctx) { ctx.fillStyle = '#ccc' ctx.font = 'normal 1em arial' } step(ctx){ if(!this.drawing) { return } let a = this.startPoint.quantize(20) let b = this.mouse.point.quantize(20) a.pen.line(ctx, b) } draw(ctx){ this.clear(ctx) this.step(ctx) if(this.line.length==2) { this.stageB(ctx) } return this.stageA(ctx) } stageA(ctx) { let a = this.startPoint let b = this.mouse.point.quantize(20) if(this.line.length > 0 && !this.drawing){ a = this.line[0] b = this.line[1] } if(a) { a.pen.line(ctx, b, 'red') a.pen.fill(ctx) b.pen.fill(ctx) let dis = a.distanceTo(b).toFixed(2) let tp = a.midpoint(b) tp.lookAt(b) tp.text.label(ctx, dis, {y:-10, x: 0}) } } stageB(ctx) { let a = this.startPoint let b = this.line[1] let mousePoint = this.mouse.point.quantize(20) a.pen.line(ctx, mousePoint, 'orange') mousePoint.pen.fill(ctx) let arcPlot = arcFromTo(a, b, mousePoint) arcPlot.point.radius = quantizeNumber(a.distanceTo(mousePoint) * .5, 2) penArcPlot(arcPlot, ctx, 'orange') /* Get the arc angle drawn */ let deg = getArcPlotAngle(arcPlot) /* Write the degrees at the center. */ arcPlot.point.text.string(ctx, ~~deg) } } ;stage = MainStage.go();
Run
Meta Data
title Line Length
imports ()
files ('head', 'point', 'pointlist', 'mouse', 'stage', 'stroke', 'dragging', '../point_src/random.js', '../point_src/stage-clock.js', '../point_src/easing.js', '../point_src/functions/quantize.js', '../point_src/iter/lerp.js', '../point_src/text/beta.js', '../point_src/arc.js')
unused_keys ()
unknown_keys ()
filepath_exists True
path click-create-line-length-present-2.js
filepath click-create-line-length-present-2.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/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/events.js', '../point_src/automouse.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/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/stage-clock.js', '../point_src/easing.js', '../point_src/functions/quantize.js', '../point_src/iter/lerp.js', '../point_src/arc.js')
markdown {'html': '<p>Click-hold to draw a line. Apply the length as a label orientated along the line.</p>\n<hr />', 'content': '---\ntitle: Line Length\nfiles:\n head\n point\n pointlist\n mouse\n stage\n stroke\n dragging\n ../point_src/random.js\n ../point_src/stage-clock.js\n ../point_src/easing.js\n ../point_src/functions/quantize.js\n ../point_src/iter/lerp.js\n ../point_src/text/beta.js\n ../point_src/arc.js\n\n\nClick-hold to draw a line. Apply the length as a label orientated along the line.\n\n---'}