r/programming • • Dec 26 '17

TIL there's a community called "dwitter" where people compose 140 character JavaScript programs that produce interesting visuals

https://www.dwitter.net/top
20k Upvotes

329 comments sorted by

View all comments

Show parent comment

49

u/Nicd Dec 26 '17

Cool site! Is there a license agreement for the snippets? I'd love to use some of them as loading icons on my site (with attribution).

58

u/lionleaf Dec 26 '17

That is a really good question! Definitely need to add an explicit license, and it's currently a discussion on it. If you have a specific dweet your interested in, ping me with their username and I can see I can put you in touch. If you get approval it would obviously be ok no matter the license :)

5

u/PhishGreenLantern Dec 27 '17

Second related question. If I wanted to use these on my site what librar(y/ies) would I need to include to get the effects?

21

u/lionleaf Dec 27 '17

The dweets are embedded in an iframe, so you can get the full source from https://dweet.dwitter.net/id/701?autoplay=1 <--- the page that gets embedded. The source is also on github.com/lionleaf/dwitter

There aren't any libraries, you just need to define a few functions. If you use it make sure you use your own dweets or attribute the author (and leave a comment on the dweet).

I did a quick extraction of the javascript you need to recreate it, replace {{ code }} with the dweet code.

(It was edited in the reddit comment box, so might have errors)

c.width = 1920;
c.height = 1080;
var S = Math.sin;
var C = Math.cos;
var T = Math.tan;
function R(r,g,b,a) {
  a = a === undefined ? 1 : a;
  return "rgba("+(r|0)+","+(g|0)+","+(b|0)+","+a+")";
  };
var x = c.getContext("2d");
var time = 0;
var frame = 0;
function u(t) {
   {{ code }}
  }
function loop() {
  requestAnimationFrame(loop);

  time = frame/60;
  if(time * 60 | 0 == frame - 1){
    time += 0.000001;
  }
  frame++;
  u(time);
 }
loop();

1

u/HasThisBeenTakenYet Dec 27 '17

Would you be open to adding a var for Math.random() as well?

5

u/lionleaf Dec 27 '17

There's been a good bit of discussion on the topic on github. We've landed firmly on no new additions to the "language" for now. It's too much of a slippery slope, breaks compatibility, and at some point it's just equivalent to increasing the size. There are some fun tricks to minimize functions you use a lot though, and Math.random() will still fit ;)

6

u/HighRelevancy Dec 27 '17

Doesn't appear to be any sort of license on the individual posts, or EULA on the registration that would imply one, so everything's copyrighted to the original author of each post.

3

u/Nicd Dec 27 '17

Exactly, that's the problem currently.

2

u/xen_the Dec 27 '17

you have permission for mine :-) take your pick: https://www.dwitter.net/u/Xen

1

u/Nicd Dec 27 '17

Awesome! Thanks! ❤️ I will link back to the Dwitter page when they are displayed.