Javascript Fluid Simulation in 1872 Bytes

 


Click on the image above to run it.

I've made a port to Javascript of the famous Jos Stam's code from his paper "Real-Time Fluid Dynamics for Games", trying to get a nice thing to present in the great js1k.com contest.

I've reached 1872 Bytes using Closure compiler, and since almost no hand-made optimization was done yet, I think I could reach the 1024 Bytes limit, necessary to enter the contest. But I will not enter, for two reasons:

1. I don't feel this experiment visually interesting enough, and the optimizations I'd made will degrade it even more.
2. I prefer to participate in the contest with my 1024 Bytes pong. It's my original code, and not a port of someother's code.

But as usual, it really was a lot of fun! :)

 

Here is the original uncompressed code.

later! :)


--- Comments --------

Nice stuff!

I'm looking forward to working again with you! :D
Borja ~ 1 day ago

  
»Post a comment
(Tags allowed: <b> <u> <s>)

 
Write down: XOTE  

Puesta de sol en Saians



Habrá que hacer más y mejores! :) El video está disponible en HD y para descarga en Vimeo.

Actualización: Un par de fotos en plan making of, cortesía de Thai :))











--- Comments --------

que gonito ;_
Adrián (masi) ~ 28 days ago

Que chulooo!!
Al final la música queda muy bien.
Eres un geniooo!
Alberto ~ 27 days ago

gracias!
El mérito es tuyo por recomendarla :))
Diego ~ 27 days ago

Hala!! que video mas bonito que os habeis currado!! esta genial, ademas la edicion con la música esta superbien ( o a mi me lo parece) aparte de que le pega mucho.
que pasada!!
por que esta J borroso en la foto? no habia merendao?? ;b
m'encanta el carrito de la camara, es de la NASA no?
bss
gracia ~ 26 days ago

  
»Post a comment
(Tags allowed: <b> <u> <s>)

 
Write down: NIGHT  

4-sided two player pong game in 1024Bytes

js1k is a new contest in which participants have to do something in Javascript in no more than 1024 Bytes. 


I could not resist and took the bait, so I've done a 2-sided two player pong game, that you play clicking on the image:




Don't forget to check out the rest of participants, great stuff! :)

The most difficult thing was to put all the code, that initially was 2029 Bytes, to 1024 Bytes. It ended preety obfuscated:

var d=document;
var C=d.getElementById('c');
d.onkeydown=kd;
d.onkeyup=ku;
d.onmousemove=mm;
var K=[], M=Math, w=500, h=w, c= C.getContext('2d'),
t, V=0, a, H=h, O, P, A, B, J=['#8cf','#c8f'], li, v=20, z=100, G=v, E=0, r=120, n=50;
C.width=w;C.height=600;
Z(0);
window.setInterval(l, 26);
function Z(q)
{
    E+=q;
    O=P=250;
    a= M.random()*2*M.PI;
    A=M.cos(a)*5;
    B=M.sin(a)*5;
    l();
    t=30;
}
function l()
{
    if(t<=0){
    c.globalAlpha=0.4;
    f(0,0,w,600,'#fff');
    f(v,v,w-40,h-40,'#ddd');
    c.globalAlpha=1;
    f(250,h+v,E,5,J[E>0?1:0]);
   
    if (K[65]) V-=3;
    if (K[90]) V+=3;
    V= V<-v?-v:V>v?v:V;
    G+= V;
    if(G<v){ G=v; V=0;}
    if(G>h-r){ G=h-r; V=0;}
    V*=0.8;
    f(0,G,v,z,J[0]);
    f(G,0,z,v,J[0]);
   
   
    H= H<v?v:H>h-r?h-r:H;
    f(w-v,H,v,z,J[1]);
    f(H,h-v,z,v,J[1]);

    O+= A;
    P+= B;
    if (O<v || P<v) Z(v);
    if (O>w-v || P>h-v) Z(-v);
    if ((O<30 && M.abs(P-(G+n))<n) || (O>w-30 && M.abs(P-(H+n))<n)) A*=-1-M.random()*0.2;
    if ((P<30 && M.abs(O-(G+n))<n) || (P>h-30 && M.abs(O-(H+n))<n)) B*=-1-M.random()*0.2;
   
    f(O-10,P-10,v,v,'#999')
    }t--;
}
function f(y,u,i,o,x){c.fillStyle=x;c.fillRect(y,u,i,o);}
function kd(e){K[e.keyCode]=1;}
function ku(e){K[e.keyCode]=0;}
function mm(e){H=e.pageY-40;}


