精彩:JS画的图形[Good篇] (转)

精彩:JS画的图形[Good篇] (转)[@more@]

<!--
如果您想在线看看效果:.NET/test/2.htm">http://m9m.nease.net/test/2.htm
--&gt
XMLns:v="urn:schemas-microsoft-com:vml">


test

style="position:relative;WIDTH:800px;HEIGHT:600px;top:0;left:0;"

CoordOrig="-500,-500" coordsize="1000,1000">



function line(x, y, x1, y1, n)
{
  document.write("

(x1 - n) + "," + y1 + "" style="position:relative;top:-80;left:-50;z

-index:9999;" strokeweight="1pt">

");
  //  StrokeColor=Rgb("" + Math.round(Math.ran dom() * 255 ) + "," +

Math.round(Math.random() * 255) + "," + Math.round(Math.random() * 255

) +")
}

var i, j, a;
var length = 1000;  // 方块边长
var n = 60, theta = 3;  // 每个方块里画子方块的个数,偏移角度值
var x = 300, y = 300;  // 原始坐标位置
var py = 800;  // x 偏移值

function polygonc(x0, y0, r, n, af)
{
  var x, y, xs, ys, i, dtheta, theta;

  if(n < 3)return;
  dtheta = 6.28318 / n;
  theta = af * 0.0174533;
  xs = x0 + r * Math.cos(theta);
  ys = y0 + r * Math.sin(theta);
  var xo = xs, yo = ys;
  for ( i = 1; i < n; i++)
  {
  theta += dtheta;
  x = x0 + r * Math.cos(theta);
  y = y0 + r * Math.sin(theta);
  line(xs, ys, x, y, py);
 xs = x;
 ys = y;
  }
  line(xs, ys, xo, yo, py);
}

function block(x, y, a, n, theta)
{
  var x0, y0, i, r, t, f, af = 45;
  t = Math.abs(theta * 0.0174533);
  f = 1 / (Math.cos(t) + Math.sin(t));
  r = a / 1.414;
  x0 = x + 0.5 * a;
  y0 = y + 0.5 * a;
  for (i = 1; i <= n; i++)
  {
  polygonc(x0, y0, r, 4, af);
  r = r * f;
  af -= theta;
  }
}

a = length /4;
for (i = 1; i <= 4; i++)
{
  for (j = 1; j <= 4; j++)
  {
  block(x, y, a, n, theta);
  theta = 0 - theta;
  x += a;
  }
  x = 300;
  y -= a;
  theta = 0 - theta
}






来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-962284/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10752043/viewspace-962284/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值