Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mods
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
mods
Commits
ea973abd
You need to sign in or sign up before continuing.
Commit
ea973abd
authored
3 years ago
by
Shawn Liu
Browse files
Options
Downloads
Patches
Plain Diff
path to hpgl module
parent
342e20a5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/path/formats/hpgl
+117
-0
117 additions, 0 deletions
modules/path/formats/hpgl
with
117 additions
and
0 deletions
modules/path/formats/hpgl
0 → 100644
+
117
−
0
View file @
ea973abd
//
// path to HPGL
//
// Neil Gershenfeld
// (c) Massachusetts Institute of Technology 2021
//
// This work may be reproduced, modified, distributed, performed, and
// displayed for any purpose, but must acknowledge the mods
// project. Copyright is retained and must be preserved. The work is
// provided as is; no warranty is provided, and users accept all
// liability.
//
// closure
//
(function(){
//
// module globals
//
var mod = {}
//
// name
//
var name = 'path to HPGL (unfinished)'
//
// initialization
//
var init = function() {
}
//
// inputs
//
var inputs = {
toolpath:{type:'object',
event:function(evt){
mod.name = evt.detail.name
mod.path = evt.detail.path
mod.dpi = evt.detail.dpi
mod.width = evt.detail.width
mod.height = evt.detail.height
make_path()
}}}
//
// outputs
//
var outputs = {
file:{type:'object',
event:function(str){
obj = {}
obj.name = mod.name+".hpgl"
obj.contents = str
mods.output(mod,'file',obj)
}}}
//
// interface
//
var interface = function(div){
mod.div = div
//
// display file name
//
div.appendChild(document.createTextNode(mod.name + '.hpgl'))
div.appendChild(document.createElement('br'))
}
//
// local functions
//
function make_path() {
var units = 25.4/0.025
var dx = units*mod.width/mod.dpi
var nx = mod.width
var scale = dx/(nx-1)
str = "IN;SP1;"
//
// follow segments
//
for (var seg = 0; seg < mod.path.length; ++seg) {
//
// Pen up
//
x = Math.round(scale * mod.path[seg][0][0])
y = Math.round(scale * mod.path[seg][0][1])
str += "PU" + x + "," + y + ";PD"
//
// Pen down
//
for (var pt = 1; pt < mod.path[seg].length; ++pt) {
//
// move to next point
//
x = Math.round(scale * mod.path[seg][pt][0])
y = Math.round(scale * mod.path[seg][pt][1])
str += x + "," + y
pt < (mod.path[seg].length - 1) ? str += "," : str += ";"
}
}
//Move to origin
str += "PU0,0;SP0;IN;"
//
// output file
//
outputs.file.event(str)
}
//
// return values
//
return ({
mod:mod,
name:name,
init:init,
inputs:inputs,
outputs:outputs,
interface:interface
})
}())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment