- Author:
- Scriptin
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- dmitry-scriptin.blogspot.com
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-first/demo/625
- Shortlink:
- https://js1k.com/625
- Blog post:
- please update here!
- Bytes:
- 988
- Chars:
- 988
- Submission
var c = document.getElementById('c'),
$ = c.getContext('2d'),
_ = [],
s = 300,
m = Math,
l = 40,
n = 20;
m.r = m.random;
c.width = s;
c.height = s;
$.fillStyle = '#000';
$.lineWidth = 13;
function x() {
return m.floor(m.r()*255.9);
}
function Tile() {
var a = m.r()*2;
return {
t: +new Date(),
c: 'rgba('+x()+','+x()+','+x()+',',
w: 0.1,
l: (1+m.r())/3,
s: a,
z: a,
r: m.r()
};
}
for (var i=0; i<l; i++) _[i] = new Tile();
setInterval(function() {
var t = +new Date(),
h = s/2,
r = m.sqrt(s*h),
p = 1/n;
$.fillRect(0,0,s,s);
for (var i=0; i<l; i++) {
var a = _[i],
d = (a.s + 0.0015*(t-a.t)) % 2;
a.z = d - 1;
}
for (var o=p; o<=1; o+=p) {
for (var i=0; i<l; i++) {
if ((o>_[i].z) && (_[i].z+_[i].l>o)) {
var a = _[i],
e = 2*m.PI*a.r;
$.strokeStyle = a.c+o+')';
$.beginPath();
$.arc(h,h,r*o,e,e-2*m.PI*a.w,true);
$.stroke();
}
}
}
}, 1000/35);
- Description
- supposed to be a simulation of flight through illuminated tunnel =)
- Base64 encoded
dmFyIGMgPSBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgnYycpLA0KCSQgPSBjLmdldENvbnRleHQoJzJkJyksDQoJXyA9IFtdLA0KCXMgPSAzMDAsDQoJbSA9IE1hdGgsDQoJbCA9IDQwLA0KCW4gPSAyMDsNCm0uciA9IG0ucmFuZG9tOw0KYy53aWR0aCA9IHM7DQpjLmhlaWdodCA9IHM7DQokLmZpbGxTdHlsZSA9ICcjMDAwJzsNCiQubGluZVdpZHRoID0gMTM7DQo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('2d'),
_ = [], // tiles
s = 300, // size 300x300
m = Math,
l = 40, // # of tiles
n = 20; // # of circles
m.r = m.random;
c.width = s;
c.height = s;
$.fillStyle = '#000';
$.lineWidth = 13;
// random 0..255
function x() {
return m.floor(m.r()*255.9);
}
// tile class
function Tile() {
var a = m.r()*2;
return {
t: +new Date(), // creatin time
c: 'rgba('+x()+','+x()+','+x()+',', // color w/o alpha channel
w: 0.1, // width
l: (1+m.r())/3, // length
s: a, // start position (depth)
z: a, // current position (depth)
r: m.r() // position (radial)
};
}
// generating tiles
for (var i=0; i<l; i++) _[i] = new Tile();
// main
setInterval(function() {
var t = +new Date(), // current time
h = s/2, // half of size
r = m.sqrt(s*h), // max radius
p = 1/n; // step = 1 / # circles
$.fillRect(0,0,s,s); // background
for (var i=0; i<l; i++) {
var a = _[i],
d = (a.s + 0.0015*(t-a.t)) % 2; // 0.0015 - speed
a.z = d - 1; // new position, start from -1
}
for (var o=p; o<=1; o+=p) { // depth and opacity
for (var i=0; i<l; i++) {
if ((o>_[i].z) && (_[i].z+_[i].l>o)) {
var a = _[i],
e = 2*m.PI*a.r;
$.strokeStyle = a.c+o+')'; // + opacity
$.beginPath();
$.arc(h,h,r*o,e,e-2*m.PI*a.w,true); // draw it!
$.stroke();
}
}
}
}, 1000/35); // 35 fps max