【发布时间】:2010-12-21 04:49:44
【问题描述】:
Shape 类包含两个方法 drawCircle() 和 drawTriangle()。每个 函数采用不同的参数集。目前,我调用这个 通过直接调用 pde 文件。如何从 如果我必须控制传递给的参数,则直接使用 HTML 文件 绘图功能? 1) Example.html 有(当前版本)
<script src="processing-1.0.0.min.js"></script>
<canvas data-processing-sources="example.pde"></canvas>
2) Example.pde 有
class Shape {
void drawCircle(intx, int y, int radius) {
ellipse(x, y, radius, radius);
}
void drawTriangle(int x1, int y1, int x2, int y2, int x3, int
y3) {
rect(x1, y1, x2, y2, x3, y3);
}
}
Shape shape = new Shape();
shape.drawCircle(10, 40, 70);
我希望在我的 HTML 文件中做这样的事情,这样我就可以 将所有函数移动到一个单独的文件中并调用它们 不同的参数来绘制不同的形状(非常类似于你如何 会用Java做) 一个.html
<script>
Shape shape = new Shape();
shape.drawCircle(10, 10, 3);
</script>
B.html
<script>
Shape shape = new Shape();
shape.drawTriangle(30, 75, 58, 20, 86, 75);
</script>
2) 我使用 Example2.pde 有
void setup() {
size(200,200);
background(125);
fill(255);
}
void rectangle(int x1, int y1, int x2, int y2) {
rect(x1, y1, x2, y2);
}
我的 Example2.html 有
var 处理实例; processingInstance.rectangle(30, 20, 55, 55);但这不起作用。如何从 html 动态传递这些参数。
【问题讨论】:
-
提前声明您正在使用 processing.js 可能是值得的