--- Comments --------

Hi :)
The vars can be chained (and weren't required for this compo, but good practice anyways).
The if's can be rewritten into ternary operators: `if(x)y;` to `x?y:0;` or `x&&y;`
Random could be cached (M.random()M.random()M.random() vs R='random';m[R]()m[R]()m[R]()). Same for keyCode.
I think the abs can be rewritten but I don't know that one by heart :)

Just in case you're looking to improve :)
Peter van der Zee ~ 1 month ago

Fuck, you're right!
I'll try all that, thanks! :)
Diego ~ 1 month ago

  
»Post a comment
(Tags allowed: <b> <u> <s>)

 
Write down: MARDIT  

Demo de LUXI disponible



Al fin! casi un año después de que el LUXI ganara ArtFutura, y por numerosos motivos que nos llevaron a postponer el acabado del juego, durante todo este mes de Julio le dimos duro para intentar finiquitarlo.

No está totalmente acabado, solo nos queda finalizar unas cinemáticas y acabar de pulir un par de niveles, cosa que iremos haciendo tranquilamente este mes.

Mientras, hemos enviado tres niveles de LUXI a concursar en el Concurso de Desarrolladores de IndiePubGames.com. Con los premios tan jugosos que tienen, no podíamos dejar de aprovechar la ocasión ;)

Si tienes un hueco en tu apretada agenda veraniega, te invitamos a

                            JUGAR LA DEMO DE LUXI 

(no es el juego completo, son los 3 primeros niveles), y a votarlo como favorito! :)




--- Comments --------

Votado!

Buena suerte, ahora sólo queda terminarlo!
Z ~ 1 month ago

  
»Post a comment
(Tags allowed: <b> <u> <s>)

 
Write down: BASTAR  

HTML5 Drag and Drop

Messing with HTML5 DnD for a small project of my own, I've done a little web for testing main events and its objects:


http://feiss.be/tmp/dnd_debug/

I put it online, maybe can be helpful for someone. Only tested in Chrome 6.0.472 and Firefox 4.0 b1. The fact is that you already can see lots of differences regarding DnD in both browsers... The DnD Spec it's preety nice, but having to deal with browser peculiarities it's tiring and exhausting...


--- Comments --------

It is even worse to try to use the pseudo-dnd in earlier versions of Firefox (like 3.0).
Ruben ~ 1 month ago

  
»Post a comment
(Tags allowed: <b> <u> <s>)

 
Write down: XOTE  

Un avanzao

"Cualquier persona, en mar o en tierra, con un aparato sencillo y barato que cabe en un bolsillo, podría recibir noticias de cualquier parte del mundo o mensajes particulares destinados sólo al portador, la Tierra se asemejaría, pues, a un inconmensurable cerebro, capaz de emitir una respuesta desde cualquier punto".


--Nikola Tesla (1856-1943)


--- Comments --------

Veo que te gusto la peli ;)
Mr.doob ~ 1 month ago

heh, si, esuvo bien. Un poco mala y sosa, pero tiene cosas chulas, como conocer la historia del tipo, lo mucho que se parece el actor, o mismo ver a Orson Welles.. :)
Gracias, btw!
Diego ~ 1 month ago

  
»Post a comment
(Tags allowed: <b> <u> <s>)

 
Write down: PLANET  

← Older posts


All content is Copyright 2009 Diego Fernández Goberna, unless otherwise stated.