Loading...
Logo
Processing Forum

mesh dance tiny

in Programming Questions  •  2 years ago  
Hi guys, there's one tiny  sketch I came across on openprocessing.org recently.
It runs quite smooth from openprocessing site, but not if I copy code to p5.
It was written for tiny sketch competition, so bitcraft(author) used some funky shortcut techniques here.
Could please someone explain what is going along these lines?

I'm guessing there are several bit-to-bit operations... but the "for" loop is just frightening me ))

Copy code
  1. int b,i,t,d,a,n,c,e;
    void draw(){n=key&63;for(background(i=0);i++<n*n;stroke(-1,e+=n-dist(a=f(),b=f(),c=f(),d=f())-e))if(e>0)line(a,b,c,d);}int f(){return int(500*noise(t++%4>1?i/n:i%n,t%2*n+t/1E6));}

Replies(2)

Re: mesh dance tiny

2 years ago

I cannot disentangle the code right now but if you copy the code in the form below into the Processing editor,
it should work.

Andreas

Copy code
  1. int b,i,t,d,a,n,c,e;
  2. void setup(){
  3.   size(500,500);
  4. }
  5. void draw() {
  6.   n=key&63;
  7.   for(background(i=0);i++<n*n;stroke(-1,e+=n-dist(a=f(),b=f(),c=f(),d=f())-e))
  8.     if(e>0)
  9.       line(a,b,c,d);
  10. }

  11. int f() {
  12.   return int(500*noise(t++%4>1?i/n:i%n,t%2*n+t/1E6));
  13. }

Re: mesh dance tiny

2 years ago
I'll be trying to sort it out piece by piece.
Copy code
  1. n=key&63;
ok, they avoid using keyPressed(), because 'key' variable always keeps the last pressed character on keyboard.
I wonder if &63 part is just the way to make an int from char?
Copy code
  1. for(background(i=0);i++<n*n;
does the i++ in this case happen every cycle the loop has? 
Copy code
  1. stroke(-1,e+=n-dist(a=f(),b=f(),c=f(),d=f())-e))
stroke(-1) is the same as stroke(255) I guess. 

That's how much I got so far. the most tricky is the f() function.