[ Launch: SVG Path Test 1 ] 4721138 by roundrobin[ Launch: SVG Path Element ] 4721053 by roundrobin[ Launch: Bootstrap Trib ] 4711978 by roundrobin[ Launch: Tributary inlet ] 4711690 by roundrobin
[ Launch: Variable Stroke width ] 4721145 by roundrobin[ Launch: SVG Path Test 1 ] 4721138 by roundrobin[ Launch: SVG Path Element ] 4721053 by roundrobin[ Launch: Bootstrap Trib ] 4711978 by roundrobin[ Launch: Tributary inlet ] 4711690 by roundrobin
[ Launch: PathLib & Pattern ] 4749218 by roundrobin[ Launch: Variable Stroke width ] 4735469 by roundrobin[ Launch: SVG Path Test 1 ] 4721138 by roundrobin[ Launch: SVG Path Element ] 4721053 by roundrobin[ Launch: Bootstrap Trib ] 4711978 by roundrobin[ Launch: Tributary inlet ] 4711690 by roundrobin
| // http://phrogz.net/SVG/convert_path_to_polygon.xhtml | |
| function pathToPolygon(path,samples){ | |
| if (!samples) samples = 0; | |
| var doc = path.ownerDocument; | |
| var poly = doc.createElementNS('http://www.w3.org/2000/svg','polygon'); | |
| // Put all path segments in a queue | |
| for (var segs=[],s=path.pathSegList,i=s.numberOfItems-1;i>=0;--i) segs[i] = s.getItem(i); | |
| var segments = segs.concat(); |
| /* | |
| @fliptopbox | |
| LZW Compression/Decompression for Strings | |
| Implementation of LZW algorithms from: | |
| http://rosettacode.org/wiki/LZW_compression#JavaScript | |
| Usage: | |
| var a = 'a very very long string to be squashed'; | |
| var b = a.compress(); // 'a veryāăąlong striċ to bečquashed' |
| // this is the background code... | |
| // listen for our browerAction to be clicked | |
| chrome.browserAction.onClicked.addListener(function (tab) { | |
| // for the current tab, inject the "inject.js" file & execute it | |
| chrome.tabs.executeScript(tab.ib, { | |
| file: 'inject.js' | |
| }); | |
| }); |
This example shows the results (orange) of performing four different boolean operations (union, difference, xor and intersection) on two 2D shapes (blue). Thanks to the powerful clipper.js library, the computation is performed in client-side Javascript.
The example is almost entirely taken from this clipper.js demo.
| <!doctype html> | |
| <html> | |
| <title>Flatten.js, General SVG Flattener</title> | |
| <head> | |
| <script> | |
| /* | |
| Random path and shape generator, flattener test base: https://jsfiddle.net/fjm9423q/embedded/result/ | |
| Basic usage example: https://jsfiddle.net/nrjvmqur/embedded/result/ |
| function splitCubicBezier(options) { | |
| var z = options.z, | |
| cz = z-1, | |
| z2 = z*z, | |
| cz2 = cz*cz, | |
| z3 = z2*z, | |
| cz3 = cz2*cz, | |
| x = options.x, | |
| y = options.y; |
| Split bezier | |
| Shows the possibility to split a bezier curve, two separate techniques are used: | |
| Bernstein's Polynomials | |
| Casteljau's Algorithm | |
| Bernstein's Polynomials | |
| The Bernstein Polynomial implemented in javascript reads as: | |
| getBezier = function getBez(percent,p1,cp1,cp2,p2) { |