- Author:
- Yuri Ivatchkocitch
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- sites.google.com/site/holycaffeine
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-first/demo/601
- Shortlink:
- https://js1k.com/601
- Blog post:
- please update here!
- Bytes:
- 1024
- Chars:
- 1024
- Submission
c=(b=document.body).children[0],d=c.getContext("2d"),g=(e=c.width=innerWidth)*(f=c.height=innerHeight)/810,h=[],j=(i=Math).random,k=i.max,l=i.min,n=[o=p=i.sin,i.cos,i.tan,function(x){return 1},function(x){return g/(x*x)},function(x){return n[1]((new Date()).getTime()/1e11)},function(x){return 5/(x%5)},function(x){return g/(x*25-g)},function(x){return g/(x*25-e/2)},function(x){return x%4>2?1:-1},function(x){return 1/n[0](x)},function(x){return n[0](x)*n[2](x/5)},function(x){return n[0](x)*n[9](x)}],u=v=1;b.style.overflow="hidden";b.onmousedown=function(){o=n[j()*13|0];p=n[j()*13|0],u=j()>.5?1:-1,v=j()>.5?1:-1};for(b.bgColor='#000';h.length<g;)h.push({x:j()*e,y:j()*f,a:0,b:0});setInterval(function(){d.fillStyle="rgba(0,0,0,.02)";d.fillRect(0,m=0,e,f);for(;m<g;++m){with(h[m]){x=(x+e+(a=o(y/25)-.5)*u)%e;y=(y+f+(b=p(x/25)-.5)*v)%f;d.fillStyle="rgba("+(l(k(x/e,0),1)*255|0)+","+(l(k(a*a+b*b,0),1)*255|0)+","+(l(k(y/f,0),1)*255|0)+",.5)";d.beginPath();d.arc(x,y,5/k(a*a+b*b,.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-howitwork
== update ==
Reduced from 776 to 661 bytes... 14% less =D
Intense manual work.
== update ==
Reduced to 650 with manual improvements
http://sites.google.com/site/holycaffeine/home/caffeine-consequences/javascriptmicrofication
== update ==
Used the remaining bytes to create new formulas - total of 13.
It can generate 676 different patterns (if I still remember combinatorics).
- Base64 encoded
Yz0oYj1kb2N1bWVudC5ib2R5KS5jaGlsZHJlblswXSxkPWMuZ2V0Q29udGV4dCgiMmQiKSxnPShlPWMud2lkdGg9aW5uZXJXaWR0aCkqKGY9Yy5oZWlnaHQ9aW5uZXJIZWlnaHQpLzgxMCxoPVtdLGo9KGk9TWF0aCkucmFuZG9tLGs9aS5tYXgsbD1pLm1pbixuPVtvPXA9aS5zaW4saS5jb3MsaS50YW4sZnVuY3Rpb24oeCl7cmV0dXJuIDF9LGZ1bmN0aW9uKHgpe3JldHVybiBnLyh4KngpfSxmdW5jdGlvbih4KXtyZXR1cm4gblsxXSgobmV3IERhdGUoKSkuZ2V0VGltZSgpLzFlMTEpfSxmdW5jdGlvbih4KXtyZXR1cm4gNS8oeCU1KX0sZnVuY3Rpb24oeCl7cmV0dXJuIGcvKHgqMjUtZyl9LGZ1bmN0aW9uKHgpe3JldHVybiBnLyh4KjI1LWUvMil9LGZ1bmN0aW9uKHgpe3JldHVybiB4JTQ+Mj8xOi0xfSxmdW5jdGlvbih4KXtyZXR1cm4gMS9uWzBdKHgpfSxmdW5jdGlvbih4KXtyZXR1cm4gblswXSh4KSpuWzJdKHgvNSl9LGZ1bmN0aW9uKHgpe3JldHVybiBuWzBdKHgpKm5bOV0oeCl9XSx1PXY9MTtiLnN0eWxlLm92ZXJmbG93PSJoaWRkZW4iO2Iub25tb3VzZWRvd249ZnVuY3Rpb24oKXtvPW5baigpKjEzfDBdO3A9bltqKCkqMTN8MF0sdT1qKCk+LjU/MTotMSx2PWooKT4uNT8xOi0xfTtmb3IoYi5iZ0NvbG9yPScjMDAwJztoLmxlbmd0aDxnOyloLnB1c2goe3g6aigpKmUseTpqKCkqZixhOjAsYjowfSk7c2V0SW50ZXJ2YWwoZnVuY3Rpb24oKXtkLmZpbGxTdHlsZT0icmdiYSgwLDAsMCwuMDIpIjtkLmZpbGxSZWN0KDAsbT0wLGUsZik7Zm9yKDttPGc7KyttKXt3aXRoKGhbbV0pe3g9KHgrZSsoYT1vKHkvMjUpLS41KSp1KSVlO3k9KHkrZisoYj1wKHgvMjUpLS41KSp2KSVmO2QuZmlsbFN0eWxlPSJyZ2JhKCIrKGwoayh4L2UsMCksMSkqMjU1fDApKyIsIisobChrKGEqYStiKmIsMCksMSkqMjU1fDApKyIsIisobChrKHkvZiwwKSwxKSoyNTV8MCkrIiwuNSkiO2QuYmVnaW5QYXRoKCk7ZC5hcmMoeCx5LDUvayhhKmErYipiLC41KSwwLDIqaS5QSSwwKTtkLmNsb3NlUGF0aCgpO2QuZmlsbCgpfX19LDEwKQ==
- 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
)