From b461d173d3b4a3e98db8699689bffa2868dfb98f Mon Sep 17 00:00:00 2001 From: BenPancake <37308709+BenPancake@users.noreply.github.com> Date: Tue, 16 Jul 2019 23:32:21 -0400 Subject: [PATCH] Create record-flag.js --- js/record-flag.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 js/record-flag.js diff --git a/js/record-flag.js b/js/record-flag.js new file mode 100644 index 0000000..201d3fe --- /dev/null +++ b/js/record-flag.js @@ -0,0 +1,29 @@ + (function() { + let canvas = document.getElementsByTagName("canvas")[0]; + let ctx = canvas.getContext('2d'); + // https://stackoverflow.com/questions/50681683/how-to-save-canvas-animation-as-gif-or-webm + // records canvas for 10 seconds, but potato can be hindered due to lag + // only needs to be included in index.html to work, I'm pretty sure + // maybe some window.onload things need to happen as well + startRecording(); + function startRecording() { + let chunks = []; + let stream = canvas.captureStream(); + let rec = new MediaRecorder(stream); + rec.ondataavailable = function(e) { + chunks.push(e.data); + } + rec.onstop = function(e) { + let a = document.createElement('a'); + a.download = 'flagwave.webm'; + a.href = URL.createObjectURL(new Blob(chunks, {type: 'video/webm'})); + a.innerHTML = 'Download'; + a.style = "position: absolute; left: 10px; top: 100px; font-family: 20px monospace"; + document.body.appendChild(a); + } + rec.start(); + setTimeout(function() { + rec.stop(); + }, 10000); + } + })();