Created
November 16, 2019 05:03
-
-
Save Iheartweb/d34ad687cd6e96cde93a6f0355679a6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require("fs"); | |
| const utils = require("./utils"); | |
| const settings = require("./settings"); | |
| const [...fibonacciNumbers] = utils.fibonacci(30); | |
| const phi = (1 + Math.sqrt(5)) / 2; | |
| let frame = 0; | |
| const height = settings.canvas.height * 25.4; | |
| const width = settings.canvas.width * 25.4; | |
| const maxLength = fibonacciNumbers[settings.max]; | |
| const minLength = fibonacciNumbers[settings.min]; | |
| function calulateDestination(origin, length, angle) { | |
| const destination = utils.circumferencePoint(length / 2, angle, | |
| origin); | |
| if (destination[0] < 0) { | |
| return origin; | |
| } | |
| if (destination[0] > width) { | |
| return origin; | |
| } | |
| if (destination[1] < 0) { | |
| return origin; | |
| } | |
| if (destination[1] > height) { | |
| return origin; | |
| } | |
| return destination; | |
| } | |
| let points = [[0, 965.2]]; | |
| function calculateAngle(frame) { | |
| const v = Math.random() * settings.variance; | |
| return frame % 360 - v; | |
| } | |
| function calculateLength(frane) { | |
| const position = frame % (settings.max - settings.min) + settings.min; | |
| return fibonacciNumbers[position]; | |
| } | |
| function next(point) { | |
| const angle = calculateAngle(frame); | |
| const length = calculateLength(frame); | |
| const destination = calulateDestination(point, length, angle); | |
| return destination; | |
| } | |
| while (frame < settings.lines) { | |
| const nextPoint = next(points[frame]); | |
| points.push([nextPoint[0], nextPoint[1]]); | |
| frame += 1; | |
| } | |
| // Line Number | |
| function N() { | |
| const number = frame * settings.file.skip; | |
| frame += 1; | |
| return number < 10 ? `N0${number}` : `N${number}`; | |
| } | |
| const stream = fs.createWriteStream("testprogram.txt"); | |
| stream.once('open', () => { | |
| // begin | |
| // Signals start of data during file transfer. | |
| stream.write(`%\n`); | |
| // G01 Linear interpolation | |
| // G21 Programming in millimeters (mm) | |
| // stream.write(`${N()} G90 G01 G21 F10\n`); | |
| stream.write(`${N()} G90 G01 F10\n`); | |
| // S0 Spindle speed | |
| stream.write(`${N()} S0\n`); | |
| // position | |
| points.forEach(point => { | |
| stream.write(`${N()} X${point[0] / 25.4} Y${point[1] / 25.4} Z0\n`); | |
| }); | |
| // end | |
| // MO2 End program | |
| stream.write("M02\n"); | |
| stream.end(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment