螺旋图形Linux,Canvas 螺旋线几何图形绘制

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

window.requestAnimFrame = (function() {

return window.requestAnimationFrame ||

window.webkitRequestAnimationFrame ||

window.mozRequestAnimationFrame ||

window.oRequestAnimationFrame ||

window.msRequestAnimationFrame ||

function(callback) {

window.setTimeout(callback, 1000 / 60);

};

})();

var scol = 'hsla(75, 5%, 95%, 1)';

function ready() {

var c = document.getElementById("canvas");

var $ = c.getContext("2d");

var w = c.width = window.innerWidth;

var h = c.height = window.innerHeight;

var graph = new Graph(c.width, c.height);

window.addEventListener('mousemove', function(e) {

graph.ms.x = e.pageX;

graph.ms.y = e.pageY;

}, false);

window.addEventListener('touchmove', function(e) {

graph.ms.x = e.touches[0].pageX;

graph.ms.y = e.touches[0].pageY;

}, false);

var draw = function() {

graph.figure();

graph.draw($);

};

run();

function run() {

window.requestAnimFrame(run);

draw();

}

}

function Graph(w, h) {

var spiro = this;

spiro.msdn = false;

spiro.ms = {

x: w / 2,

y: h / 2

};

var contC = 224;

var oc = contC / 12 + (contC * 10 / 12 * Math.random()) | 0;

var ic = oc / 12 + (oc * 10 / 12 * Math.random()) | 0;

var rat = contC / oc;

var cont = new Circle(w / 2, h / 2, contC, 0);

cont.strokeStyle = "hsla(75, 5%, 95%, 1)";

var outer = cont.i_circle(oc, 0);

var inner = outer.i_circle(ic, 0);

var loc = [];

var ang = 0;

var bAng = cont.ang;

spiro.figure = function() {

ang += 2.0;

var cAng = ang * Math.PI / 180 - bAng;

cont.set(cAng);

var oAng = -cAng * rat;

outer.set(oAng);

var p = inner.getPos();

loc.push(p);

};

spiro.draw = function($) {

$.clearRect(0, 0, w, h);

$.fillStyle = 'hsla(255,255%,2555%,1)';

$.shadowColor = 'hsla(0,0%,0%,.5)';

$.shaodwBlur = 10;

$.shadowOffsetX = 2;

$.shadowOffsetY = 2;

var ms = spiro.ms;

if (cont.graph(ms.x, ms.y)) {

$.lineWidth = 4.0;

cont.draw($);

outer.draw($);

inner.draw($);

}

$.strokeStyle = scol;

$.lineWidth = 2;

$.beginPath();

$.moveTo(loc[0].x, loc[0].y);

for (var i = 1; i < loc.length; i++) {

$.lineTo(loc[i].x, loc[i].y);

}

$.stroke();

};

}

function Circle(cx, cy, r, ang) {

var spiro = this;

spiro.parent = null;

spiro.children = null;

spiro.cx = cx;

spiro.cy = cy;

spiro.r = r;

spiro.strokeStyle = null;

spiro.fillStyle = 'hsla(255,255%,255%,.7)';

spiro.set = function(a) {

spiro.ang = a;

spiro.cos = Math.cos(spiro.ang);

spiro.sin = Math.sin(spiro.ang);

};

spiro.set(ang);

spiro.i_circle = function(ri, ai) {

var x = spiro.cos * (spiro.r - ri);

var y = spiro.sin * (spiro.r - ri);

var ci = new Circle(x, y, ri, ai);

spiro.appendChild(ci);

return ci;

};

spiro.appendChild = function(e) {

if (spiro.children === null) {

spiro.children = [];

}

e.parent = spiro;

spiro.children.push(e);

};

spiro.remove = function(e) {

var kids = spiro.children;

if (kids !== null) {

for (var i in kids) {

if (kids[i] == e) {

kids.splice(i, 1);

}

}

}

};

spiro.getPos = function() {

var x = spiro.cx;

var y = spiro.cy;

var e = spiro.parent;

while (e !== null) {

var xx = e.cx + e.cos * x - e.sin * y;

y = e.cy + e.sin * x + e.cos * y;

x = xx;

e = e.parent;

}

return {

x: x,

y: y

};

};

spiro.graph = function(x, y) {

var p = spiro.getPos();

return (p.x - x) * (p.x - x) + (p.y - y) * (p.y - y) <= spiro.r * spiro.r;

};

spiro.draw = function($) {

if (spiro.strokeStyle === null && spiro.fillStyle === null) {

return;

}

var p = spiro.getPos();

$.beginPath();

$.arc(p.x, p.y, spiro.r, 0, Math.PI * 2.0, true);

if (spiro.strokeStyle !== null) {

$.strokeStyle = spiro.strokeStyle;

$.stroke();

} else {

$.fillStyle = spiro.fillStyle;

$.fill();

}

};

}

