- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以下代码绘制了 egg 的图像在 html5 Canvas 上
function init() {
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
draw(ctx);
}
function draw(ctx) {
// layer1/Path
ctx.save();
ctx.beginPath();
ctx.moveTo(100.0, 90.0);
ctx.bezierCurveTo(100.0, 95.5, 95.5, 100.0, 90.0, 100.0);
ctx.lineTo(10.0, 100.0);
ctx.bezierCurveTo(4.5, 100.0, 0.0, 95.5, 0.0, 90.0);
ctx.lineTo(0.0, 10.0);
ctx.bezierCurveTo(0.0, 4.5, 4.5, 0.0, 10.0, 0.0);
ctx.lineTo(90.0, 0.0);
ctx.bezierCurveTo(95.5, 0.0, 100.0, 4.5, 100.0, 10.0);
ctx.lineTo(100.0, 90.0);
ctx.closePath();
ctx.fillStyle = "rgb(229, 229, 229)";
ctx.fill();
// layer1/Path
ctx.beginPath();
ctx.moveTo(10.0, 28.0);
ctx.bezierCurveTo(10.0, 37.9, 18.1, 46.0, 28.0, 46.0);
ctx.bezierCurveTo(37.9, 46.0, 46.0, 37.9, 46.0, 28.0);
ctx.bezierCurveTo(46.0, 18.1, 37.9, 10.0, 28.0, 10.0);
ctx.bezierCurveTo(18.1, 10.0, 10.0, 18.1, 10.0, 28.0);
ctx.closePath();
ctx.fillStyle = "rgb(255, 191, 30)";
ctx.fill();
ctx.restore();
}
<body onload="init()">
<canvas id="canvas" width="100" height="100"></canvas>
</body>
我试图让 arbor.js 将鸡蛋显示为一个节点,我还将展示其他插图,例如交互式餐厅菜单的培根和面包。它应该进入每个节点,我相信?但不太确定如何。
particleSystem.eachNode(function(node, pt){
// node: {mass:#, p:{x,y}, name:"", data:{}}
// pt: {x:#, y:#} node position in screen coords
// determine the box size and round off the coords if we'll be
// drawing a text label (awful alignment jitter otherwise...)
var w = ctx.measureText(node.data.label||"").width + 6
var label = node.data.label
if (!(label||"").match(/^[ \t]*$/)){
pt.x = Math.floor(pt.x)
pt.y = Math.floor(pt.y)
}else{
label = null
}
// clear any edges below the text label
// ctx.fillStyle = 'rgba(255,255,255,.6)'
// ctx.fillRect(pt.x-w/2, pt.y-7, w,14)
ctx.clearRect(pt.x-w/2, pt.y-7, w,14)
// draw the text
if (label){
ctx.font = "bold 11px Arial"
ctx.textAlign = "center"
// if (node.data.region) ctx.fillStyle = palette[node.data.region]
// else ctx.fillStyle = "#888888"
ctx.fillStyle = "#888888"
// ctx.fillText(label||"", pt.x, pt.y+4)
ctx.fillText(label||"", pt.x, pt.y+4)
}
})
},
resize:function(){
var w = $(window).width(),
h = $(window).height();
canvas.width = w; canvas.height = h // resize the canvas element to fill the screen
particleSystem.screenSize(w,h) // inform the system so it can map coords for us
that.redraw()
},
initMouseHandling:function(){
// no-nonsense drag and drop (thanks springy.js)
selected = null;
nearest = null;
var dragged = null;
var oldmass = 1
$(canvas).mousedown(function(e){
var pos = $(this).offset();
var p = {x:e.pageX-pos.left, y:e.pageY-pos.top}
selected = nearest = dragged = particleSystem.nearest(p);
if (selected.node !== null){
// dragged.node.tempMass = 10000
dragged.node.fixed = true
}
return false
});
非常感谢。
最佳答案
因此,打开 arbor 0.92 附带的示例项目。在 main.js 中,找到附加到 eachNode
的匿名函数:
particleSystem.eachNode(function(node, pt){
// node: {mass:#, p:{x,y}, name:"", data:{}}
// pt: {x:#, y:#} node position in screen coords
// draw a rectangle centered at pt
var w = 20
ctx.fillStyle = (node.data.alone) ? "orange" : "black"
ctx.fillRect(pt.x-w/2, pt.y-w/2, w/2,w)
})
这是我们需要用您的“蛋”代码替换的部分。问题是您不能直接将绘图函数放入其中,因为它使用的是绝对 坐标,而我们需要使用相对于节点渲染位置的坐标。本质上,您需要修改 draw(ctx)
函数中的每个调用以使用 pt.x
和 pt.y
,如所述在示例中。
编辑
好的,完成了。用这个替换整个 block :
particleSystem.eachNode(function(node, pt){
// node: {mass:#, p:{x,y}, name:"", data:{}}
// pt: {x:#, y:#} node position in screen coords
// draw a rectangle centered at pt
ctx.beginPath();
ctx.moveTo(100.0 + pt.x, 90.0 + pt.y);
ctx.bezierCurveTo(100.0 + pt.x, 95.5 + pt.y, 95.5 + pt.x, 100.0 + pt.y, 90.0 + pt.x, 100.0 + pt.y);
ctx.lineTo(10.0 + pt.x, 100.0 + pt.y);
ctx.bezierCurveTo(4.5 + pt.x, 100.0 + pt.y, 0.0 + pt.x, 95.5 + pt.y, 0.0 + pt.x, 90.0 + pt.y);
ctx.lineTo(0.0 + pt.x, 10.0 + pt.y);
ctx.bezierCurveTo(0.0 + pt.x, 4.5 + pt.y, 4.5 + pt.x, 0.0 + pt.y, 10.0 + pt.x, 0.0 + pt.y);
ctx.lineTo(90.0 + pt.x, 0.0 + pt.y);
ctx.bezierCurveTo(95.5 + pt.x, 0.0 + pt.y, 100.0 + pt.x, 4.5 + pt.y, 100.0 + pt.x, 10.0 + pt.y);
ctx.lineTo(100.0 + pt.x, 90.0 + pt.y);
ctx.closePath();
ctx.fillStyle = "rgb(229, 229, 229)";
ctx.fill();
// layer1/Path
ctx.beginPath();
ctx.moveTo(10.0 + pt.x, 28.0 + pt.y);
ctx.bezierCurveTo(10.0 + pt.x, 37.9 + pt.y, 18.1 + pt.x, 46.0 + pt.y, 28.0 + pt.x, 46.0 + pt.y);
ctx.bezierCurveTo(37.9 + pt.x, 46.0 + pt.y, 46.0 + pt.x, 37.9 + pt.y, 46.0 + pt.x, 28.0 + pt.y);
ctx.bezierCurveTo(46.0 + pt.x, 18.1 + pt.y, 37.9 + pt.x, 10.0 + pt.y, 28.0 + pt.x, 10.0 + pt.y);
ctx.bezierCurveTo(18.1 + pt.x, 10.0 + pt.y, 10.0 + pt.x, 18.1 + pt.y, 10.0 + pt.x, 28.0 + pt.y);
ctx.closePath();
ctx.fillStyle = "rgb(255, 191, 30)";
ctx.fill();
})
它们并不像您所看到的那样居中,但希望这能为如何继续提供足够的理想。 :)
关于javascript - arbor.js 自定义每个节点的形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9414832/
我是 TensorFlow 菜鸟。我已经从 deeppose 的开源实现中训练了一个 TensorFlow 模型,现在必须针对一组新图像运行该模型。 该模型是在大小为 100 * 100 的图像上训练
我正在尝试以这种方式设置节点的大小: controller[shape=circle,width=.5,label="Controller",style=filled,fillcolor="#8EC1
是否有 VBA 代码可以在选择的每个单元格周围添加文本框。文本框应该是单元格的大小(类似于边框)? 最佳答案 您可以使用 .AddTextbox方法。循环遍历您选择的单元格,并使用单元格的尺寸属性来设
我有一个变量 a尺寸 (1, 5) 我想“平铺”的次数与我的小批量的大小一样多。例如,如果小批量大小为 32,那么我想构造一个张量 c维度为 (32, 5),其中每一行的值与原始 (1, 5) 变量
我在使用 javaFX 时遇到问题。我想每 1000 毫秒在应用程序窗口中显示一次时间。 public class Main extends Application { StackPane root
所以我目前正在创建这个 API。这个登录类应该只创建一个场景,其中包含制作 GUI 所需的所有框。我遇到的问题是,单击时我的形状不会执行任何操作。我有事件监听器,但它不起作用。 import
我正在用 python turtle 画一些东西,我使用了形状函数,但是形状 overdraw 了它们之前的其他形状(我可以看到形状在移动),并且我只得到了最后一个形状: `up() goto(-20
我正在读取多个 .csv 文件作为具有相同形状的 panda DataFrame。对于某些索引,某些值为零,因此我想选择具有相同形状的每个索引的值,并为相同的索引放置零值并删除零以成为相同的形状: a
我有一个简单的二维网格,格式为 myGrid[x,y] 我正在尝试找到一种方法来找到围绕选定网格的周长,这样我就有了一个可供选择的形状。 这是我的意思的一个例子: 这里的想法是找到所有相关的“角”,也
我有一个网络层,用于调用多个端点。我想减少重复代码的数量,并认为也许我可以将响应模型作为端点的一部分传递。 这个想法是不需要多个仅因响应而不同的函数,我可以调用我的网络层并根据路径进行设置。 我看到的
我正在创建一个自定义 ImageView,它将我的图像裁剪成六边形并添加边框。我想知道我的方法是否正确,或者我是否以错误的方式这样做。有很多自定义库已经在执行此操作,但开箱即用的库中没有一个具有我正在
我正在编写一些代码,这些代码需要识别一些基于节点云的相当基本的几何图形。我会对检测感兴趣: 板(简单有界平面) 圆柱体(两个节点循环) 半圆柱(圆弧+直线+圆弧+直线) 圆顶(n*loop+top n
我有这个形状: http://screencast.com/t/9UUhAXT5Wu 但边界在截止点处没有跟随它 - 我该如何解决? 这是我当前 View 的代码: self.view.backgro
我现在脑震荡,所以我想问一个非常简单的问题。 目前,我正在尝试打印出这样的开头 当输入为 7 时,输出为 * ** * ** * ** * 这里是我的代码,它打印 14 次而不是 7 次,或者当我输入
我想生成如下设计。计划选项卡顶部的"new"。我使用的属性适用于 chrome 和 mozilla,但在 Edge 中出现故障。 以下是我在 chrome 中应用的样式: a.subnav__item
我想要一个带有两种颜色边框轮廓的 shape 元素。我可以使用 solid 元素做一个单一的颜色轮廓,但这只允许我画一条线。我尝试在我的形状中使用两个 stroke 元素,但这也不起作用。 有没有办法
我需要为屏幕上的形状着色任何我想要的颜色。我目前正在尝试使用 UIImage 来执行此操作,我想根据自己的需要重新着色。据我所知,执行此操作的唯一方法是获取 UIImage 的各个像素,这需要更多我想
因此,经过多年的 OOP,我从我的一门大学类(class)中得到了一个非常简单的家庭作业,以实现一个简单的面向对象的结构。 要求的设计: 实现面向对象的解决方案以创建以下形状: 椭圆、圆形、正方形、矩
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 5 年前。 Improve this qu
我想知道是否可以使用类似于以下的 div 制作复杂的形状: 它基本上是一个四 Angular 向内收缩的圆 Angular 正方形。目标是使用背景图像来填充它。我可以使用具有以下 SVG 路径的剪辑蒙
我是一名优秀的程序员,十分优秀!