• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

令人惊奇的10个HTML5和令人惊奇的JavaScript效果

JavaScript 开心洋葱 1278次浏览 0个评论

效果一:Breathing Galaxies

说明:使用键盘来改变形状中的线条样式,或移动鼠标来创建一个新的形状。

Breathing Galaxies效果如:

令人惊奇的10个HTML5和令人惊奇的JavaScript效果

在线演示地址:http://mudcu.be/labs/JS1k/BreathingGalaxies.html

代码如下:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>JS1k: Breathing Galaxies (1013 bytes)</title>
<script type="text/javascript">

/*
 Breathing Galaxies (1013 bytes)
 ——————————–
 window.onload=function(){C=Math.cos;S=Math.sin;U=0;w=window;j=document;d=j.getElementById("c");c=d.getContext("2d");W=d.width=w.innerWidth;H=d.height=w.innerHeight;c.fillRect(0,0,W,H);c.globalCompositeOperation="lighter";c.lineWidth=0.2;c.lineCap="round";var e=0,h=0;d.onmousemove=function(k){if(window.T){if(D==9){D=Math.random()*15;f(1)}clearTimeout(T)}X=k.pageX;Y=k.pageY;b=a=0;A=X;B=Y;R=(k.pageX/W*999>>0)/999;r=(k.pageY/H*999>>0)/999;U=k.pageX/H*360>>0;D=9;g=360*Math.PI/180;T=setInterval(f=function(l){c.save();c.globalCompositeOperation="source-over";if(l!=1){c.fillStyle="rgba(0,0,0,0.02)";c.fillRect(0,0,W,H)}c.restore();for(i=25;i–;){c.beginPath();if(D>450||e){e||(e=1);if(D<0.1)e=0;h-=g;D-=0.1}if(!e){h+=g;D+=0.1}q=(R/r-1)*h;x=(R-r)*C(h)+D*C(q)+(A+(X-A)*(i/25))+(r-R);y=(R-r)*S(h)-D*S(q)+(B+(Y-B)*(i/25));if(a){c.moveTo(a,b);c.lineTo(x,y)}c.strokeStyle="hsla("+U%360+",100%,50%,0.75)";c.stroke();a=x;b=y}U-=0.5;A=X;B=Y},16)};j.onkeydown=function(){a=b=0;R+=0.05};d.onmousemove({pageX:300,pageY:290})};

*/

window.onload = function () {
 C = Math.cos; // cache Math objects
 S = Math.sin;
 U = 0;
 w = window;
 j = document;
 d = j.getElementById("c");
 c = d.getContext("2d");
 W = d.width = w.innerWidth;
 H = d.height = w.innerHeight;
 c.fillRect(0, 0, W, H); // resize <canvas> and draw black rect (default)
 c.globalCompositeOperation = "lighter"; // switch to additive color application
 c.lineWidth = 0.2;
 c.lineCap = "round";
 var bool = 0,
  t = 0; // theta
 d.onmousemove = function (e) {
  if(window.T) {
   if(D==9) { D=Math.random()*15; f(1); }
   clearTimeout(T);
  }
  X = e.pageX; // grab mouse pixel coords
  Y = e.pageY;
  a=0; // previous coord.x
  b=0; // previous coord.y
  A = X, // original coord.x
  B = Y; // original coord.y
  R=(e.pageX/W * 999>>0)/999;
  r=(e.pageY/H * 999>>0)/999;
  U=e.pageX/H * 360 >>0;
  D=9;
  g = 360 * Math.PI / 180;
  T = setInterval(f = function (e) { // start looping spectrum
   c.save();
   c.globalCompositeOperation = "source-over"; // switch to additive color application
   if(e!=1) {
    c.fillStyle = "rgba(0,0,0,0.02)";
    c.fillRect(0, 0, W, H); // resize <canvas> and draw black rect (default)
   }
   c.restore();
   i = 25; while(i –) {
    c.beginPath();
    if(D > 450 || bool) { // decrease diameter
     if(!bool) { // has hit maximum
      bool = 1;
     }
     if(D < 0.1) { // has hit minimum
      bool = 0;
     }
     t -= g; // decrease theta
     D -= 0.1; // decrease size
    }
    if(!bool) {
     t += g; // increase theta
     D += 0.1; // increase size
    }
    q = (R / r – 1) * t; // create hypotrochoid from current mouse position, and setup variables (see: http://en.wikipedia.org/wiki/Hypotrochoid)
    x = (R – r) * C(t) + D * C(q) + (A + (X – A) * (i / 25)) + (r – R); // center on xy coords
    y = (R – r) * S(t) – D * S(q) + (B + (Y – B) * (i / 25));
    if (a) { // draw once two points are set
     c.moveTo(a, b);
     c.lineTo(x, y)
    }
    c.strokeStyle = "hsla(" + (U % 360) + ",100%,50%,0.75)"; // draw rainbow hypotrochoid
    c.stroke();
    a = x; // set previous coord.x
    b = y; // set previous coord.y
   }
   U -= 0.5; // increment hue
   A = X; // set original coord.x
   B = Y; // set original coord.y
  }, 16);
 }
 j.onkeydown = function(e) { a=b=0; R += 0.05 }
 d.onmousemove({pageX:300, pageY:290})
}

</script>
<style>
body { margin: 0; }
div { padding: 1px 5px; background: #333; position: absolute; z-index: 2; color: #555; font-family: arial; }
a { color: #ccf }
a:hover { color: #ff0000 }
</style>
</head>
<body>
<div><a href="http://mudcu.be/">mudcu.be</a> &rsaquo; <a href="http://mudcu.be/journal/">journal</a> &rsaquo; <a href="http://mudcu.be/journal/2010/08/what-can-1kb-of-javascript-do/">JS1k: What can 1kb of Javascript do?</a></div>

<div id="text"></div>
<canvas id="c"></canvas>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-400768-7']);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-400768-7']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script></body>
</html>

#p#副标题#e#

效果二:根据按键放置的位置不同来产生不同的单调。

Keylight效果图:

令人惊奇的10个HTML5和令人惊奇的JavaScript效果

在线观看地址:http://hakim.se/experiments/html5/keylight/03

 

效果三:Noise Field

移动鼠标来改变粒子的运动。点击随机产生参数。

效果图:

令人惊奇的10个HTML5和令人惊奇的JavaScript效果

查看: http://www.airtightinteractive.com/demos/processing_js/noisefield08.html 

 


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明令人惊奇的10个HTML5和令人惊奇的JavaScript效果
喜欢 (0)

您必须 登录 才能发表评论!

加载中……