Skip to content

Instantly share code, notes, and snippets.

@natcl
Last active March 20, 2018 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natcl/e354bbfe69f605b551b701419d11d493 to your computer and use it in GitHub Desktop.
Save natcl/e354bbfe69f605b551b701419d11d493 to your computer and use it in GitHub Desktop.
[{"id":"114a5d8c.c2b092","type":"inject","z":"be63dfb5.edca6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":120,"wires":[["94f49e0d.136bb8"]]},{"id":"94f49e0d.136bb8","type":"function","z":"be63dfb5.edca6","name":"[0,255,0]","func":"msg.payload = Buffer.alloc(64*3, Buffer.from([0,255,0]));\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":120,"wires":[["32b2de23.568a02"]]},{"id":"ee2e23c1.8721d","type":"function","z":"be63dfb5.edca6","name":"black","func":"msg.payload = Buffer.alloc(64*3, Buffer.from([0,0,0]));\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":220,"wires":[["32b2de23.568a02"]]},{"id":"1b558bf5.5f2984","type":"inject","z":"be63dfb5.edca6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":220,"wires":[["ee2e23c1.8721d"]]},{"id":"23a4922f.e7fbae","type":"function","z":"be63dfb5.edca6","name":"[0,0,255]","func":"msg.payload = Buffer.alloc(64*3, Buffer.from([0,0,255]));\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":160,"wires":[["32b2de23.568a02"]]},{"id":"6c3c498f.cb7708","type":"inject","z":"be63dfb5.edca6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":160,"wires":[["23a4922f.e7fbae"]]},{"id":"76ab9948.7450f","type":"function","z":"be63dfb5.edca6","name":"[255,0,0]","func":"msg.payload = Buffer.alloc(64*3, Buffer.from([255,0,0]));\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":80,"wires":[["32b2de23.568a02"]]},{"id":"9584f7f1.973638","type":"inject","z":"be63dfb5.edca6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":80,"wires":[["76ab9948.7450f"]]},{"id":"ccab230d.0b4a3","type":"unsafe-function","z":"be63dfb5.edca6","name":"","func":"var Canvas = require('canvas');\ncanvas = new Canvas(150, 1);\nctx = canvas.getContext('2d');\n\nctx.fillStyle=\"#660000\";\nctx.fillRect(0,0,4,1);\n\nctx.fillStyle=\"#006600\";\nctx.fillRect(8,0,6,1);\n\n\n\nctx.globalCompositeOperation = 'lighter';\nctx.fillStyle=\"#000066\";\nctx.fillRect(12,0,8,1);\n\nmsg.payload = canvas.toBuffer('raw');\nmsg.source = 'canvas';\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":280,"wires":[[]]},{"id":"362d997a.1eea86","type":"inject","z":"be63dfb5.edca6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":280,"wires":[["ccab230d.0b4a3"]]},{"id":"f6cd2e13.6ac9b","type":"unsafe-function","z":"be63dfb5.edca6","name":"","func":"var Canvas = require('canvas');\ncanvas = new Canvas(31, 1);\nctx = canvas.getContext('2d');\n\nmsg.source = 'canvas';\n\nfunction drawCircle(x){\n \tctx.beginPath();\n \tctx.arc(x,10,10,0,2*Math.PI);\n \tctx.fill();\n \tmsg.payload = canvas.toBuffer('raw');\n\tnode.send(msg);\n}\nvar x = 0;\nsetInterval(function(){ \n \tctx.clearRect(0,0,31,31);\n \tctx.fillStyle=\"red\";\n \tdrawCircle(x%40);\n \tx++;\n}, 25);","outputs":1,"noerr":0,"x":530,"y":320,"wires":[[]]},{"id":"1676e3bf.37fa94","type":"inject","z":"be63dfb5.edca6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":320,"wires":[["f6cd2e13.6ac9b"]]},{"id":"68069e0.7b59ce4","type":"unsafe-function","z":"be63dfb5.edca6","name":"0","func":"var requestAnimFrame = (function(){\n return function( callback ){\n\t\t\tsetTimeout(callback, 1000 / 60);\n\t\t };\n})();\n\nvar Canvas = require('canvas')\n\nvar W = 150;//window.innerWidth\n\nvar H = 1;//window.innerHeight\nvar canvas = new Canvas(W, H);\nvar ctx = canvas.getContext(\"2d\")\nvar circles = [];\n\ncanvas.width = W;\ncanvas.height = H; \n\n//Random Circles creator\nfunction create() {\n\t\n\t//Place the circles at the center\n\t\n\tthis.x = 0;\n\tthis.y = 5;\n\n\t\n\t//Random radius between 2 and 6\n\tthis.radius = 5 + Math.random()*3; \n\t\n\t//Random velocities\n\tthis.vx = 0.5 + Math.random()*1;\n\tthis.vy = 0;// + Math.random()*10;\n\t\n\t//Random colors\n\tthis.r = Math.round(Math.random())*255;\n\tthis.g = 0;//Math.round(Math.random())*255;\n\tthis.b = Math.round(Math.random())*255;\n}\n\nfor (var i = 0; i < 500; i++) {\n\tcircles.push(new create());\n}\n\nfunction draw() {\n\t\n\t//Fill canvas with black color\n ctx.globalCompositeOperation = \"source-over\";\n ctx.fillStyle = \"rgba(0,0,0,0.15)\";\n ctx.fillRect(0, 0, W, H);\n\t\n\t//Fill the canvas with circles\n\tfor(var j = 0; j < circles.length; j++){\n\t\tvar c = circles[j];\n\t\t\n\t\t//Create the circles\n\t\tctx.beginPath();\n\t\tctx.arc(c.x, c.y, c.radius, 0, Math.PI*2, false);\n ctx.fillStyle = \"rgba(\"+c.r+\", \"+c.g+\", \"+c.b+\", 0.5)\";\n\t\tctx.fill();\n\t\t\n\t\tc.x += c.vx;\n\t\tc.y += c.vy;\n\t\tc.radius -= .01;\n\t\t\n\t\tif(c.radius < 0)\n\t\t\tcircles[j] = new create();\n\t}\n msg.source = 'canvas';\n msg.payload = canvas.toBuffer('raw');\n node.send(msg);\n}\n\nfunction animate() {\n\trequestAnimFrame(animate);\n\tdraw();\n}\n\nanimate();","outputs":1,"noerr":0,"x":530,"y":360,"wires":[[]]},{"id":"f995ff9.8ff028","type":"inject","z":"be63dfb5.edca6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":360,"wires":[["68069e0.7b59ce4"]]},{"id":"fa8758f1.206538","type":"unsafe-function","z":"be63dfb5.edca6","name":"8x8","func":"if (msg.payload === false) {\n if (context.timeout) {\n clearTimeout(context.timeout);\n return;\n }\n}\n\nvar requestAnimFrame = (function(){\n return function( callback ){\n\t\t\tcontext.timeout = setTimeout(callback, 1000 / 60);\n\t\t };\n})();\n\nconst { createCanvas, loadImage } = require('canvas');\n\nvar W = 8;//window.innerWidth\nvar H = 8;//window.innerHeight\n\nconst canvas = createCanvas(W, H);\nvar ctx = canvas.getContext(\"2d\");\nvar circles = [];\n\ncanvas.width = W;\ncanvas.height = H; \n\n//Random Circles creator\nfunction create() {\n\t\n\t//Place the circles at the center\n\t\n\tthis.x = W/2;\n\tthis.y = H/2;\n\n\t\n\t//Random radius between 2 and 6\n\tthis.radius = 1 + Math.random()*1; \n\t\n\t//Random velocities\n\tthis.vx = -0.5 + Math.random()*2;\n\tthis.vy = -0.5 + Math.random()*2;\n\t\n\t//Random colors\n\tthis.r = Math.round(Math.random())*255;\n\tthis.g = Math.round(Math.random())*127;\n\tthis.b = Math.round(Math.random())*55;\n}\n\nfor (var i = 0; i < 10; i++) {\n\tcircles.push(new create());\n}\n\nfunction draw() {\n\t\n\t//Fill canvas with black color\n ctx.globalCompositeOperation = \"source-over\";\n ctx.fillStyle = \"rgba(0,0,0,0.15)\";\n ctx.fillRect(0, 0, W, H);\n\t\n\t//Fill the canvas with circles\n\tfor(var j = 0; j < circles.length; j++){\n\t\tvar c = circles[j];\n\t\t\n\t\t//Create the circles\n\t\tctx.beginPath();\n\t\tctx.arc(c.x, c.y, c.radius, 0, Math.PI*2, false);\n ctx.fillStyle = \"rgba(\"+c.r+\", \"+c.g+\", \"+c.b+\", 0.5)\";\n\t\tctx.fill();\n\t\t\n\t\tc.x += c.vx;\n\t\tc.y += c.vy;\n\t\tc.radius -= .02;\n\t\t\n\t\tif(c.radius < 0)\n\t\t\tcircles[j] = new create();\n\t}\n\t\n\tmsg.mode = 'canvas';\n\tmsg.payload = canvas.toBuffer('raw');\n\tnode.send(msg);\n}\n\nfunction animate() {\n\trequestAnimFrame(animate);\n\tdraw();\n}\n\nanimate();","outputs":1,"noerr":0,"x":530,"y":400,"wires":[["32b2de23.568a02"]]},{"id":"2ff567ba.1449e8","type":"inject","z":"be63dfb5.edca6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":400,"wires":[["fa8758f1.206538"]]},{"id":"46a1af06.c3869","type":"inject","z":"be63dfb5.edca6","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":440,"wires":[["fa8758f1.206538"]]},{"id":"bb20ef21.e776c","type":"unsafe-function","z":"be63dfb5.edca6","name":"8x8","func":"const { createCanvas, loadImage } = require('canvas');\n\t\nvar W = 8;//window.innerWidth\nvar H = 8;//window.innerHeight\n\nconst c = createCanvas(W, H);\nvar ctx = c.getContext(\"2d\");\n \nctx.beginPath();\nctx.moveTo(100,0);\nctx.lineTo(100,200);\nctx.stroke();\n\nfunction drawCircle(x){\n ctx.beginPath();\n ctx.arc(x,100,10,0,2*Math.PI);\n ctx.fillStyle=\"red\";\n ctx.fill();\n}\n\nfunction rotate() {\n\t\n // Clear the canvas\n ctx.clearRect(0, 0, W, H);\n\t\n // Move registration point to the center of the canvas\n ctx.translate(W/2, W/2);\n\t\n // Rotate 1 degree\n ctx.rotate(Math.PI / 180);\n \n // Move registration point back to the top left corner of canvas\n ctx.translate(-W/2, -W/2);\n\t\n ctx.fillStyle = \"red\";\n ctx.fillRect(W/4, W/4, W/2, H/4);\n ctx.fillStyle = \"blue\";\n ctx.fillRect(W/4, W/2, W/2, H/4);\n \n msg.mode = 'canvas';\n msg.payload = c.toBuffer('raw');\n node.send(msg);\n}\n\nsetInterval(rotate, 25);","outputs":1,"noerr":0,"x":530,"y":460,"wires":[["32b2de23.568a02"]]},{"id":"7ede2f9f.a73d3","type":"inject","z":"be63dfb5.edca6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":520,"wires":[["bb20ef21.e776c"]]},{"id":"32b2de23.568a02","type":"rpi-ws281x-native","z":"be63dfb5.edca6","width":"8","height":"8","brightness":"20","reverse":true,"mode":"default","name":"","x":920,"y":400,"wires":[]},{"id":"9aa1c423.946958","type":"unsafe-function","z":"be63dfb5.edca6","name":"8x8","func":"const { createCanvas } = require('canvas');\n\nvar CANVAS_WIDTH = 8;\nvar CANVAS_HEIGHT = 8;\n\nvar canvas = createCanvas(CANVAS_WIDTH, CANVAS_HEIGHT);\nvar context = canvas.getContext('2d');\ncanvas.width = CANVAS_WIDTH;\ncanvas.height = CANVAS_HEIGHT;\n\nvar FPS = 60;\n \nvar context;\nvar dot;\n\ninit();\n\nfunction init() {\n\n\n \ncreateTrail();\n\nsetInterval(loop, 1000 / FPS);\n \n}\n\nfunction createTrail() {\n dot = {\n x: CANVAS_WIDTH, \n y: CANVAS_HEIGHT,\n speed: 0.3,\n direction: Math.PI * 2 * Math.random()\n }\n}\n\nfunction updatePosition() {\n var dx = dot.x + dot.speed * Math.cos(dot.direction);\n var dy = dot.y + dot.speed * Math.sin(dot.direction);\n \n if (dx < 0 || dx > CANVAS_WIDTH || dy < 0 || dy > CANVAS_HEIGHT) {\n dot.direction = Math.PI * 2 * Math.random();\n updatePosition();\n } else {\n dot.x = dx;\n dot.y = dy;\n }\n}\n\nfunction loop() {\n updatePosition();\n \n // Draw over the whole canvas to create the trail effect\n context.fillStyle = 'rgba(255, 255, 255, 0.01)';\n context.fillRect(0, 0, canvas.width, canvas.height);\n \n // Draw the dot\n context.beginPath();\n context.fillStyle = '#ff0000';\n context.moveTo(dot.x, dot.y);\n context.arc(dot.x, dot.y, 1, 0, Math.PI*2, true);\n context.fill();\n \n msg.mode = 'canvas';\n msg.payload = canvas.toBuffer('raw');\n node.send(msg);\n}","outputs":1,"noerr":0,"x":470,"y":620,"wires":[["32b2de23.568a02"]]},{"id":"29fab595.4ccc6a","type":"inject","z":"be63dfb5.edca6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":620,"wires":[["9aa1c423.946958"]]},{"id":"522aed7a.e7816c","type":"ui_template","z":"be63dfb5.edca6","group":"abf6b909.950558","name":"","order":0,"width":"6","height":"6","format":"<img src={{msg.payload}}>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":760,"y":820,"wires":[[]]},{"id":"c1ad3a52.cb9658","type":"unsafe-function","z":"be63dfb5.edca6","name":"Nuclear Super Bomb","func":"var CANVAS_WIDTH = 8;\nvar CANVAS_HEIGHT = 8;\n\nvar FPS = 40;\n \nvar canvas;\nvar context;\nvar dot;\nvar red;\nvar blue;\nvar green;\nvar size;\n\ninit();\n\nfunction init() {\n try {\n canvas = document.getElementById('canvas');\n }\n catch(err) {\n const {createCanvas} = require('canvas');\n canvas = createCanvas(CANVAS_WIDTH, CANVAS_HEIGHT);\n }\n \n if (canvas && canvas.getContext) {\n context = canvas.getContext('2d');\n canvas.width = CANVAS_WIDTH;\n canvas.height = CANVAS_HEIGHT;\n \n createTrail();\n \n setInterval(loop, 1000 / FPS);\n }\n}\n\nfunction createTrail() {\n dot = {\n x: CANVAS_WIDTH, \n y: CANVAS_HEIGHT,\n speed: 1.5,\n direction: Math.PI * 2 * Math.random()\n }\n}\n\nfunction updatePosition() {\n var dx = dot.x + dot.speed * Math.cos(dot.direction);\n var dy = dot.y + dot.speed * Math.sin(dot.direction) + 1;\n red = parseInt(red/1.1);\n blue = parseInt(blue+10);\n size = 1;\n \n if (dx < 0 || dx > CANVAS_WIDTH || dy < 0 || dy > CANVAS_HEIGHT) {\n blue = 255;//parseInt(Math.random()*500);\n red = 255;//parseInt(Math.random()*255);\n dot.direction = Math.PI * 2 * Math.random();\n updatePosition();\n size = 4;\n green = 0;//parseInt(Math.random()*255);\n \n } else {\n dot.x = dx;\n dot.y = dy;\n }\n}\n\nfunction loop() {\n updatePosition();\n \n // Draw over the whole canvas to create the trail effect\n context.fillStyle = 'rgba(0, 0, 0, .02)';\n context.fillRect(0, 0, canvas.width, canvas.height);\n \n // Draw the dot\n context.beginPath();\n console.log(red);\n context.fillStyle = 'rgba('+ red + ',' + green + ','+ blue +', 1)';\n context.moveTo(dot.x, dot.y);\n context.arc(dot.x, dot.y, size, 0, Math.PI*2, true);\n context.fill();\n \n node.send([{payload:canvas.toDataURL()}, {payload:canvas.toBuffer('raw'), mode: 'canvas'}]);\n}","outputs":2,"noerr":0,"x":380,"y":860,"wires":[["522aed7a.e7816c"],["32b2de23.568a02"]]},{"id":"b23e7fd0.57e0c","type":"inject","z":"be63dfb5.edca6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":860,"wires":[["c1ad3a52.cb9658"]]},{"id":"c48a11a9.ec532","type":"artnet","z":"be63dfb5.edca6","name":"","x":710,"y":1020,"wires":[["75dc87.a11a4b78"]]},{"id":"75dc87.a11a4b78","type":"udp out","z":"be63dfb5.edca6","name":"","addr":"10.10.90.220","iface":"","port":"6454","ipv":"udp4","outport":"","base64":false,"multicast":"false","x":914,"y":1019,"wires":[]},{"id":"d6cde58c.0a1038","type":"split","z":"be63dfb5.edca6","name":"","splt":"510","spltType":"len","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":370,"y":1020,"wires":[["941403e9.8218e8"]]},{"id":"941403e9.8218e8","type":"change","z":"be63dfb5.edca6","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"parts.index","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":1020,"wires":[["c48a11a9.ec532"]]},{"id":"306edfda.d51af","type":"unsafe-function","z":"be63dfb5.edca6","name":"Remove 4th byte","func":"// each pixel is bgra\nconst numPixels = Math.floor(msg.payload.length/4);\n\n// final bugger is rgb\nvar finalBuffer = Buffer.allocUnsafe(numPixels*3);\n\n// for each pixel\nfor (var p = 0; p < numPixels; p++) {\n // swap the buffer --> bgra --> argb\n msg.payload.slice(p*4, p*4+4).swap32();\n // get rid of first byte (a)\n msg.payload.copy(finalBuffer, p*3, p*4+1, p*4+4);\n}\nreturn {payload: finalBuffer};","outputs":1,"noerr":0,"x":190,"y":1020,"wires":[["d6cde58c.0a1038"]]},{"id":"abf6b909.950558","type":"ui_group","z":"","name":"Default","tab":"127ae2fb.e9e445","disp":true,"width":"6","collapse":false},{"id":"127ae2fb.e9e445","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment