Advertisement
mateon1

McCollough effect

May 17th, 2015
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; // Mateon1 x Semicolon
  2.  
  3. if (window.ran) throw "Don't run this multiple times, you'll break it!";
  4. window.ran = true;
  5.  
  6. (function(){
  7.  
  8. document.body.innerHTML="Look at the reference image first.<br>After you're done, look at the center-ish of the changing image. You can blink and move your eyes a little bit, but don't move in relation to your screen.<br><br>After the time (6 minutes 30 seconds) passes, you will be shown the reference image again. It should have a tint near the bars.<br>This is NOT a persistence of view illusion. This effect can stay for a longer amount of time. <a href='https://en.wikipedia.org/wiki/McCollough_effect'>More info on the Wikipedia page for the McCollough effect.</a><br>";
  9. document.head.innerHTML = "<style>canvas{display:block;margin-left:70px;margin-right:50px;float:left}</style>";
  10. document.body.appendChild(canvas = document.createElement("canvas"));
  11. document.body.appendChild(timerD = document.createElement("div"));;;;
  12.  
  13. function timer(initial, now, duration) {
  14.   if(now-initial-duration>0)return timerD.innerHTML="<pre>Time's up!</pre>";
  15.   timerD.innerHTML = "<pre>TIMER:<br>Start: "+new Date(initial)+"<br>Now:   "+new Date+"<br>---<br>Seconds passed/total:"+((now-initial)/1000).toFixed(2)+"/"+duration/1000+"<br>Left:"+((duration-now+initial)/1000)+"<br>Percentage:"+((now-initial)/duration*100).toFixed(2)+"%</pre>"
  16. }
  17.  
  18. size = 600;
  19. canvas.width=canvas.height=size + 10;
  20. ctx = canvas.getContext("2d");
  21. mins = 6.5;
  22. interval = 6
  23. gap = 5;
  24.  
  25.  
  26. function drawTest() {
  27.   ctx.clearRect(0,0,size+20,size+20);
  28.   ctx.fillStyle = "black";
  29.   for (var i = 0; i < size/2-gap; i += 2*interval) {
  30.     ctx.fillRect(i+5,0+5,interval,size/2-gap);
  31.     ctx.fillRect(i+size/2+gap+5,size/2+gap+5,interval,size/2-gap);
  32.     ctx.fillRect(size/2+gap+5,i+5,size/2-gap,interval);
  33.     ctx.fillRect(0+5,i+size/2+gap+5,size/2-gap,interval);
  34.   }
  35. }
  36.  
  37. function drawActivator(color,orientation) {
  38.   ctx.fillStyle = "black";
  39.   ctx.fillRect(0,0,size+20,size+20);
  40.   ctx.fillStyle=color;
  41.   for (var i = 0; i < size; i += 2 * interval) {
  42.     if (orientation) ctx.fillRect(i+5, 5, interval, size);
  43.     else             ctx.fillRect(5, i+5, size, interval);
  44.   }
  45. }
  46.  
  47. drawTest();
  48. var start = Date.now(), last = 0;
  49. setTimeout(function loop(){
  50.   if (Date.now() > start + mins * 60 * 1000) return drawTest();
  51.   drawActivator(["#2e2","red"][last],last=(last+1)&1);
  52.   setTimeout(loop, 3000)
  53. }, 10000);
  54. requestAnimationFrame(function t(){requestAnimationFrame(t);timer(start,Date.now(),mins*60000);})
  55. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement