-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support SVG <circle> #10
Comments
At this point, SVGs are fully converted to I will investigate on this. In the meantime, try to use Also note that the firmware is currently not able to draw real curves, and instead use a subset of straight lines. |
Also, note that like xy-plotter/ |
Thanks!
Good to know. Is that why circles (from the built-in API) are drawing quite slowly at the moment?
Great news! Is the new version going to support curves as well? |
I checked how other plotters deal with curve drawing, and the majority seems to use the same straight line curve approximation as the xy's firmware. That means that the next version will certainly use the same approach, and draw small straight lines instead of real curves. IMHO this isn't an issue, but the speed could be one. You could try setting manually the speed before calling a circle command : ...
job.setSpeed(0.8).circle(x, y, radius)
job.resetSpeed()
... Setting manually the speed will use a linear interpolation instead of the default eased one. |
Thanks for investigating this. I made some tests with different speeds but realized it made not much difference (see further down this post). Different numbers of sidesI then realized there is, of course, the option of setting the number of sides from default=100. 100 sides = 5s There is a lot of room for optimization it seems. I assume the number of sides should be optimized depending on the circle's size. I quickly looked into the Axidraw repo and found this:
Not sure, but aren't those paths curves or multiple straight lines as well? And in the wiki of StippleGen under "Saving a Stipple Drawing" it reads:
'Stipples' are actually circles. I wonder what sort of optimization they do? Maybe even drawing dots only if the circles are really small? Checking the corresponding repos might be worth it. Different speedsI've tried drawing a 2mm circle with the default 100 sides using Drawing a circle with 30 sides using eased speed or |
I have implemented this answer from Stack Overflow: How to render a circle with as few vertices as possible?
Tested with a few circles:
Gives:
At least the renderings seem to be okay. I'm not too sure about smaller circles in the physical drawing though. But this might be my pen holder, which is still not sitting super tight. I think as an improvement depending on the radius, for bigger circles the drawing speed could go up quite a bit. |
Your Eventually, it might be a good idea to implement in the firmware a real curve drawing, but I can't find any existing solution. I don't quite understand the approach used in the official axidraw repo you mentioned : they do convert I looked in Fogleman's version of axidraw, and it seems that he does draw the circle as straight lines too (axi/examples/circles.py#L5-L12). |
I'm glad if it helps.
In the official XY-Plotter-2.0 repo, there seems to be arc drawing in the firmware. But in the end, it's all resolved to linear movements, and it doesn't really matter if that happens in the firmware or the software, does it?
After converting to and before PlanTrajectory() there seems to be another conversion happening in here which "Turn[s] this path into a cubicsuperpath (list of beziers)". Not quite sure what that is though.
Indeed, that looks promising. Would be interesting to see the difference. |
According to svg/svgo#818 it requires svgo 1.0.0 to convert circles and ellipses to paths. This project currently uses svgo 0.7.0 Also not sure if it might be a problem that flatten transforms (groups) is not implemented in svgo yet. Maybe https://github.com/stadline/svg-flatten could help in the meantime? |
My example from the beginning of this thread works with const plotter = require('xy-plotter')()
const svgFlatten = require('svg-flatten')
const fs = require('fs');
let flattendSvgPath = 'tmp-flattened.svg'
// read SVG into string
let svgString = fs.readFileSync('circle-rect.svg', 'utf8')
// convert all objects to paths and write to disk
fs.writeFileSync(flattendSvgPath, svgFlatten(svgString).pathify().value());
const job = plotter.Job('svg')
job.svg(flattendSvgPath, {
x: 0, // x coordinate
y: 150, // y coordinate
width: 150, // custom width
height: 150, // custom height
// angle: 90, // angle in degrees
origin: [0, 1] // origin point of the transformation
})
const file = plotter.File()
file.export(job, path.join(__dirname, job.name + '.png')) But in the rendered PNG the circles have clearly visible vertices: The preview of I tried to use |
First of all, thanks a lot for creating this software!
I tried loading SVGs I created and exported from Affinity Designer. This is an example:
The SVG file: circle-rect.svg.zip
Unfortunately, it seems that circles are not going to be picked up. The plots and exported PNGs do not contain any circles. Rectangles show up though:
Loading this SVG heart icon worked as well:
https://thenounproject.com/search/?q=dsf&i=350276
Are there any certain specifications or limitations to the SVGs you can load?
Thanks!
The text was updated successfully, but these errors were encountered: