(function(a){
a.fn.starBg=function(p){
var p=p||{}; var w_w=p&&p.window_width?p.window_width:"500";
var w_h=p&&p.window_height?p.window_height:"400";
var w_b=p&&p.window_background?p.window_background:"#000";
var s_c=p&&p.star_count?p.star_count:"600";
var s_color=p&&p.star_color?p.star_color:"#FFF";
var s_d=p&&p.star_depth?p.star_depth:"250";
var dom=a(this);
var fov = parseInt(s_d);
var SCREEN_WIDTH = parseInt(w_w);
var SCREEN_HEIGHT = parseInt(w_h);
var HALF_WIDTH = SCREEN_WIDTH/2;
var HALF_HEIGHT = SCREEN_HEIGHT/2;
var c_id = dom.attr("id");
var numPoints = s_c;
dom.attr({ width: w_w, height: w_h});
setup(); function setup()
{
function draw3Din2D(point3d)
{
x3d = point3d[0];
y3d = point3d[1];
z3d = point3d[2];
var scale = fov/(fov+z3d); // if(scale > 3){
// scale = (scale-3)*0.3>3?(scale-3)*0.3*0.3:(scale-3)*0.3;
//
// }
var x2d = (x3d * scale) + HALF_WIDTH;
var y2d = (y3d * scale) + HALF_HEIGHT; c.lineWidth= scale;
c.strokeStyle = s_color;
c.beginPath();
c.moveTo(x2d,y2d);
c.lineTo(x2d+scale*0.5,y2d);
c.closePath();
c.stroke(); } var canvas = document.getElementById(c_id);
var c = canvas.getContext('2d'); var points = []; function initPoints()
{
for (i=0; i<numPoints; i++)
{
point = [(Math.random()*400)-200, (Math.random()*400)-200, (Math.random()*400)-200 ];
points.push(point); } } function render()
{ c.fillStyle=w_b;
c.fillRect(0,0, SCREEN_WIDTH, SCREEN_HEIGHT); for (i=0; i<numPoints; i++)
{
point3d = points[i]; z3d = point3d[2];
z3d-=1;
if(z3d<-fov){
z3d +=400; }
point3d[2] = z3d; draw3Din2D(point3d); } } initPoints(); var loop = setInterval(function(){
render();
}, 30); } }
})(jQuery);
    $("#stars").starBg({
window_width: $(document).width(),
window_height: $(document).height(),
window_background: '#000000',
star_count: '500',
star_color: '#fff',
star_depth: '100'
});

依赖Jquery

canvas 星空插件的更多相关文章

  1. canvas星空背景特效+CSS旋转相册学习

    今天在看帖子的时候,看到了个有趣的css旋转相册,刚好之前做了一个星空背景dome,这里给大家分享下代码: 旋转相册参考:https://blog.csdn.net/gitchatxiaomi/art ...

  2. js封装成插件-------Canvas统计图插件编写

    之前就说过,我想写一个canvas画统计图的插件,现在写好了 先说下实现的功能吧: 1.可以通过自定义X轴坐标属性和Y轴坐标属性按比例画出统计图 2.可以选择画折现图还是柱形统计图,或者两者都实现 3 ...

  3. canvas星空和图形变换

    图形变换. 一.画一片星空 先画一片canvas.width宽canvas.height高的黑色星空,再画200个随机位置,随机大小,随机旋转角度的星星. window.onload=function ...

  4. HTML5 CANVAS 弹幕插件

    概述 修改了普通弹幕运动的算法,新增了部分功能 详细 代码下载:http://www.demodashi.com/demo/10595.html 修改了普通弹幕运动的算法,新增了部分功能,具体请参看附 ...

  5. 开源造轮子:一个简洁,高效,轻量级,酷炫的不要不要的canvas粒子运动插件库

    一:开篇 哈哈哈,感谢标题党的莅临~ 虽然标题有点夸张的感觉,但实际上,插件库确实是简洁,高效,轻量级,酷炫酷炫的咯.废话不多说,先来看个标配例子吧: (codepen在线演示编辑:http://co ...

  6. konva canvas插件写雷达图示例

    最近,做了一个HTML5的项目,里面涉及到了雷达图效果,这里,我将react实战项目中,用到的雷达图单拎出来写一篇博客,供大家学习. 以下内容涉及的代码在我的gitlab仓库中:Konva canva ...

  7. 13个JavaScript图表(JS图表)图形绘制插件【转】

    现在网络上又有越来越多的免费的(JS 图表)JavaScript图表图形绘制插件.我之前给一家网站做过复杂的图形,我们用的是 highchart.在那段时间,没有很多可供选择的插件.但现在不同了,很容 ...

  8. canvas剪裁图片并上传,前端一步到位,无需用到后端

    背景: 当前主流的图片剪裁主要有两种实现方式. 1:flash操作剪裁.2:利用js和dom操作剪裁. 目前看来这个剪裁主要还是先通过前端上传图片到服务器,然后前端操作后把一些坐标和大小数据传到后台, ...

  9. 关于canvas中的jquery

    关于h5,相比前端的同事们都很了解了吧!h5里面有个canvas,现在用的蛮火.但是canvas里面的代码确实是有点繁多,特别是要对于图形做什么操作的时候...我昨天无意间发现了一个canvas的插件 ...

随机推荐

  1. nginx日志打印请求响应时间

    log_format  timed_combined  '$remote_addr - $remote_user [$time_local] "$request" ' '$stat ...

  2. Spring之BeanFactory与ApplicationConText区别

    使用BeanFactory从xml配置文件加载bean: import org.springframework.beans.factory.xml.XmlBeanFactory; import org ...

  3. 百度网络监控实战:NetRadar横空出世(上)

    原文:https://mp.weixin.qq.com/s/VBShicsqReDtureKAdEgDA 转自订阅号「AIOps智能运维」,已授权运维帮转发 作者简介:运小贝,百度高级研发工程师 负责 ...

  4. 古代猪文 BZOJ 1951

    古代猪文 [问题描述] “在那山的那边海的那边有一群小肥猪.他们活泼又聪明,他们调皮又灵敏.他们自由自在生活在那绿色的大草坪,他们善良勇敢相互都关心……” ——选自猪王国民歌 很久很久以前,在山的那边 ...

  5. 【kindeditor】kindeditor的使用

    官网:http://kindeditor.net/demo.php 效果:

  6. postgresql 10 分页

    示例: select * from test limit 2 offset 2; limit:指查多少条数据 offset:从下标多少开始查,下标从0开始,不能为负数. offset计算公式: var ...

  7. js - 锚点-scrollIntoView()

    document.getElementById("view").scrollIntoView(false);

  8. Careercup | Chapter 3

    3.1 Describe how you could use a single array to implement three stacks. Flexible Divisions的方案,当某个栈满 ...

  9. c实现的trim函数

    功能:去掉字符串首尾的空格,换行符等空白. 代码: #include <string.h> #include <stdio.h> #include <ctype.h> ...

  10. UvaLive 4287 Proving Equivalences 强连通缩点

    原题链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...