Draw vertical line between circles in canvas(在画布中的圆圈之间绘制垂直线)
问题描述
我想在我的项目中的圆圈之间画一条垂直线.
I want draw a vertical line between circles in my project.
这些是我的代码:
html:
这些是js代码:
如何在圆圈之间画一条垂直线?当我尝试这样做时,变成了这个图像:
How I can draw a vertical line between circles? when I tried to do this become this image:
这是我的 js 代码:
and this is my js code:
请帮忙解决这个问题!
谢谢你!
please help for this problem!
thank u!
推荐答案
我不知道你为什么选择使用多个画布,但我已经在我的 小提琴在这里.
I'm not sure why you're opting to use multiple canvases but I have implemented a more generic solution in my fiddle here.
它使用两个循环定义为:
It uses two loops defined as:
这使它更加灵活,因为您可以在脚本中指定行和列.剩下的就是知道你的偏移量是多少!
This makes it more flexible as you can specify the rows and columns in the script. The rest is just knowing what your offsets are!
实现圆的代码基本没有改动,但有趣的是什么时候画一条线:
The code to implement the circle is largely untouched, but the fun is when to draw a line:
这就是说你应该在每一列上画一条水平线,除了最后一列.这工作得很好,即使你有一行一列.您还想在多行时绘制一条垂直线,并将其偏移,使其看起来像连接到前一行.
All this is saying is that you should draw a horizontal line on every column except for the last one. This works pretty well, even when you have one row by one column. You also want to draw a vertical line when there is more than one row, and offset it so it looks like it joins onto the previous row.
注意到你有不同的 x 和 y 距离,所以我修改了 fiddle 来解释这个.
Noticed you have different x and y distances, so I modified the fiddle to account for this.
这篇关于在画布中的圆圈之间绘制垂直线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!