gears-simple.js

total 0
used 0
limit 0
/* title: Gears (Nearly) categories: gears src_dir: ../point_src/ 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/point.js dragging pointlist mouse stroke ../point_src/split.js ../point_src/stage-clock.js ../point_src/touching.js --- A simple example of gear-like rotations */ function cv(circleA, circleB) { // circleA and circleB each have: // radius: number // angularVelocity: number (radians per second or degrees per second) // Angular velocity of B given A: circleB.angularVelocity = -(circleA.radius / circleB.radius) * circleA.angularVelocity; circleB.rotation += circleB.angularVelocity } const isMotor = function(point) { let mv = point.motor if(mv === undefined || mv === false) { return false } return true } class MainStage extends Stage { // canvas = document.getElementById('playspace'); canvas = 'playspace' mounted(){ this.rawPointConf = { circle: { color: 'orange', width: 1}} this.generate() this.dragging.add(...this.randomPoints) } generate(pointCount=2){ this.randomPoints = new PointList( new Point({x:300, y:200, radius: 70, motor: true, angularVelocity: 1}), new Point({x:500, y:200, radius: 150, angularVelocity: 0}), new Point({x:700, y:200, radius: 70, angularVelocity: 0}), new Point({x:800, y:300, radius: 70, angularVelocity: 0}), ) } draw(ctx){ this.clear(ctx) this.drawView(ctx) let ps = this.randomPoints ps.forEach(p=> { if(isMotor(p)) { p.rotation += p.motor } }) let prev = ps[0] for (let i = 1; i < ps.length; i++) { let p = ps[i] let distance = prev.distanceTo(p) - p.radius if(distance < prev.radius) { let ip = prev.copy().update({radius:distance}) ip.pen.circle(ctx, {color:'#444'}) } if(pointToPointContact(prev, p)) { let chained = cv(prev, p) prev = p } } let p = this.dragging.getPoint(); if(p) { p.pen.circle(ctx) } } drawView(ctx){ /* Draw a circle at the origin points */ let style = { color: "#333", line: {color: 'white'}} this.randomPoints.forEach((p)=> { p.split(~~(p.radius/5)).pen.indicators(ctx, style) }) this.randomPoints.pen.indicators(ctx, this.rawPointConf) // this.others.pen.indicators(ctx, this.rawPointConf) } } stage = MainStage.go()
Run
Meta Data
title Gears (Nearly)
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/point.js', 'dragging', 'pointlist', 'mouse', 'stroke', '../point_src/split.js', '../point_src/stage-clock.js', '../point_src/touching.js')
unused_keys ()
unknown_keys ('categories', 'src_dir')
categories ['gears']
src_dir ['../point_src/']
filepath_exists True
path gears-simple.js
filepath gears-simple.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/relative-xy.js', '../point_src/pointcast.js', '../point_src/point.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/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/setunset.js', '../point_src/stroke.js', '../point_src/split.js', '../point_src/stage-clock.js', '../point_src/touching.js')
markdown {'html': '<hr />\n<p>A simple example of gear-like rotations</p>', 'content': 'title: Gears (Nearly)\ncategories: gears\nsrc_dir: ../point_src/\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/point.js\n dragging\n pointlist\n mouse\n stroke\n ../point_src/split.js\n ../point_src/stage-clock.js\n ../point_src/touching.js\n\n---\n\nA simple example of gear-like rotations'}