小编Def*_*iti的帖子

三个js中文本在一行的中心点

我拥有的。

此处的文本位于浏览器的左上角

我想要实现的目标:

我想要到达这部分,其中行的中心有一个用于放置文本的空间

所以这是我的问题:

  1. 如何将三个js中的位置x和y转换为浏览器坐标,以便我可以将文本正确定位在行的中心?我只添加了垂直线的示例,我将有不同的线,例如水平线和对角线。

  2. 如何剪切中心的箭头线以便为文本留出空间?

这是我的代码

var gridCanvas = document.getElementById('gridcanvas');
			var ctx = gridCanvas.getContext('2d');
			ctx.beginPath();
			for(var x=0.5; x<gridCanvas.width; x+=20) {
			    ctx.moveTo(x, 0);
			    ctx.lineTo(x, gridCanvas.height);
			}
			for(var y=0.5; y<gridCanvas.height; y+=20) {
			    ctx.moveTo(0, y);
			    ctx.lineTo(gridCanvas.width, y);
			}

			ctx.strokeStyle = 'lightgrey';
			ctx.stroke();

			var container = document.getElementById( '3dcontainer' );
			var aspect = 400 / 400;
			var viewHeight = 400;
			var viewWidth = viewHeight * aspect;
			var scene = new THREE.Scene();
			var camera = new THREE.OrthographicCamera(
			    viewWidth / - 2, viewWidth / 2, viewHeight / …
Run Code Online (Sandbox Code Playgroud)

html javascript three.js

5
推荐指数
1
解决办法
1335
查看次数

为从标准输入接收到的每一行添加时间戳

您好,我正在尝试使用 bash 创建日志,但我得到的时间是错误的。我在后台运行这个。

# log code here before executing curl script log "Yay I was started"

curl https://example.com/process | sed "s/^/$(date -u) /" >> /path/to/logs.log &
Run Code Online (Sandbox Code Playgroud)

处理curl后设置的时间是执行它的时间,而不是我得到响应后的时间。我需要得到回复后的时间。

这是示例输出(错误响应)

Fri Aug 21 01:43:12 UTC 2020 Yay I was started
Fri Aug 21 01:43:12 UTC 2020 Yay I was the response returned by the url
Run Code Online (Sandbox Code Playgroud)

这里的 urlhttps://example.com/process会休眠 2 秒,但正如您所看到的,时间与执行时和执行后我们收到响应的时间相同。

正确反应

Fri Aug 21 01:43:12 UTC 2020 Yay I was started
Fri Aug 21 01:43:14 UTC 2020 Yay I was the …
Run Code Online (Sandbox Code Playgroud)

bash stdin timestamp

1
推荐指数
1
解决办法
844
查看次数

标签 统计

bash ×1

html ×1

javascript ×1

stdin ×1

three.js ×1

timestamp ×1