- Author:
- Jon Gjengset
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- thesquareplanet.com
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-first/demo/82
- Shortlink:
- https://js1k.com/82
- Blog post:
- please update here!
- Bytes:
- 1020
- Chars:
- 1020
- Submission
function b(c,g){if(c)for(var e=0;e<g.length;e++){var a=g[e],d=Math.random()*100;if(d<2){d=a.a;a.a=a.b;a.b=d}else if(d<4){d=a.a;a.a=-a.b;a.b=-d}if(a.x<=0){a.x=0;a.a=1;a.b=0}if(a.x>=c.canvas.width){a.x=c.canvas.width;a.a=-1;a.b=0}if(a.y<=0){a.y=0;a.b=1;a.a=0}if(a.y>=c.canvas.height){a.y=c.canvas.height;a.b=-1;a.a=0}c.beginPath();c.moveTo(a.x,a.y);a.x+=a.c*a.a;a.y+=a.c*a.b;c.lineTo(a.x,a.y);c.stroke();c.closePath()}}var f=window,h=document.getElementById("c");h.width=f.innerWidth;h.height=f.innerHeight;
if(h.getContext){h=h.getContext("2d");h.strokeStyle="#000000";h.lineWidth=1;for(var i=[{x:0,y:0,a:1,b:0,c:3},{x:parseInt(h.canvas.width/2),y:0,a:0,b:1,c:3},{x:h.canvas.width,y:0,a:0,b:1,c:3},{x:h.canvas.width,y:parseInt(h.canvas.height/2),a:-1,b:0,c:3},{x:h.canvas.width,y:h.canvas.height,a:-1,b:0,c:3},{x:parseInt(h.canvas.width/2),y:h.canvas.height,a:-1,b:0,c:3},{x:0,y:parseInt(h.canvas.height/2),a:0,b:-1,c:3},{x:0,y:h.canvas.height,a:0,b:-1,c:3}],j=0;j<4E3;j+=3)b(h,i);setInterval(function(){b(h,
i)},100)};
- Description
- Dynamically draws a background pattern using several traced paths
- Base64 encoded
ZnVuY3Rpb24gYihjLGcpe2lmKGMpZm9yKHZhciBlPTA7ZTxnLmxlbmd0aDtlKyspe3ZhciBhPWdbZV0sZD1NYXRoLnJhbmRvbSgpKjEwMDtpZihk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pZ2h0LzIpLGE6MCxiOi0xLGM6M30se3g6MCx5OmguY2FudmFzLmhlaWdodCxhOjAsYjotMSxjOjN9XSxqPTA7ajw0RTM7ais9MyliKGgsaSk7c2V0SW50ZXJ2YWwoZnVuY3Rpb24oKXtiKGgsDQppKX0sMTAwKX07
- Original source
var drawLength = 0;
function drawMore( context, cursors ) {
// Only draw if supported
if ( !context ) return;
for ( var i = 0; i < cursors.length; i++ ) {
var cursor = cursors[i];
var random = Math.random() * 100;
if ( random < 2 ) {
// In some cases, we start moving orthogonally one way
var temp = cursor.vx;
cursor.vx = cursor.vy;
cursor.vy = temp;
} else if ( random < 4 ) {
// In some cases, we start moving orthogonally the other way
var temp = cursor.vx;
cursor.vx = -cursor.vy;
cursor.vy = -temp;
}
if ( cursor.x <= 0 ) {
cursor.x = 0;
cursor.vx = 1
cursor.vy = 0;
}
if ( cursor.x >= context.canvas.width ) {
cursor.x = context.canvas.width;
cursor.vx = -1;
cursor.vy = 0;
}
if ( cursor.y <= 0 ) {
cursor.y = 0;
cursor.vy = 1
cursor.vx = 0;
}
if ( cursor.y >= context.canvas.height ) {
cursor.y = context.canvas.height;
cursor.vy = -1;
cursor.vx = 0;
}
context.beginPath();
context.moveTo ( cursor.x, cursor.y );
cursor.x += cursor.step * cursor.vx;
cursor.y += cursor.step * cursor.vy;
context.lineTo ( cursor.x, cursor.y );
context.stroke();
context.closePath();
}
}
var d = document;
var w = window;
var b = d.body;
var c = d.getElementById("c");
c.width = w.innerWidth;
c.height = w.innerHeight
if ( c.getContext ) {
c = c.getContext('2d');
c.strokeStyle = '#000000';
c.lineWidth = 1;
var step = 3;
var time = 100;
var quicklyUntilLength = 4000;
var cursors = [
{ x: 0, y: 0, vx: 1, vy: 0, step: step },
{ x: parseInt ( c.canvas.width / 2 ), y: 0, vx: 0, vy: 1, step: step },
{ x: c.canvas.width, y: 0, vx: 0, vy: 1, step: step },
{ x: c.canvas.width, y: parseInt ( c.canvas.height / 2 ), vx: -1, vy: 0, step: step },
{ x: c.canvas.width, y: c.canvas.height, vx: -1, vy: 0, step: step },
{ x: parseInt ( c.canvas.width / 2 ), y: c.canvas.height, vx: -1, vy: 0, step: step },
{ x: 0, y: parseInt ( c.canvas.height / 2 ), vx: 0, vy: -1, step: step },
{ x: 0, y: c.canvas.height, vx: 0, vy: -1, step: step }
];
for ( var i = 0; i < quicklyUntilLength; i += step ) {
drawMore ( c, cursors )
}
setInterval ( function(){
drawMore ( c, cursors )
}, time );
}