- Author:
- Yuri Ivatchkovitch
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- sites.google.com/site/holycaffeine
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-first/demo/473
- Shortlink:
- https://js1k.com/473
- Blog post:
- please update here!
- Bytes:
- 776
- Chars:
- 776
- Submission
var b=document.body,c=b.children[0],d=c.getContext("2d"),e=c.width=innerWidth-21,f=c.height=innerHeight-21,g=e*f/810,h=[],i=Math,j=i.random,k=i.max,l=i.min,m=0,n=["sin","cos","tan"],o=i.sin,p=i.sin,q=i.abs;b.style.overflow="hidden";b.onmousedown=function(){o=i[n[j()*n.length|0]];p=i[n[j()*n.length|0]]};for(b.bgColor="#000";h.length<g;)h.push({x:j()*e|0,y:j()*f|0,a:0,b:0});setInterval(function(){d.fillStyle="rgba(0,0,0,0.01)";d.fillRect(0,0,e,f);for(m=0;m<g;m++){var a=h[m];a.x+=a.a;a.y+=a.b;a.x=q(a.x+e)%e;a.y=q(a.y+f)%f;a.b=p(a.x/25)-0.5;a.a=o(a.y/25)-0.5;var r="rgb("+(l(k(a.x/e,0),1)*255|0)+","+(l(k(a.a*a.a+a.b*a.b,0),1)*255|0)+","+(l(k(a.y/f,0),1)*255|0)+")";d.fillStyle=r;d.beginPath();d.arc(a.x,a.y,5/k(a.a*a.a+a.b*a.b,0.5),0,2*i.PI,0);d.closePath();d.fill()}},10);
- Description
- Colorful Wavy Waves.
Uses a trigonometric functions to draw shapes on screen. Click to randomize functions.
Closure compiler reduced 55% of the original code.
== update ==
Reduced from 818 to 776 bytes... 5% less.
See how the original script works @ https://sites.google.com/site/holycaffeine/home/caffeine-consequences/wavywavesjs1k-howitworks
- Base64 encoded
dmFyIGI9ZG9jdW1lbnQuYm9keSxjPWIuY2hpbGRyZW5bMF0sZD1jLmdldENvbnRleHQoIjJkIiksZT1jLndpZHRoPWlubmVyV2lkdGgtMjEsZj1jLmhlaWdodD1pbm5lckhlaWdodC0yMSxnPWUqZi84MTAsaD1bXSxpPU1hdGgsaj1pLnJhbmRvbSxrPWkubWF4LGw9aS5taW4sbT0wLG49WyJzaW4iLCJjb3MiLCJ0YW4iXSxvPWkuc2luLHA9aS5zaW4scT1pLmFicztiLnN0eWxlLm92ZXJmbG93PSJoaWRkZW4iO2Iub25tb3VzZWRvd249ZnVuY3Rpb24oKXtvPWlbbltqKCkqbi5sZW5ndGh8MF1dO3A9aVtuW2ooKSpuLmxlbmd0aHwwXV19O2ZvcihiLmJnQ29sb3I9IiMwMDAiO2gubGVuZ3RoPGc7KWgucHVzaCh7eDpqKCkqZXwwLHk6aigpKmZ8MCxhOjAsYjowfSk7c2V0SW50ZXJ2YWwoZnVuY3Rpb24oKXtkLmZpbGxTdHlsZT0icmdiYSgwLDAsMCwwLjAxKSI7ZC5maWxsUmVjdCgwLDAsZSxmKTtmb3IobT0wO208ZzttKyspe3ZhciBhPWhbbV07YS54Kz1hLmE7YS55Kz1hLmI7YS54PXEoYS54K2UpJWU7YS55PXEoYS55K2YpJWY7YS5iPXAoYS54LzI1KS0wLjU7YS5hPW8oYS55LzI1KS0wLjU7dmFyIHI9InJnYigiKyhsKGsoYS54L2UsMCksMSkqMjU1fDApKyIsIisobChrKGEuYSphLmErYS5iKmEuYiwwKSwxKSoyNTV8MCkrIiwiKyhsKGsoYS55L2YsMCksMSkqMjU1fDApKyIpIjtkLmZpbGxTdHlsZT1yO2QuYmVnaW5QYXRoKCk7ZC5hcmMoYS54LGEueSw1L2soYS5hKmEuYSthLmIqYS5iLDAuNSksMCwyKmkuUEksMCk7ZC5jbG9zZVBhdGgoKTtkLmZpbGwoKX19LDEwKTs=
- Original source
/*
Copyright (c) 2010 Yuri Ivatchkovitch - http://sites.google.com/site/holycaffeine/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
var doc = document;
var canvas = doc.getElementById( 'c' );
var context = canvas.getContext( '2d' );
var width = canvas.width = window.innerWidth - 21;
var height = canvas.height = window.innerHeight - 21;
var max_particles = width * height / 810;
var particles = [];
var math = Math;
var rnd = math.random;
var max = math.max;
var min = math.min;
var i = 0;
var functions = ['sin','cos','tan'];
var fnx = math['sin'];
var fny = math['sin'];
doc.onmousedown = function()
{
fnx = math[functions[( rnd() * functions.length ) | 0 ] ];
fny = math[functions[( rnd() * functions.length ) | 0 ] ];
};
doc.bgColor = '#000';
while ( particles.length < max_particles )
{
particles.push( { x: ( rnd() * width ) | 0, y: ( rnd() * height ) | 0, vx: 0, vy: 0 });
}
function x_movement_fn( particle )
{
return fnx( particle.y / 25 ) - 0.5;
}
function y_movement_fn( particle )
{
return fny( particle.x / 25 ) - 0.5;
}
function update( )
{
var p = particles[ i ];
p.vy = y_movement_fn( p );
p.vx = x_movement_fn( p );
p.x += p.vx;
p.y += p.vy;
if ( p.x < 0 )
{
p.x = width + p.x;
}
else if ( p.x >= width )
{
p.x -= width;
}
if ( p.y < 0 )
{
p.y = height + p.y;
}
else if ( p.y >= height )
{
p.y -= height;
}
}
function clamp_str( v )
{
return ( min( max( v, 0 ), 1 ) * 255 ) | 0;
}
function draw( )
{
var p = particles[ i ];
var c = 'rgb(' + clamp_str( p.x / width )+ ',' + clamp_str( p.vx * p.vx + p.vy * p.vy ) + ',' + clamp_str( p.y / height ) +')';
context.fillStyle = c;
context.beginPath();
context.arc( p.x, p.y, 5 / max( ( p.vx * p.vx + p.vy * p.vy ), 0.5 ), 0, 2 * math.PI, 0 );
context.closePath();
context.fill();
}
setInterval(
function()
{
context.fillStyle = 'rgba(0,0,0,0.01)';
context.fillRect( 0, 0, width, height );
for ( i = 0; i < max_particles; i++ )
{
update( );
draw( );
}
},
10
)