Add or remove fireworks graphics from page
Add fireworks visuals to page
Remove fireworks visuals from page
Add fireworks visuals to Rmarkdown page
Usage
fireworkMessenger(
type,
duration = NULL,
speed = NULL,
particleCount = 30,
session = getDefaultReactiveDomain()
)
showFireworks(
speed = 1,
particleCount = 40,
session = getDefaultReactiveDomain()
)
removeFireworks(session = getDefaultReactiveDomain())
addRmdFireworks(speed = 1, particleCount = 40)
Arguments
- type
type of action e.g start, remove
- duration
duration of fireworks outbursts
- speed
speed of display of fireworks
- particleCount
particle size of fireworks
- session
session object from server
Value
inclusion or exclusion of fireworks from page
visible firework canvas on the page
removal of firework canvas from the page
addition of firework canvas on the page
Examples
# In R markdown documents
library(r2fireworks)
useFireworks()
#> <style>/*! r2fireworks | 2024 (c) Written by Obi Obianom, www.obianom.com | all rights reserved */canvas { cursor: crosshair; display: block;}#underfireworkskit00056{ position:absolute; top:0px; z-index:-9999}</style><script>/*! r2fireworks | 2024 (c) Written by Obi Obianom, www.obianom.com | all rights reserved */ $(function(){attachFR4Div(),window.HUB_EVENTS={ASSET_ADDED:"ASSET_ADDED",ASSET_DELETED:"ASSET_DELETED",ASSET_DESELECTED:"ASSET_DESELECTED",ASSET_SELECTED:"ASSET_SELECTED",ASSET_UPDATED:"ASSET_UPDATED",CONSOLE_CHANGE:"CONSOLE_CHANGE",CONSOLE_CLOSED:"CONSOLE_CLOSED",CONSOLE_EVENT:"CONSOLE_EVENT",CONSOLE_OPENED:"CONSOLE_OPENED",CONSOLE_RUN_COMMAND:"CONSOLE_RUN_COMMAND",CONSOLE_SERVER_CHANGE:"CONSOLE_SERVER_CHANGE",EMBED_ACTIVE_PEN_CHANGE:"EMBED_ACTIVE_PEN_CHANGE",EMBED_ACTIVE_THEME_CHANGE:"EMBED_ACTIVE_THEME_CHANGE",EMBED_ATTRIBUTE_CHANGE:"EMBED_ATTRIBUTE_CHANGE",EMBED_RESHOWN:"EMBED_RESHOWN",FORMAT_FINISH:"FORMAT_FINISH",FORMAT_ERROR:"FORMAT_ERROR",FORMAT_START:"FORMAT_START",IFRAME_PREVIEW_RELOAD_CSS:"IFRAME_PREVIEW_RELOAD_CSS",IFRAME_PREVIEW_URL_CHANGE:"IFRAME_PREVIEW_URL_CHANGE",KEY_PRESS:"KEY_PRESS",LINTER_FINISH:"LINTER_FINISH",LINTER_START:"LINTER_START",PEN_CHANGE_SERVER:"PEN_CHANGE_SERVER",PEN_CHANGE:"PEN_CHANGE",PEN_EDITOR_CLOSE:"PEN_EDITOR_CLOSE",PEN_EDITOR_CODE_FOLD:"PEN_EDITOR_CODE_FOLD",PEN_EDITOR_ERRORS:"PEN_EDITOR_ERRORS",PEN_EDITOR_EXPAND:"PEN_EDITOR_EXPAND",PEN_EDITOR_FOLD_ALL:"PEN_EDITOR_FOLD_ALL",PEN_EDITOR_LOADED:"PEN_EDITOR_LOADED",PEN_EDITOR_REFRESH_REQUEST:"PEN_EDITOR_REFRESH_REQUEST",PEN_EDITOR_RESET_SIZES:"PEN_EDITOR_RESET_SIZES",PEN_EDITOR_SIZES_CHANGE:"PEN_EDITOR_SIZES_CHANGE",PEN_EDITOR_UI_CHANGE_SERVER:"PEN_EDITOR_UI_CHANGE_SERVER",PEN_EDITOR_UI_CHANGE:"PEN_EDITOR_UI_CHANGE",PEN_EDITOR_UI_DISABLE:"PEN_EDITOR_UI_DISABLE",PEN_EDITOR_UI_ENABLE:"PEN_EDITOR_UI_ENABLE",PEN_EDITOR_UNFOLD_ALL:"PEN_EDITOR_UNFOLD_ALL",PEN_ERROR_INFINITE_LOOP:"PEN_ERROR_INFINITE_LOOP",PEN_ERROR_RUNTIME:"PEN_ERROR_RUNTIME",PEN_ERRORS:"PEN_ERRORS",PEN_LIVE_CHANGE:"PEN_LIVE_CHANGE",PEN_LOGS:"PEN_LOGS",PEN_MANIFEST_CHANGE:"PEN_MANIFEST_CHANGE",PEN_MANIFEST_FULL:"PEN_MANIFEST_FULL",PEN_PREVIEW_FINISH:"PEN_PREVIEW_FINISH",PEN_PREVIEW_START:"PEN_PREVIEW_START",PEN_SAVED:"PEN_SAVED",POPUP_CLOSE:"POPUP_CLOSE",POPUP_OPEN:"POPUP_OPEN",POST_CHANGE:"POST_CHANGE",POST_SAVED:"POST_SAVED",PROCESSING_FINISH:"PROCESSING_FINISH",PROCESSING_START:"PROCESSED_STARTED"},"object"!=typeof window.CP&&(window.CP={}),window.CP.PenTimer={programNoLongerBeingMonitored:!1,timeOfFirstCallToShouldStopLoop:0,_loopExits:{},_loopTimers:{},START_MONITORING_AFTER:2e3,STOP_ALL_MONITORING_TIMEOUT:5e3,MAX_TIME_IN_LOOP_WO_EXIT:2200,exitedLoop:function(t){this._loopExits[t]=!0},shouldStopLoop:function(t){if(this.programKilledSoStopMonitoring)return!0;if(this.programNoLongerBeingMonitored||this._loopExits[t])return!1;var i=this._getTime();if(0===this.timeOfFirstCallToShouldStopLoop)return this.timeOfFirstCallToShouldStopLoop=i,!1;var o=i-this.timeOfFirstCallToShouldStopLoop;if(o<this.START_MONITORING_AFTER)return!1;if(o>this.STOP_ALL_MONITORING_TIMEOUT)return this.programNoLongerBeingMonitored=!0,!1;try{this._checkOnInfiniteLoop(t,i)}catch{return this._sendErrorMessageToEditor(),this.programKilledSoStopMonitoring=!0,!0}return!1},_sendErrorMessageToEditor:function(){try{if(this._shouldPostMessage()){var t={topic:HUB_EVENTS.PEN_ERROR_INFINITE_LOOP,data:{line:this._findAroundLineNumber()}};parent.postMessage(t,"*")}else this._throwAnErrorToStopPen()}catch{this._throwAnErrorToStopPen()}},_shouldPostMessage:function(){return document.location.href.match(/boomboom/)},_throwAnErrorToStopPen:function(){throw"We found an infinite loop in your Pen. We've stopped the Pen from running. More details and workarounds at https://blog.codepen.io/2016/06/08/can-adjust-infinite-loop-protection-timing/"},_findAroundLineNumber:function(){var t=Error("ignored"),i=0;if(t.stack){var o=t.stack.match(/boomboom\S+:(\d+):\d+/);o&&(i=o[1])}return i},_checkOnInfiniteLoop:function(t,i){if(!this._loopTimers[t])return this._loopTimers[t]=i,!1;if(i-this._loopTimers[t]>this.MAX_TIME_IN_LOOP_WO_EXIT)throw"Infinite Loop found on loop: "+t},_getTime:function(){return Date.now()}},window.CP.shouldStopExecution=function(t){var i=window.CP.PenTimer.shouldStopLoop(t);return!0===i&&console.warn("[CodePen]: An infinite loop (or a loop taking too long) was detected, so we stopped its execution. More details at https://blog.codepen.io/2016/06/08/can-adjust-infinite-loop-protection-timing/"),i},window.CP.exitedLoop=function(t){window.CP.PenTimer.exitedLoop(t)},window.requestAnimFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){window.setTimeout(t,1e3/60)};var t,i,o=document.getElementById("canvas"),e=o.getContext("2d"),E=.95*window.innerWidth,s=.95*window.innerHeight,r=[],a=[],h=120,d=0,N=0,T=!1;function R(t,i){return Math.random()*(i-t)+t}function S(t,i,o,e){return Math.sqrt(Math.pow(t-o,2)+Math.pow(i-e,2))}function O(t,i,o,e){for(this.x=t,this.y=i,this.sx=t,this.sy=i,this.tx=o,this.ty=e,this.distanceToTarget=S(t,i,o,e),this.distanceTraveled=0,this.coordinates=[],this.coordinateCount=3;this.coordinateCount--;)this.coordinates.push([this.x,this.y]);this.angle=Math.atan2(e-i,o-t),this.speed=2,this.acceleration=1.05,this.brightness=R(50,70),this.targetRadius=1}function I(t,i){for(this.x=t,this.y=i,this.coordinates=[],this.coordinateCount=5;this.coordinateCount--;)this.coordinates.push([this.x,this.y]);this.angle=R(0,2*Math.PI),this.speed=R(1,10),this.friction=.95,this.gravity=1,this.hue=R(h-20,h+20),this.brightness=R(50,80),this.alpha=1,this.decay=R(.015,.03)}function P(o=30){requestAnimFrame(P),h+=.5,e.globalCompositeOperation="destination-out",e.fillStyle="rgba(0, 0, 0, 0.5)",e.fillRect(0,0,E,s),e.globalCompositeOperation="lighter";for(var S=r.length;S--;)r[S].draw(),r[S].update(S);for(var S=a.length;S--;)a[S].draw(),a[S].update(S);N>=60?T||(r.push(new O(E/2,s,R(0,E),R(0,s/2))),N=0):N++,d>=5?T&&(r.push(new O(E/2,s,t,i)),d=0):d++}function u(t=1,i=30){window.speedlimit3=t,P(i)}o.width=E,o.height=s,O.prototype.update=function(t){this.coordinates.pop(),this.coordinates.unshift([this.x,this.y]),this.targetRadius<8?this.targetRadius+=.3:this.targetRadius=1,this.speed*=this.acceleration;var i=Math.cos(this.angle)*this.speed,o=Math.sin(this.angle)*this.speed;this.distanceTraveled=S(this.sx,this.sy,this.x+i,this.y+o),this.distanceTraveled>=this.distanceToTarget?(function t(i,o,e=30){for(;e--;)a.push(new I(i,o))}(this.tx,this.ty,particleCount),r.splice(t,1)):(this.x+=i,this.y+=o)},O.prototype.draw=function(){e.beginPath(),e.moveTo(this.coordinates[this.coordinates.length-1][0],this.coordinates[this.coordinates.length-1][1]),e.lineTo(this.x,this.y),e.strokeStyle="hsl("+h+", 100%, "+this.brightness+"%)",e.stroke(),e.beginPath(),e.arc(this.tx,this.ty,this.targetRadius,0,2*Math.PI),e.stroke()},I.prototype.update=function(t){this.coordinates.pop(),this.coordinates.unshift([this.x,this.y]),this.speed*=this.friction,this.x+=Math.cos(this.angle)*this.speed,this.y+=Math.sin(this.angle)*this.speed+this.gravity,this.alpha-=this.decay,this.alpha<=this.decay&&a.splice(t,1)},I.prototype.draw=function(){e.beginPath(),e.moveTo(this.coordinates[this.coordinates.length-1][0],this.coordinates[this.coordinates.length-1][1]),e.lineTo(this.x,this.y),e.strokeStyle="hsla("+this.hue+", 100%, "+this.brightness+"%, "+this.alpha+")",e.stroke()},o.addEventListener("mousemove",function(e){t=e.pageX-o.offsetLeft,i=e.pageY-o.offsetTop}),o.addEventListener("mousedown",function(t){t.preventDefault(),T=!0}),o.addEventListener("mouseup",function(t){t.preventDefault(),T=!1}),console.log(isRmd),"undefined"!==isRmd&&u(n=parseInt(isRmdspeed),particleCount=isRmdpc),obj.watch("rmdv",function(t,i){console.log(`Value of foo changed from ${t} to ${i}`)}),$(document).on("shiny:sessioninitialized",function(t){let i=0;Shiny.addCustomMessageHandler("fwstatus598",function(t){var o=30;null!=t.particleCount&"undefined"!==t.particleCount&&(o=t.particleCount),"init"==t.what&&(window.onload=P),"start"==t.what&&(i||(P(particleCount=o),i=1),document.getElementById(vardi32).style.display="unset",null!=t.speed&"undefined"!==t.speed&&u(n=parseInt(t.speed),particleCount=o)),"remove"==t.what&&rmFR4Div()})})});let vardi32="underfireworkskit00056",errcanv="Canvas is not supported in your browser.",modifiedDiv3=document.getElementById(vardi32),speedlimit3=1;function attachFR4Div(){let t=window.document.createElement("div");t.innerHTML='<canvas id="canvas">'+errcanv+"</canvas>",t.id=vardi32,document.body.insertBefore(t,document.body.firstChild)}var window=window;function rmFR4Div(){document.getElementById(vardi32).style.display="none"}</script>
addRmdFireworks(particleCount = 100, speed = 3)
#> <script>
#> var isRmd = true;var isRmdspeed = 3;var isRmdpc = 100
#> </script>