Created
January 1, 2018 18:04
-
-
Save eeropic/7e39aad234636e28f57322e6d4eee1c6 to your computer and use it in GitHub Desktop.
Paper.JS effect stack prototype
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
| function roughenSegments(path,amp){ | |
| var amp=amp || 10; | |
| for(s in path.segments){ | |
| var seg=path.segments[s]; | |
| seg.point.x+=Math.random()*(2-1)*amp | |
| seg.point.y+=Math.random()*(2-1)*amp | |
| } | |
| } | |
| Item.prototype.roughen = function (amp) { | |
| var amp=amp || 10; | |
| var self=this; | |
| var itemTypes={ | |
| Path(){ | |
| roughenSegments(self,amp) | |
| }, | |
| CompoundPath(){ | |
| }, | |
| Shape(){ | |
| }, | |
| Raster(){ | |
| }, | |
| SymbolItem(){ | |
| }, | |
| PointText(){ | |
| }, | |
| Group(){ | |
| for(var i in self.children){ | |
| var item=self.children[i]; | |
| roughenSegments(item,10) | |
| } | |
| }, | |
| Layer(){ | |
| } | |
| } | |
| itemTypes[this.className]() | |
| return self | |
| } | |
| Item.prototype.repeat = function (options) { | |
| var pt=options.offset || new Point(10,0); | |
| var num=options.copies || 5; | |
| var self=this; | |
| var itemTypes={ | |
| Path(){ | |
| var group=new Group(); | |
| group.appendTop(self) | |
| for(var i=0;i<num+1;i++){ | |
| var clone=self.clone() | |
| clone.position+=pt*(i+1); | |
| } | |
| self=group; | |
| }, | |
| CompoundPath(){ | |
| }, | |
| Shape(){ | |
| }, | |
| Raster(){ | |
| }, | |
| SymbolItem(){ | |
| }, | |
| PointText(){ | |
| }, | |
| Group(){ | |
| var group=new Group(); | |
| group.appendTop(self) | |
| for(var i=0;i<num+1;i++){ | |
| var clone=self.clone() | |
| clone.position+=pt*(i+1); | |
| } | |
| self=group; | |
| }, | |
| Layer(){ | |
| } | |
| } | |
| itemTypes[this.className]() | |
| return self | |
| } | |
| Item.prototype.scatter = function (radius) { | |
| var radius=radius || 10; | |
| var self=this; | |
| var itemTypes={ | |
| Path(){ | |
| self.position+=Math.random()*radius-(radius/2) | |
| }, | |
| Group(){ | |
| for(var i in self.children){ | |
| self.children[i].position+=Math.random()*radius-(radius/2) | |
| } | |
| }, | |
| } | |
| itemTypes[this.className]() | |
| return self | |
| } | |
| Item.prototype.colorize = function (color) { | |
| var color=color || new RGBColor(1,0,0); | |
| var self=this; | |
| var itemTypes={ | |
| Path(){ | |
| }, | |
| CompoundPath(){ | |
| }, | |
| Shape(){ | |
| }, | |
| Raster(){ | |
| }, | |
| SymbolItem(){ | |
| }, | |
| PointText(){ | |
| }, | |
| Group(){ | |
| for(i in self.children){ | |
| var item=self.children[i]; | |
| item.fillColor=new Color( | |
| Math.random(), | |
| Math.random(), | |
| Math.random()) | |
| } | |
| }, | |
| Layer(){ | |
| } | |
| } | |
| itemTypes[this.className]() | |
| return self | |
| } | |
| var path=new Path.Rectangle({ | |
| position:[100,100], | |
| size:[10,50], | |
| fillColor:"blue" | |
| }) | |
| path | |
| .repeat({offset:new Point(10,0),copies:40}) | |
| .roughen(40) | |
| .colorize("red","blue") | |
| .scatter(150) | |
| console.log(project.activeLayer.children) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment