Skip to content

Instantly share code, notes, and snippets.

@nyango
Created November 21, 2013 08:37
Show Gist options
  • Save nyango/7577970 to your computer and use it in GitHub Desktop.
Save nyango/7577970 to your computer and use it in GitHub Desktop.
forked: リサージュ天使/ローレンツ方程式
fork楽しい!!
http://jsdo.it/jag/8Alz/
* {
margin: 0;
padding: 0;
border: 0;
}
body {
background: #dff;
font: 30px sans-serif;
}
<canvas id="world"></canvas><br>
<input type="button" onclick="kaisi()" id="stb" value="スタート" />
<div id="coudiv"></div>
// forked from jag's "forked: リサージュ天使" http://jsdo.it/jag/rycU
// forked from jagarikin's "リサージュ天使" http://jsdo.it/jagarikin/g2S2
var can,ctx,kari,gime,gmax,isstart,timer,gx,gy,gX,gY;
var gr1,gr2,gr3,gr4,gr5,gr6;
(function(){
canvas=document.getElementById("world");
ctx=canvas.getContext("2d");
canvas.width=400;
canvas.height=400;
ctx.fillStyle="rgb(0,0,0)";
ctx.fillRect(0,0,400,400);
gime=ctx.getImageData(0,0,400,400);
init();
jaga(50000);
imeset();
ctx.putImageData(gime,0,0);
})();
function init(){
var a;
gmax=0;
gx=gy=gz=gZ=gX=gY=gr1=gr2=gr3=gr4=gr5=gr6=0;
kari=[];
for(a=0;a<400;a++){
kari[a]=new Float32Array(400*3);
}
}
function imeset(){
var a,b,c,d,iti,miti,ki;
ki=70000/gmax;
iti=0;
for(a=0;a<400;a++){
for(b=0;b<400;b++){
for(c=0;c<3;c++){
d=Math.floor(kari[a][b*3+c]*ki);
if(d>255)d=255;
gime.data[iti+c]=d;
}
iti+=4;
}
}
}
function kaisi(ev){
var a;
a=document.location+"";
a=a.split("/")[3];
if(a!="jagarikin" && ev!=1){
window.open("http://jsdo.it/jagarikin/g2S2");
return;
}
if(isstart==1){
isstart=0;
return;
}
document.getElementById("stb").value="ストップ";
isstart=1;
init();
timer=setTimeout(ruup,0);
}
function ruup(){
var a;
clearTimeout(timer);
if(isstart===0){
document.getElementById("stb").value="スタート";
return;
}
timer=setTimeout(ruup,16);
a=100;
if(gmax>=100000)a=1000;
if(gmax>=1000000)a=10000;
jaga(a);
imeset();
ctx.putImageData(gime,0,0);
if(gmax>=10000000)isstart=0;
}
function jaga(max){
var a,b,c,d,e,p,r;
var x,y,z,X,Y,Z,r1,r2,r3,r4,r5,r6,sin,cos,abs,pow,pai2,col,dx,dy,dz;
sin=Math.sin;cos=Math.cos;abs=Math.abs;pow=Math.pow;pai2=Math.PI*2;
col=[[255,105,15],[255,105,15],[255,225,113]];
x=gx;y=gy;z=gz;X=gX;Y=gY+0.01;Z=gZ-1;r1=gr1;r2=gr2;r3=gr3;r4=gr4;r5=gr5;r6=gr6;
p=10;r=28;
for(kai=0;kai<max;kai++){
r1-=0.2;r2+=0.3;r3+=2.1111;r4+=3;r5-=1.6;r6-=0.6;
dx = -p*X + p*Y;
dy = -X*Z + r*X - Y;
dz = X*Y - Z;
x=X+0.001*dx;
y=Y+0.001*dy;
z=Z+0.001*dz;
d=gra(Math.atan2(X-x,Y-y)/pai2,col);
b=x*10+200;
c=y*10+200;
ten1(b,c,d[0],d[1],d[2]);
X=x;Y=y;Z=z;
}
gx=x;gy=y;gz=z;gX=X;gY=Y;gZ=Z;gr1=r1;gr2=r2;gr3=r3;gr4=r4;gr5=r5;gr6=r6;
gmax+=max;
document.getElementById("coudiv").innerHTML="点描画数:"+gmax;
}
function ten1(x,y,c1,c2,c3){
var mx,x1,y1,x2,y2;
mx=Math.floor(x);
x2=x-mx;
x1=1-x2;
my=Math.floor(y);
y2=y-my;
y1=1-y2;
pp(mx,my,x2*y2);
pp(mx+1,my,x1*y2);
pp(mx,my+1,x2*y1);
pp(mx+1,my+1,x1*y1);
function pp(px,py,bai){
if(px<0 || px>=400 || py<0 || py>=400)return;
px*=3;
kari[py][px]+=c1*bai;
kari[py][px+1]+=c2*bai;
kari[py][px+2]+=c3*bai;
}
}
function gra(atai,col){
var a,b,c;
atai=atai%1;
if(atai<0)atai+=1;
atai*=col.length;
a=atai%1;
a=0.5-Math.cos(a*Math.PI)/2;
b=1-a;
c=Math.floor(atai)%col.length;
d=(c+1)%col.length;
c1=col[c][0]*b+col[d][0]*a;
c2=col[c][1]*b+col[d][1]*a;
c3=col[c][2]*b+col[d][2]*a;
return [c1,c2,c3];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment