within-polygon-test.js

total 0
used 0
limit 0
/* title: Polgon hit-test files: ../point_src/core/head.js ../point_src/pointpen.js ../point_src/pointdraw.js ../point_src/extras.js ../point_src/math.js ../point_src/point-content.js ../point_src/stage.js ../point_src/stagepen.js ../point_src/point.js ../point_src/distances.js ../point_src/pointlist.js ../point_src/pointlistpen.js ../point_src/events.js ../point_src/functions/clamp.js ../point_src/curve-extras.js ../point_src/random.js dragging ../point_src/setunset.js ../point_src/stroke.js ../point_src/functions/within.js ../point_src/automouse.js --- Click to draw connected lines (filling a `PointList`) Then check the mouse is within the drawn _polygon_ using the `withinPolygon` function */ addButton('Toggle Line', { onclick() { stage.drawLine = !stage.drawLine } }) addButton('Toggle Fill', { onclick() { stage.fillPolygon = !stage.fillPolygon } }) class MainStage extends Stage { // canvas = document.getElementById('playspace'); canvas = 'playspace' mounted(){ this.drawn = [] // this.events.wake() this.stroke = new Stroke({ color: '#b32bb6' , width: 2 , dash: [7, 4] }) this.fillPolygon = true this.drawLine = false this.line = new PointList this.dragging.wake() } onEmptyDown(ev) { // onClick(ev, point) { // if(point == undefined) { console.log('Down') let np = Point.from(ev) this.line.push(np) this.dragging.add(np) // } } draw(ctx){ this.clear(ctx) this.stroke.set(ctx) let l = this.line; if(l) { let f = l.first() f && f.pen.circle(ctx) l.draw.line(ctx) } if(this.fillPolygon) { this.pen.fill(ctx, '#621763') } if(l && this.drawLine){ l.pen.line(ctx, '#b32bb6') l[0].pen.line(ctx, l.last(), '#b32bb6') } /* Start texting if we have enough points.*/ if(l?.length > 2) { let within = withinPolygon(this.mouse.point, l) if(within) { this.mouse.point.pen.fill(ctx, this.fillPolygon? 'purple': 'orange') } } else { if(l && (!this.drawLine)){ l.pen.line(ctx, '#555') } } l.pen.circle(ctx) this.stroke.unset(ctx) } } stage = MainStage.go()
Run
Meta Data
title Polgon hit-test
imports ()
files ('../point_src/core/head.js', '../point_src/pointpen.js', '../point_src/pointdraw.js', '../point_src/extras.js', '../point_src/math.js', '../point_src/point-content.js', '../point_src/stage.js', '../point_src/stagepen.js', '../point_src/point.js', '../point_src/distances.js', '../point_src/pointlist.js', '../point_src/pointlistpen.js', '../point_src/events.js', '../point_src/functions/clamp.js', '../point_src/curve-extras.js', '../point_src/random.js', 'dragging', '../point_src/setunset.js', '../point_src/stroke.js', '../point_src/functions/within.js', '../point_src/automouse.js')
unused_keys ()
unknown_keys ()
filepath_exists True
path within-polygon-test.js
filepath within-polygon-test.js
clean_files ('../point_src/core/head.js', '../point_src/pointpen.js', '../point_src/pointdraw.js', '../point_src/extras.js', '../point_src/math.js', '../point_src/compass.js', '../point_src/center.js', '../point_src/point-content.js', '../point_src/stage-resize.js', '../point_src/functions/resolve.js', '../point_src/stage.js', '../point_src/stagepen.js', '../point_src/relative-xy.js', '../point_src/pointcast.js', '../point_src/point.js', '../point_src/distances.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/functions/clamp.js', '../point_src/curve-extras.js', '../point_src/random.js', '../point_src/protractor.js', '../point_src/text/beta.js', '../point_src/dragging.js', '../point_src/setunset.js', '../point_src/stroke.js', '../point_src/functions/within.js', '../point_src/automouse.js')
markdown {'html': '<hr />\n<p>Click to draw connected lines (filling a <code>PointList</code>)\nThen check the mouse is within the drawn <em>polygon</em> using the <code>withinPolygon</code> function</p>', 'content': 'title: Polgon hit-test\nfiles:\n ../point_src/core/head.js\n ../point_src/pointpen.js\n ../point_src/pointdraw.js\n ../point_src/extras.js\n ../point_src/math.js\n ../point_src/point-content.js\n ../point_src/stage.js\n ../point_src/stagepen.js\n ../point_src/point.js\n ../point_src/distances.js\n ../point_src/pointlist.js\n ../point_src/pointlistpen.js\n ../point_src/events.js\n ../point_src/functions/clamp.js\n ../point_src/curve-extras.js\n ../point_src/random.js\n dragging\n ../point_src/setunset.js\n ../point_src/stroke.js\n ../point_src/functions/within.js\n ../point_src/automouse.js\n\n---\n\nClick to draw connected lines (filling a `PointList`)\nThen check the mouse is within the drawn _polygon_ using the `withinPolygon` function'}