- Author:
- Viktor Kovacs
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- kovacsv.hu
- Compo:
- classic
- Demo link:
- https://js1k.com/2014-dragons/demo/1755
- Shortlink:
- https://js1k.com/1755
- Blog post:
- please update here!
- Bytes:
- 887
- Chars:
- 887
- Submission
function G(j,b,t,o){function e(p,z){this.x=p;this.y=z}function m(z,y,p){var x=new e(y*Math.cos(p),y*Math.sin(p));return new e(x.x+z.x,x.y+z.y)}function u(A,x,y,z,B,p){return m(m(A,x-y,B),z,p)}oc.clearRect(0,0,w,h);var l=0.017453292519943;var v=new e(w/2,h/2);var n=0;var g=0;var k=1;var q=k*(1/o);var f=u(v,j,b,t,g,n);oc.beginPath();oc.moveTo(f.x,f);for(i=0;i<=360*(1/q);i++){f=u(v,j,b,t,g,n);oc.lineTo(f.x,f.y);g-=k*l;n-=q*l}oc.stroke();c.clearRect(0,0,w,h);c.drawImage(ocn,0,0,w,h);return true}function D(){G(gr,sr,gr/3,r);r=r+s;d=r<20+s;if(d){requestAnimationFrame(D)}}window.onclick=function(){function b(g,e){return Math.floor((Math.random()*(e-g+1))+g)}r=0.1;gr=b(w/20,w/6);sr=b(w/40,w/3);if(!d){D()}};var w=a.width;var h=a.height;var d=0;var gr=w/5;var sr=gr/4;var s=0.05;var r=0.1;var ocn=document.createElement("canvas");ocn.width=w;ocn.height=h;var oc=ocn.getContext("2d");D();
- Description
- Click to generate new random shape.
- Base64 encoded
ZnVuY3Rpb24gRyhqLGIsdCxvKXtmdW5jdGlvbiBlKHAseil7dGhpcy54PXA7dGhpcy55PXp9ZnVuY3Rpb24gbSh6LHkscCl7dmFyIHg9bmV3IGUoeSpNYXRoLmNvcyhwKSx5Kk1hdGguc2luKHApKTtyZXR1cm4gbmV3IGUoeC54K3oueCx4Lnkrei55KX1mdW5jdGlvbiB1KEEseCx5LHosQixwKXtyZXR1cm4gbShtKEEseC15LEIpLHoscCl9b2MuY2xlYXJSZWN0KDAsMCx3LGgpO3ZhciBsPTAuMDE3NDUzMjkyNTE5OTQzO3ZhciB2PW5ldyBlKHcvMixoLzIpO3ZhciBuPTA7dmFyIGc9MDt2YXIgaz0xO3ZhciBxPWsqKDEvbyk7dmFyIGY9dSh2LGosYix0LGcsbik7b2MuYmVnaW5QYXRoKCk7b2MubW92ZVRvKGYueCxmKTtmb3IoaT0wO2k8PTM2MCooMS9xKTtpKyspe2Y9dSh2LGosYix0LGcsbik7b2MubGluZVRvKGYueCxmLnkpO2ctPWsqbDtuLT1xKmx9b2Muc3Ryb2tlKCk7Yy5jbGVhclJlY3QoMCwwLHcsaCk7Yy5kcmF3SW1hZ2Uob2NuLDAsMCx3LGgpO3JldHVybiB0cnVlfWZ1bmN0aW9uIEQoKXtHKGdyLHNyLGdyLzMscik7cj1yK3M7ZD1yPDIwK3M7aWYoZCl7cmVxdWVzdEFuaW1hdGlvbkZyYW1lKEQpfX13aW5kb3cub25jbGljaz1mdW5jdGlvbigpe2Z1bmN0aW9uIGIoZyxlKXtyZXR1cm4gTWF0aC5mbG9vcigoTWF0aC5yYW5kb20oKSooZS1nKzEpKStnKX1yPTAuMTtncj1iKHcvMjAsdy82KTtzcj1iKHcvNDAsdy8zKTtpZighZCl7RCgpfX07dmFyIHc9YS53aWR0aDt2YXIgaD1hLmhlaWdodDt2YXIgZD0wO3ZhciBncj13LzU7dmFyIHNyPWdyLzQ7dmFyIHM9MC4wNTt2YXIgcj0wLjE7dmFyIG9jbj1kb2N1bWVudC5jcmVhdGVFbGVtZW50KCJjYW52YXMiKTtvY24ud2lkdGg9dztvY24uaGVpZ2h0PWg7dmFyIG9jPW9jbi5nZXRDb250ZXh0KCIyZCIpO0QoKTs=
- Original source
function G (gr, sr, cr, rs) {
// a coordinate class
function C (x, y) {
this.x = x;
this.y = y;
}
// polar to cartesian conversion
function PC (c, r, a) {
var t = new C (r * Math.cos (a), r * Math.sin (a));
return new C (t.x + c.x, t.y + c.y);
}
// calculate control point location
function GCP (gc, gr, sr, cr, ra, ca) {
return PC (PC (gc, gr - sr, ra), cr, ca);
}
oc.clearRect (0, 0, w, h);
var dr = 0.017453292519943;
var gc = new C (w / 2, h / 2);
var ca = 0;
var ra = 0;
var as = 1;
var cs = as * (1.0 / rs);
var p = GCP (gc, gr, sr, cr, ra, ca);
oc.beginPath ();
oc.moveTo (p.x, p);
for (i = 0; i <= 360 * (1 / cs); i++) {
p = GCP (gc, gr, sr, cr, ra, ca);
oc.lineTo (p.x, p.y);
ra -= as * dr;
ca -= cs * dr;
}
oc.stroke ();
c.clearRect (0, 0, w, h);
c.drawImage (ocn, 0, 0, w, h);
return true;
}
// draw current frame
function D () {
G (gr, sr, gr / 3, r);
r = r + s;
d = r < 20 + s;
if (d) {
requestAnimationFrame (D);
}
}
window.onclick = function () {
// random integer between two numbers
function R (f, t) {
return Math.floor ((Math.random () * (t - f + 1)) + f);
}
r = 0.1;
gr = R (w / 20, w / 6);
sr = R (w / 40, w / 3);
if (!d) {
D ();
}
};
var w = a.width;
var h = a.height;
var d = 0;
var gr = w / 5;
var sr = gr / 4;
var s = 0.05;
var r = 0.1;
// initialize offscreen context
var ocn = document.createElement ('canvas');
ocn.width = w;
ocn.height = h;
var oc = ocn.getContext ('2d');
D ();