ready();

document.getElementById('reset').onclick = ready;

window.addEventListener('resize', function() {

c.width = w = window.innerWidth;

c.height = h = window.innerHeight;

}, false);

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/272645.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

28家知名IT公司名称的由来

28家IT公司名称由来&#xff0c;你知道吗&#xff1f;EMC、VMware、IBM、Oracle、NetApp、Citrix、Cisco、Google、Amazon、Alibaba、UCloud、Tencent、Baidu等著名的存储、备份或云计算行业的IT公司&#xff0c;相信你我都是耳熟能详&#xff0c;但这些公司的名称是如何而来的…

编程应该用 Mac ,还是 PC ?

爱编程&#xff0c;不爱修电脑&#xff1b;爱学习&#xff0c;更爱运动&#xff1b;爱科技&#xff0c;也爱娱乐&#xff1b;爱工作&#xff0c;不爱加班。爱幽默、爱生活、爱浪漫、爱打拼&#xff0c;我是程序员&#xff0c;我为自己代言&#xff0c;关注程序员&#xff0c;分…

linux创建虚拟声卡,Pear BIOS 安装和配置指引

Pear BIOS 安装指引Pear BIOS是一套硬件模拟系统&#xff0c;操作系统可以在这套模拟硬件上运行。Pear BIOS可以让用户同时安装多套操作系统&#xff0c;使用时可以选择任何一套操作系统启动。在传统电脑系统上&#xff0c;操作系统可以识别并必须识别硬件&#xff1b;而在这套…

左右值

C/C语言中可以放在赋值符号左边的变量&#xff0c;即具有对应的可以由用户访问的存储单元&#xff0c;并且能够由用户去改变其值的量。左值表示存储在计算机内存的对象&#xff0c;而不是常量或计算的结果。或者说左值是代表一个内存地址值&#xff0c;并且通过这个内存地址&am…

关于 ASP.NET 内存缓存你需要知道的 10 点

缓存机制的主要目的是提高应用程序的性能。作为 ASP.NET 开发人员&#xff0c;你可能会意识到 ASP.NET Web 窗体以及 ASP.NET MVC 可以使用 Cache 对象缓存应用程序的数据。这通常被称为服务器端数据缓存&#xff0c;并且常作为框架的内置功能。虽然 ASP.NET Core 中并没有这样…

linux git删除的文件怎么还原,从Git仓库中恢复已删除的分支、文件或丢失的commit...

从Git仓库中恢复已删除的分支、文件或丢失的commit在使用Git的过程中&#xff0c;有时可能会有一些误操作比如&#xff1a;执行checkout -f 或 reset -hard 或 branch -d删除一个分支结果造成本地(远程)的分支或某些commit丢失可以通过reflog来进行恢复&#xff0c;前提是丢失的…

两张趣图助你理解状态码的含义~

HTTP状态码&#xff08;HTTP Status Code&#xff09;是用以表示网页服务器HTTP响应状态的3位数字代码。我们可以通过查看HTTP状态码来判断服务器状态&#xff0c;常见的有404 、502等&#xff1b;但是其他不是很常见的状态码都代表什么状态呢&#xff1f;下面有两张有趣的图片…

java 自定义注解以及获得注解的值

