svg-example.js

total 0
used 0
limit 0
/* title: SVG Example categories: svg files: ../point_src/core/head.js ../point_src/pointpen.js ../point_src/pointdraw.js ../point_src/math.js ../point_src/extras.js ../point_src/point-content.js ../point_src/pointlist.js ../point_src/pointlistpen.js ../point_src/point.js ../point_src/stage.js mouse dragging stroke ../theatre/a.js --- */ var newSVG = function(id, parent) { let home = parent || 'body' //let $svg = $("", ) let $svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"); $svg.id = id $svg.setAttribute('height', 0) $svg.setAttribute('width', 0) // document.querySelector(home).appendChild($svg) return $svg; } let pathSetPathFunction = function(d) { /* Apply as `path.setPath` as a helper to set the `d` attribute of a Path node. */ this.setAttribute('d', d) return d } const newNode = function(type='path', id, p){ let nsUri = "http://www.w3.org/2000/svg" var $node = document.createElementNS(nsUri, type); //Create a path in SVG's namespace $node.id = id $node.setPath = pathSetPathFunction $node.setPath(getInitD(p)); //Set path's data $node.style.stroke = "#000"; //Set stroke colour $node.style.strokeWidth = "5px"; //Set stroke width return $node } const getInitD = function(p){ let width = p.radius , rad = width*2 , neg_rad = -rad // , a = this.coords.a , a = p ; let arc = commands.arc; // debugger; let b = [ `M ${a.x}, ${a.y}` , ` m -${width}, 0` , ` ${arc.rel} ${width}, ${width} 0 1, 0 ${rad}, 0` , ` ${arc.rel} ${width}, ${width} 0 1, 0 -${rad}, 0` ].join('') return b } class MainStage extends Stage { // canvas = document.getElementById('playspace'); canvas = 'playspace' mounted(){ this.point = new Point({x: 250, y: 150 , radius: 20, rotation: 45}) this.dragging.add(this.point) this.svg = newSVG('new-svg') this.svg.setAttribute('height', 300) this.svg.setAttribute('width', 400) this.canvas.parentElement.appendChild(this.svg) let path = newNode('path', 'foobar', this.point) this.svg.appendChild(path) } onMousedown(ev) { // this.iPoint.rotation = random.int(180) commands.move(...this.point.xy) } draw(ctx){ this.clear(ctx) this.point.pen.indicator(ctx) } } console.log('chord'); stage = MainStage.go(/*{ loop: true }*/)
Run
Meta Data
title SVG Example
imports ()
files ('../point_src/core/head.js', '../point_src/pointpen.js', '../point_src/pointdraw.js', '../point_src/math.js', '../point_src/extras.js', '../point_src/point-content.js', '../point_src/pointlist.js', '../point_src/pointlistpen.js', '../point_src/point.js', '../point_src/stage.js', 'mouse', 'dragging', 'stroke', '../theatre/a.js')
unused_keys ()
unknown_keys ('categories',)
categories ['svg']
filepath_exists True
path svg-example.js
filepath svg-example.js
clean_files ('../point_src/core/head.js', '../point_src/pointpen.js', '../point_src/pointdraw.js', '../point_src/math.js', '../point_src/extras.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/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', '../theatre/a.js')
markdown {'html': '', 'content': 'title: SVG Example\ncategories: svg\nfiles:\n ../point_src/core/head.js\n ../point_src/pointpen.js\n ../point_src/pointdraw.js\n ../point_src/math.js\n ../point_src/extras.js\n ../point_src/point-content.js\n ../point_src/pointlist.js\n ../point_src/pointlistpen.js\n ../point_src/point.js\n ../point_src/stage.js\n mouse\n dragging\n stroke\n ../theatre/a.js\n---'}