connect-lights.js

total 0
used 0
limit 0
/* title: Most Minimal Example categories: minimal files: head point pointlist ../point_src/events.js mouse stage dragging stroke ../point_src/random.js ../point_src/rectangle.js --- The minimal requirements include the _head_, _stage_, and the _point_. */ class MainStage extends Stage { canvas = 'playspace' constantClick = true mounted() { this.points = PointList.generate.random(8, new Point(500, 500, 30), new Point(100, 100)) this.points = PointList.generate.grid(40, 7, 110) this.points.each.radius = ()=> random.int(5,15) // this.point = this.points[2].copy() // this.point.radius = 30 random.shuffle(this.points, 2) this.dragging.add(...this.points) this.action = 'connectStart' this.connections = {} } onclick(ev) { console.log('click', this.dragging._near) this[this.action](ev, this.dragging._near) } connectStart(ev, p) { if(p == undefined) { return } this.start = p this.action = 'connectEnd' console.log('started') } connectEnd(ev, p) { if(p == undefined) { return } if(p == this.start) { // turn off this.start = undefined this.action = 'connectStart' return } let uuid1 = this.start.uuid let uuid2 = p.uuid console.log('stopped') let name = `${uuid1}-${uuid2}` if(this.connections[name] == undefined){ // create this.connections[name] = [] console.log('Creating') } this.connections[name].push([this.start, p]) this.start = undefined this.action = 'connectStart' if(this.constantClick) { this.start = p this.action = 'connectEnd' } } draw(ctx){ this.clear(ctx) // this.points.pen.rect(ctx,{width: 4, color: '#444'}) for(let k in this.connections) { this.connections[k].forEach(v=>{ v[0].pen.line(ctx, v[1], '#888', 3) }) } this.points.pen.fill(ctx, {color:'purple'}) if(this.action == 'connectEnd') { this.start.pen.line(ctx, this.mouse.point, '#888', 3) } if(this.start) { this.start.pen.fill(ctx, {color:'green'}) } } } stage = MainStage.go(/*{ loop: true }*/)
Run
Meta Data
title Most Minimal Example
imports ()
files ('head', 'point', 'pointlist', '../point_src/events.js', 'mouse', 'stage', 'dragging', 'stroke', '../point_src/random.js', '../point_src/rectangle.js')
unused_keys ()
unknown_keys ('categories',)
categories ['minimal']
filepath_exists True
path connect-lights.js
filepath connect-lights.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/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/rectangle.js')
markdown {'html': '<p>The minimal requirements include the <em>head</em>, <em>stage</em>, and the <em>point</em>.</p>', 'content': 'title: Most Minimal Example\ncategories: minimal\nfiles:\n head\n point\n pointlist\n ../point_src/events.js\n mouse\n stage\n dragging\n stroke\n ../point_src/random.js\n ../point_src/rectangle.js\n---\n\nThe minimal requirements include the _head_, _stage_, and the _point_.'}