Difference between revisions of "Widget:Logo"
(since colon is not allowed anymore: URLs will be without protocol and may well be relative) |
(updated flake snow -> confetti) |
||
Line 82: | Line 82: | ||
if ( ( progress / 500 ) > snowFlakes.length && ( _timestamp - oldTimestamp < 50 ) ) | if ( ( progress / 500 ) > snowFlakes.length && ( _timestamp - oldTimestamp < 50 ) ) | ||
− | snowFlakes.push( { "x" : ( Math.random( ) * width ) | 0, "y" : 0 } ); | + | snowFlakes.push( { "x" : ( Math.random( ) * width ) | 0, "y" : 0, "c" : getRndColor() } ); |
oldTimestamp = _timestamp; | oldTimestamp = _timestamp; | ||
Line 103: | Line 103: | ||
// Calculate the new position of the flake. | // Calculate the new position of the flake. | ||
// If it can't move anywhere down (3 positions): fixate it in the dynamic image and reset the flake | // If it can't move anywhere down (3 positions): fixate it in the dynamic image and reset the flake | ||
− | if | + | if ( !updateFlake( flake, dynamicImage ) ) |
{ | { | ||
// Fixate flake | // Fixate flake | ||
− | + | pixelPos = ( flake.x + width * flake.y ) * 4; | |
− | + | dynamicImage.data[ pixelPos + 0 ] = flake[0]; | |
− | + | dynamicImage.data[ pixelPos + 1 ] = flake[1]; | |
− | + | dynamicImage.data[ pixelPos + 2 ] = flake[2]; | |
− | + | dynamicImage.data[ pixelPos + 3 ] = 255; | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
// Generate new flake | // Generate new flake | ||
− | flake = { "x" : ( Math.random( ) * width ) | 0, "y" : 0 }; | + | flake = { "x" : ( Math.random( ) * width ) | 0, "y" : 0, "c" : getRndColor() }; |
} | } | ||
Line 131: | Line 124: | ||
// Draw the dynamic image | // Draw the dynamic image | ||
− | + | ctx.putImageData( dynamicImage, 0, 0 ); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
// Draw all flakes | // Draw all flakes | ||
Line 148: | Line 133: | ||
{ | { | ||
flake = snowFlakes[ nFlake ]; | flake = snowFlakes[ nFlake ]; | ||
+ | ctx.fillStyle = 'rgb(' + flake.c[0] + ',' + flake.c[1] + ',' + flake.c[2] + ')'; | ||
ctx.fillRect( flake.x, flake.y, 1, 1 ); | ctx.fillRect( flake.x, flake.y, 1, 1 ); | ||
} | } | ||
Line 181: | Line 167: | ||
window.requestAnimationFrame( snowFall ); | window.requestAnimationFrame( snowFall ); | ||
+ | } | ||
+ | |||
+ | function getRndColor() | ||
+ | { | ||
+ | // Thanks to Adafruit's NeoPixel lib | ||
+ | var wheelPos = Math.random() * 255 | 0; | ||
+ | if( wheelPos < 85 ) | ||
+ | { | ||
+ | return [ (255 - wheelPos * 3), 0, (wheelPos * 3) ]; | ||
+ | } | ||
+ | |||
+ | if( wheelPos < 170 ) | ||
+ | { | ||
+ | wheelPos -= 85; | ||
+ | return [ 0, (wheelPos * 3), (255 - wheelPos * 3) ]; | ||
+ | } | ||
+ | wheelPos -= 170; | ||
+ | return [ (wheelPos * 3), (255 - wheelPos * 3), 0 ]; | ||
} | } | ||
Line 276: | Line 280: | ||
// Check the alpha channel (apparently, our logo has opacity < 250) | // Check the alpha channel (apparently, our logo has opacity < 250) | ||
if ( _dynamicImage.data[ ( newFlake.x + width * newFlake.y ) * 4 + 3 ] > 220 ) | if ( _dynamicImage.data[ ( newFlake.x + width * newFlake.y ) * 4 + 3 ] > 220 ) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
return null; | return null; | ||
Line 359: | Line 311: | ||
buffer.height = logo.height; | buffer.height = logo.height; | ||
bufferContext = buffer.getContext('2d'); | bufferContext = buffer.getContext('2d'); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
var img = document.getElementById("img"); | var img = document.getElementById("img"); |
Revision as of 16:05, 1 March 2016
This widget creates an animated themed ACKspace logo.
Created by xopr
Using this widget
To insert this widget, use the following code:
{{#widget:Logo |image=/w/images/e/e9/ACKsmass_logo.png |width=600px |height=200px |padding=8px |float=right }}
This will give the following result:
Notes
- image is mandatory, the rest is optional.
- it also must be written without protocol since colon (:) is not allowed, and may be relative, for example: //ackspace.nl/w/images/e/e9/ACKsmass_logo.png or /w/images/e/e9/ACKsmass_logo.png
- You must provide a unit for the sizes (i.e. px, %, etc.)
Copy to your site
To use this widget on your site, just install MediaWiki Widgets extension and copy full source code of this page to your wiki as Widget:Logo article.