- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
本质上,我希望构建这样的东西:
http://themes.pixelworkshop.fr/?theme=CircularCountdownPlugin
我正在制作一个类似的倒计时时钟,其中有两个弧形相互重叠 - 一个是完整的圆圈,另一个是另一种颜色的弧形,它位于第一个弧形的顶部并不断增长和缩小以显示时间左边。 (我决定不使用这个实际的插件,因为我的时钟在计算和显示时间方面的功能会有所不同)
通过重新利用另一个问题的代码:
var redArc = new Kinetic.Shape({
drawFunc: function (canvas) {
var ctx = canvas.getContext();
ctx.beginPath();
ctx.arc(x, y, r, 0, Math.PI / 2, true);
canvas.fillStroke(this);
},
x: x,
y: y,
stroke: 'rgb(255,0,0)',
strokeWidth: 20,
offset: [x, y]
});
我能够画出我需要的弧线。但我无法弄清楚如何为其中一个弧形的变化大小设置动画(增加或缩小“蛇”的长度)(注意这个例子并没有准确地显示我正在尝试做的事情,但它很接近足够的 b/c 它准确地显示了我想要设置动画以增长和收缩的弧线类型)
感谢您的帮助!
最佳答案
此函数会将时钟秒数转换为您可以在弧中使用的弧度:
// zero seconds (the 12 oclock position)
var startingAngle = secondsToRadians(0);
// get the current seconds and its associated radian angle
var currentSeconds=new Date().getSeconds();
var endingAngle = secondsToRadians(currentSeconds);
function secondsToRadians(seconds) {
var degrees=(seconds-15)*6;
var radians=(degrees * Math.PI)/180;
return(radians);
}
这是代码和 fiddle :http://jsfiddle.net/m1erickson/BR6TY/
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> <!-- reset css -->
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<style>
body{ background-color: ivory; }
canvas{border:1px solid red;}
</style>
<script>
$(function(){
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
var centerX = Math.floor(canvas.width / 2);
var centerY = Math.floor(canvas.height / 2);
var radius = Math.floor(canvas.width / 3);
var startingAngle = secondsToRadians(0);
ctx.fillStyle = "#819FF0";
ctx.strokeStyle="black";
ctx.lineWidth=3;
ctx.font="24px Verdana";
setInterval(function() {
// draw the arc about every second
// set the arc to reflect the actual clock seconds
drawClockWedge( new Date().getSeconds() );
}, 1000);
function drawClockWedge(seconds){
// clear the canvas
ctx.save();
ctx.clearRect(0,0,canvas.width,canvas.height);
// calculate the seconds (in actual time)
// and convert to radians that .arc requires
var endingAngle = secondsToRadians(seconds);
// draw a closed arc representing elapsed seconds
ctx.beginPath();
ctx.moveTo(centerX, centerY);
ctx.arc(centerX, centerY, radius, startingAngle, endingAngle, false);
ctx.closePath();
ctx.fill();
ctx.stroke();
// also display the seconds on top
ctx.fillText("["+seconds+"]",centerX-25,centerY-radius-20);
ctx.restore();
}
function secondsToRadians(seconds) {
var degrees=(seconds-15)*6;
var radians=(degrees * Math.PI)/180;
return(radians);
}
}); // end $(function(){});
</script>
</head>
<body>
<canvas id="canvas" width=300 height=300></canvas>
</body>
</html>
关于javascript - 如何使用 Kinetic js/html5 为弧形设置动画,以便 "snake"变长?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16740871/
我遇到了一个(至少对我而言)非常的奇怪情况。 我正在尝试重写蛇,并且移动进行得非常顺利,只有蛇在吃自己,虽然我正在删除 1 段并添加 1 (x + 1 - 1 = x?) 但是蛇消失了,而 Array
这个问题已经有答案了: NoClassDefFoundError: wrong name (8 个回答) 已关闭10 年前。 所以我正在尝试构建一个 2D 贪吃蛇游戏,而且我快完成了。我唯一的问题是,
我最近也一直在尝试做一个绘图墙,或者让这个游戏的蛇穿墙,但我不知道如何编程。如果有人知道如何让蛇穿过墙壁或在边缘画一个框架,你能帮我编程吗?如果有任何添加此游戏的建议,请在此处添加。这些是代码: im
大约两天前,我收到了我的 TI-82 STATS 可编程计算器(实际上更像是一个 TI-83) - 并想用内置的 TI-BASIC 语言编写一个贪吃蛇游戏。 虽然我不得不找出:TI-BASIC 是 极
这个问题在这里已经有了答案: How do I chain the movement of a snake's body? (1 个回答) 11 个月前关闭。 我是 python 新手,现在才开始学习
我制作了一个贪吃蛇游戏(通过尝试遵循YouTuber的代码),方向由WASD控制。然而,当我按下其中一个键时,什么也没有发生。如果我按住它,它会改变方向,但是会有很大的延迟,可能超过一秒。我该如何解决
我们都知道移动设备上的新密码屏幕。它由要连接的点矩阵组成。 唯一密码是积分的向量。这些点可以通过以下限制与自己连接: 一个点只能连接到另外一个点 如果目标点和自由点在同一条线上,则将强制一条线连接到更
我的实体定义如下: @ManyToOne private DomainObject domainObject; 运行代码时出现此错误: 2017-10-30 14:58:52,517 WARN rn
在 Snake 中向上移动意味着你只能向左和向右转。如果你向左移动,你只能向上和向下转动等。目前我有一个问题,如果我正在向左移动(例如),然后我按向上或向下,然后很快按向右,蛇将保持在同一水平并撞到自
我正在用 C++ 编写一个基本的贪吃蛇游戏作为控制台应用程序。它基于“平铺”结构的二维数组。我的问题是:当按下按钮改变蛇行进的方向时,它不会立即工作,而是等待下一个“滴答声”。管理游戏本身的函数如下所
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 4 年前。 Improve t
我只是想弄清楚逻辑并使用 Python 来帮助我做到这一点。最终,我需要使用 ImageJ 宏语言来解决这个问题。 我不知道我是否使用了正确的术语,但我想创建一个“蛇形”计数器。 x = 1 numb
我正在从 youtube 上的 thenewboston 教程中学习如何在 pygame 中制作贪吃蛇游戏,并将其制作成我自己的游戏。游戏中存在一个问题,“苹果”在蛇的位置后面生成,这是我不想要的。
给定一个 5 x 5 网格和一个对象列表(可以是任何东西,例如整数) 我怎样才能以这样的方式填充网格,网格填充的顺序是:A1、A2、A3、A4、A5、B5、B4、B3、B2、B1、C1、C2 等 所以
我正在使用 snake case 为我的 API 构建与 spring boot 的 json 映射。 spring 允许您在 application.properties 文件中轻松定义它: spr
我正在尝试读取 Yaml 模板并动态替换模板中的某些字段并创建一个新的 Yaml 文件。我生成的 yaml 文件应该在所有方面反射(reflect)模板,包括双引号。但是当我使用 snake yaml
我想找到一种方法,在单个容器中将元素包装到一条与前一行相反的新行中,就像一条蛇自己 flex 一样。我无法使用flexbox以及flex-direction和flex-wrap属性的任何组合来实现此结
我正在按照以下视频来设计贪吃蛇游戏: https://www.youtube.com/watch?v=91a7ceECNTc 我正在一步一步地跟踪它,但是当我运行它时,蛇没有显示在我的屏幕上,只显示苹
嗨,我正在尝试使用 2D 数组在控制台上创建一个矩阵。这个想法是输出应该如下所示: 1|8|9 |16 2|7|10|15 3|6|11|14 4|5|12|13 有人知道如何做到这一点吗? 最佳答案
我正在创建一个贪吃蛇游戏我使用二维数组作为我的背框。没有语法错误。我在线程中收到异常。这就是我认为错误所在: java.awt.EventQueue.invokeLater(new Runnable
我是一名优秀的程序员,十分优秀!