导航栏处理大于屏幕图
我在10000像素宽的窗口中移动透视时遇到问题,其中我每毫秒左右执行一次绘图,并且所有图形都在x方向上堆叠。我希望能够沿着x轴将屏幕上显示的视角移动到我想要的位置,以便我可以看到实时绘图的发生。导航栏处理大于屏幕图
我在Arduino型电路板上使用光传感器与PDE进行光级交流,并且我为每个光读取实例绘制了一条贝塞尔曲线,使得Bezier在光线暗淡时变宽,而当光线较强时则变窄。
我想实现这种类型的导航栏:
void setup()
{
size(1800, 1800);
}
void draw()
{ int x_navigator = width/2 - width/6, y_navigator = 80, navigator_width = width/3, navigator_height = 40;
fill(204);
rect(x_navigator, y_navigator, navigator_width, navigator_height);
fill(250, 204, 0, 160);
if (mouseX > x_navigator && mouseY > y_navigator && mouseX < x_navigator + navigator_width && mouseY < y_navigator + navigator_height)
{
if (mouseX < x_navigator + navigator_width/12)
{
rect(x_navigator, y_navigator, navigator_width/6, navigator_height);
}
else
{
if (mouseX > x_navigator + ((11 * navigator_width)/12))
{
rect(x_navigator + (5 * navigator_width)/6, y_navigator, navigator_width/6, navigator_height);
}
else
{
rect(mouseX - (navigator_width/12), y_navigator, navigator_width/6, navigator_height);
}
}
}
}
在我的代码,吸引了贝济耶:
import processing.serial.*;
Serial Engduino;
String light_String = "", temperature_String = "";
int constant = 300;
float begin_x = 0, begin_y = 550, end_x, end_y, control = 1, light, temperature;
void setup()
{
String portName = "COM3";
Engduino = new Serial(this, portName, 9600);
size(1000, 800);
noFill();
smooth();
strokeWeight(3);
}
void draw()
{
if (Engduino.available() > 0)
{
light_String = Engduino.readStringUntil('\n');
try{light = parseFloat(light_String);}
catch(NullPointerException e)
{;}
println("The light is: ");
println(light);
end_x = begin_x + (400/(sqrt(light) + 1));
end_y = begin_y - constant;
control = end_x - begin_x;
bezier(begin_x, begin_y, begin_x + control, begin_y, end_x - control, end_y, end_x, end_y);
constant = constant * (-1);
begin_x = end_x;
begin_y = end_y;
}
}
同时使它的功能,以将显示的图像移动到光标所在的位置,以便我可以实时看到图形,并检查前面的c如果我愿意的话,我会画出。
编辑:因此,如果没有Engduino工作的代码是这样的:
int constant = 300;
float begin_x = 0, begin_y = 550, end_x, end_y, control = 1, light = 30; // Light is what I get through the serial port from the Engduino (an Arduino type board`)
void setup()
{
size(10000, 800); // The 10000-pixel wide window.
noFill();
smooth();
strokeWeight(3);
}
void draw()
{
end_x = begin_x + (400/(sqrt(light) + 1));
end_y = begin_y - constant;
control = end_x - begin_x;
bezier(begin_x, begin_y, begin_x + control, begin_y, end_x - control, end_y, end_x, end_y);
constant = constant * (-1);
begin_x = end_x;
begin_y = end_y;
}
我想是有我展示了(至少在设计)类型的导航条来浏览周围的10000像素宽的窗口。我上传的导航条码只是导航的设计,没有功能,这是我想要一些帮助的地方。
因为您的绘图是在多个框架上完成的,所以这会有点复杂。你不是每一帧都清理画布,而是随着时间的推移绘制一幅画。
如果你清空画布和重绘一切每一帧(这是许多加工草图做),那么你可以简单地改变你在哪里画的一切的X
值,或绘图之前的一切只需调用translate()
功能其他。
但是,由于您正在绘制多个帧的所有内容,因此您将不得不绘制到PGraphics
缓冲区。然后在每一帧上,使用任何你想要的X偏移量绘制缓冲区。这里有一个小例子:
int constant = 300;
float begin_x = 0, begin_y = 550, end_x, end_y, control = 1, light = 30; // Light is what I get through the serial port from the Engduino (an Arduino type board`)
PGraphics pg;
void setup()
{
size(10000, 800); // The 10000-pixel wide window.
pg = createGraphics(width, height);
}
void draw()
{
end_x = begin_x + (400/(sqrt(light) + 1));
end_y = begin_y - constant;
control = end_x - begin_x;
pg.beginDraw();
pg.noFill();
pg.smooth();
pg.strokeWeight(3);
pg.bezier(begin_x, begin_y, begin_x + control, begin_y, end_x - control, end_y, end_x, end_y);
pg.endDraw();
constant = constant * (-1);
begin_x = end_x;
begin_y = end_y;
background(200);
image(pg, -mouseX, 0);
}
谢谢你的时间。我想再问几个问题,以确保我很好地理解这个概念。首先,这个图形缓冲区实时显示数据? “缓冲区”这个词让我想起了等待时间。此外,缓冲区是一个矩形和它包含的所有内容?我是否应该获得所有在设置中被称为一次的函数,以便现在在绘图中始终调用?我在说没有填充(),平滑()... –
@AndreiBarbu我建议检查[参考](https://processing.org/reference/PGraphics。首先是html)。但是,“缓冲区”这个词只是意味着你的屏幕首先是屏幕以外的东西(你已经在没有缓冲区的情况下进行,处理只是隐藏了你的屏幕)。这并不意味着等待时间。如果你仍然有后续问题,我建议在他们自己的帖子中用更新的[mcve]。祝你好运! –
如果你发布一个不依赖于串行库的[mcve],你会有更好的运气。只需使用硬编码的图形,以便我们可以复制并粘贴代码来运行它。你也没有告诉我们问题是什么。你期望这个代码做什么?它做什么呢?您是否试图将其缩小到与您期望的行为不同的特定代码行? –
当然,我会很快发布一个修改。 –
我已经发布了编辑,并且指定了这个问题。 –