处理 - 如何绘制 x/y 轴大于 width/height 或 window 的散点图
processing - how to plot a scatter graph with x/y axis bigger than width/height of window
所以我有代码 生成 recaman 序列中的数字列表并绘制它们(使用 translate(0,height); scale(1,-1);
在左下角使用 0,0)。
我的问题是它只显示了我想要绘制的图表的一小部分。例如,我希望能够在 y 轴和 x 轴上有 10,000 以及点 使用这些数字,但保持 500,500 window 大小。
我想绘制一个图大于 500,500,window 大小。
我该怎么做,如果可能的话?
创建大小为 (10000, 10000) 的 PGraphics 对象。
将你的观点渲染到这里(你可以在 PGraphics 对象上调用每个 Processing 绘图方法)。
在 window 中的不同位置绘制 PGraphics 对象以模拟图形中的平移。
以下示例显示了如何使用鼠标平移功能和静态图(在 setup() 中实例化和填充)执行上述操作。
import processing.core.PApplet;
import processing.core.PGraphics;
public class Prototype extends PApplet {
public static void main(String[] args) {
PApplet.main(Prototype.class);
}
int xOffset = 0, yOffset = 0;
int xOffsetP, yOffsetP;
int mouseDownX, mouseDownY;
boolean move = false;
PGraphics graph;
@Override
public void settings() {
size(500, 500);
}
@Override
public void setup() {
graph = createGraphics(2000, 2000); // Create graph 2000x2000px
graph.beginDraw();
graph.background(255);
graph.fill(0);
for (int i = 0; i < 1000; i++) { // Adds 1000 random points to graph
graph.ellipse(random(2000), random(2000), 3, 3);
}
for (int i = 0; i < graph.height; i += 50) { // Adds Y-axis labels
graph.text(i, 5, graph.height - i);
}
graph.line(0, 0, 1999, 0); // Graph edge/border
graph.line(0, 1999, 1999, 1999);
graph.line(0, 0, 0, 1999);
graph.line(1999, 0, 1999, 2000);
graph.endDraw();
}
@Override
public void draw() {
background(255);
if (move) {
xOffset = mouseDownX - mouseX + xOffsetP;
yOffset = mouseY - mouseDownY + yOffsetP;
xOffset = constrain(xOffset, 0, graph.width - width); // Optional
yOffset = constrain(yOffset, 0, graph.height - height); // Optional
}
image(graph, -xOffset, yOffset - graph.height + height);
fill(255, 0, 0);
text("X Offset: " + xOffset, 0, 10);
text("Y Offset: " + yOffset, 0, 25);
}
@Override
public void mousePressed() {
move = true;
mouseDownX = mouseX;
mouseDownY = mouseY;
}
@Override
public void mouseReleased() {
move = false;
xOffsetP = xOffset;
yOffsetP = yOffset;
}
}
结果(500x500 window):
所以我有代码 生成 recaman 序列中的数字列表并绘制它们(使用 translate(0,height); scale(1,-1);
在左下角使用 0,0)。
我的问题是它只显示了我想要绘制的图表的一小部分。例如,我希望能够在 y 轴和 x 轴上有 10,000 以及点 使用这些数字,但保持 500,500 window 大小。
我想绘制一个图大于 500,500,window 大小。
我该怎么做,如果可能的话?
创建大小为 (10000, 10000) 的 PGraphics 对象。
将你的观点渲染到这里(你可以在 PGraphics 对象上调用每个 Processing 绘图方法)。
在 window 中的不同位置绘制 PGraphics 对象以模拟图形中的平移。
以下示例显示了如何使用鼠标平移功能和静态图(在 setup() 中实例化和填充)执行上述操作。
import processing.core.PApplet;
import processing.core.PGraphics;
public class Prototype extends PApplet {
public static void main(String[] args) {
PApplet.main(Prototype.class);
}
int xOffset = 0, yOffset = 0;
int xOffsetP, yOffsetP;
int mouseDownX, mouseDownY;
boolean move = false;
PGraphics graph;
@Override
public void settings() {
size(500, 500);
}
@Override
public void setup() {
graph = createGraphics(2000, 2000); // Create graph 2000x2000px
graph.beginDraw();
graph.background(255);
graph.fill(0);
for (int i = 0; i < 1000; i++) { // Adds 1000 random points to graph
graph.ellipse(random(2000), random(2000), 3, 3);
}
for (int i = 0; i < graph.height; i += 50) { // Adds Y-axis labels
graph.text(i, 5, graph.height - i);
}
graph.line(0, 0, 1999, 0); // Graph edge/border
graph.line(0, 1999, 1999, 1999);
graph.line(0, 0, 0, 1999);
graph.line(1999, 0, 1999, 2000);
graph.endDraw();
}
@Override
public void draw() {
background(255);
if (move) {
xOffset = mouseDownX - mouseX + xOffsetP;
yOffset = mouseY - mouseDownY + yOffsetP;
xOffset = constrain(xOffset, 0, graph.width - width); // Optional
yOffset = constrain(yOffset, 0, graph.height - height); // Optional
}
image(graph, -xOffset, yOffset - graph.height + height);
fill(255, 0, 0);
text("X Offset: " + xOffset, 0, 10);
text("Y Offset: " + yOffset, 0, 25);
}
@Override
public void mousePressed() {
move = true;
mouseDownX = mouseX;
mouseDownY = mouseY;
}
@Override
public void mouseReleased() {
move = false;
xOffsetP = xOffset;
yOffsetP = yOffset;
}
}
结果(500x500 window):