【发布时间】:2019-02-16 15:38:19
【问题描述】:
我正在使用 p5.js 模拟绘图机,类似于this。
我已经创建了手臂相对于电机位置的定位。我试图重新创建的想法是握住铅笔/钢笔并用它在下面的旋转画布上绘画。我在 p5.js 编辑器中创建了一个测试example。
example 绘制两个点,一个红色和一个蓝色。目标是使用下方旋转图形对象上的蓝点创建一个标记或轨迹。
function setup() {
createCanvas(400, 400);
background(255);
img = createGraphics(200, 200);
img.background(150);
img.strokeWeight(3);
//rectMode(CENTER);
}
function draw() {
background('lightYellow');
translate(100, 100);
img.background('lightBlue');
img.push();
img.translate(100, 100);
img.rotate(radians(frameCount));
img.fill(240);
img.noStroke();
img.rect(-50, -50, 100, 100);
img.strokeWeight(4);
img.stroke('red');
img.point(20, 20);
img.pop();
img.stroke('blue');
img.strokeWeight(4);
img.point(100, 80);
image(img, 0, 0);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.min.js"></script>
有没有办法用我当前的例子来做到这一点,还是我应该尝试不同的方法?
【问题讨论】:
-
我不完全确定你在问什么。这段代码与您预期的有什么不同?
-
查看 Julian 的回答。它完全符合我的要求。