1.自定义注解 import java.lang.annotation.*;Documented Target(ElementType.FIELD) Inherited Retention(RetentionPolicy.RUNTIME ) public interface MyAnno {/*** 是否能为null* return*/boolean isCanNull() default true;/*** 是否能为空字符串* return*/boolean isCanE…

linux列出管道,lsof列出的管道列表示什么意思?_linux_开发99编程知识库

文件不僅以流形式打開。 其中一些是在 lsof 手冊中列出的&#xff1a;FD is the File Descriptor number of the file or:cwd current working directory;Lnn library references (AIX);err FD information error (see NAME column);jld jail directory (FreeBSD);ltx shared l…

CSS一些实用的技巧

css 字体简写规则当使用css定义字体时你可能会这样做&#xff1a;font-size: 1em;line-height: 1.5em;font-weight: bold;font-style: italic;font-variant: small-caps;font-family: verdana,serif;事实上你可以简写这些属性&#xff1a;font: 1em/1.5em bold italic small-ca…

linux openssh升级8.1,Centos7利用rpm升级OpenSSH到openssh-8.1p1版本

由于近期安全事故频发&#xff0c;打算把机器OpenSSH升级到最新版本&#xff0c;找了一圈&#xff0c;发现分享的rpm包就到7.4版本&#xff0c;最新版已经到8.1.p1&#xff0c;所以博客自编译一个openssh-8.1p1的rpm包进行分享。检查环境&#xff1a;[roottest]# ssh -VOpenSSH…

《HTTP权威指南》 – 11.验证码和新鲜度

服务器应当告知客户端能够将内容缓存多长时间&#xff0c;在这个时间内就是新鲜的。服务器可以用这两个首部之一来提供信息&#xff1a; Expires&#xff08;过期&#xff09;Cache - Control&#xff08;缓存控制&#xff09;Expires首部 规定文档“过期”的具体时间&#xff…

产品经理必备神器推荐

欢迎关注我的公众号&#xff08;同步更新文章&#xff09;&#xff1a;DoNet技术分享平台阅读原文工欲善其事&#xff0c;必先利其器&#xff0c;作为最追求极致体验的产品经理群体&#xff0c;手里有一件趁手的法器&#xff0c;工作起来才会有一种享受般的快感&#xff0c;最近…

野火linux底板设计,野火STM32F767套件(底板+核心板)

一、兑换形式1、电子芯吧客注册用户均可通过免费申请与硬件兑换两种方式进行申请试用2、免费申请形式为用户通过分享试用活动至好友&#xff0c;换取申请板卡一次试用资格3、硬件兑换方式为用户捐赠一块闲置板卡至电子芯吧客&#xff0c;换取申请板卡一次试用资格4、免费申请渠…

c++ builder xe2 (Embarcadero rad studio) 远程调试 同样适用于 delphi 远程调试 教程

c builder xe2 &#xff08;Embarcadero rad studio&#xff09; 远程调试 同样适用于 delphi 远程调试 教程转载于:https://www.cnblogs.com/LittleTiger/p/5039245.html

JS关闭浏览器 (不弹出提示框)

如果网页不是通过脚本程序打开的&#xff08;window.open()&#xff09;&#xff0c;调用window.close()脚本关闭窗口前&#xff0c;必须先将window.opener对象置为null&#xff0c;否则浏览器&#xff08;IE7、IE8&#xff09;会弹出一个确定关闭的对话框。&#xff1c;script…

天大18年c语言离线作业,天大18秋C语言程序设计在线作业一辅导资料.docx-资源下载在线文库www.lddoc.cn...

天大18秋《C语言程序设计》在线作业一辅导资料.docx天大 18 秋C 语言程序设计 在线作业一1、C 2、D 3、D 4、D 5、D 一、单选题共 40 题&#xff0c;100 分1、设有int a 31,0,3,3,4,5,6,7;,则 a21的值是 A3B5C6D4正确答案是C2、设 int a21,b021; 语句 printf“x,dn”,a,b;的输出…

AM335x(TQ335x)学习笔记——GPIO关键驱动移植

或按照S5PV210学习秩序。我们首先解决的关键问题。TQ335x有六个用户按钮&#xff0c;每个上、下、剩下、对、Enter和ESC。我想开始学习S5PV210当同一&#xff0c;写输入子系统驱动器的关键问题要解决&#xff0c;但浏览driver/input/keyboardgpio-keys.c&#xff0c;大体上看下…

程序员偷偷深爱的9个不良编程习惯

新媒体管家下面这9个编码习惯&#xff0c;虽然在编程规则中是被驳斥的&#xff0c;但我们很多人就是会不由自主地使用它们。我们曾经都做过这样的事情&#xff1a;当妈妈不注意的时候&#xff0c;偷偷地吃糖果零食&#xff0c;然后导致有了蛀牙。同样的&#xff0c;我们都违背过…

emacs c语言 自动补全,Emacs 与 C/C++ 代码自动补全

基于 Emacs 的 company 模式并配合 semantic 文法分析器&#xff0c;实现 Emacs 的 C/C 代码自动补全。关于 Emacs 的代码自动补全代码自动补全的功能&#xff0c;对于使用 Emacs 写代码的程序员而言其重要性不言而喻的&#xff0c;但是搜了一些所谓的 “Emacs 完美的 C 自动补…