Processing 将(0,0)设置为左下角,而不在处理(.org)中切换X轴和Y轴
我想更改二维处理草图中的坐标系,将0,0放在左下角,而不是左上角。以下代码将向左下角移动0,0: 0,身高; rotateradians-90; 但是,它也使X轴成为垂直轴。有没有简单的方法将0,0移动到左下角并保持X轴水平 我考虑过的一个选择是将P3D与rotate和rotateY结合使用,但我更喜欢2d情况下的解决方案Processing 将(0,0)设置为左下角,而不在处理(.org)中切换X轴和Y轴,processing,Processing,我想更改二维处理草图中的坐标系,将0,0放在左下角,而不是左上角。以下代码将向左下角移动0,0: 0,身高; rotateradians-90; 但是,它也使X轴成为垂直轴。有没有简单的方法将0,0移动到左下角并保持X轴水平 我考虑过的一个选择是将P3D与rotate和rotateY结合使用,但我更喜欢2d情况下的解决方案 谢谢你的帮助 您可以简单地在不旋转的情况下进行平移: transform(0, height); 并在翻转时处理坐标: 布尔useVFlip=true void setup
谢谢你的帮助 您可以简单地在不旋转的情况下进行平移:
transform(0, height);
并在翻转时处理坐标:
布尔useVFlip=true
void setup(){
size(400,400);
}
void draw(){
background(255);
if(useVFlip) translate(0,height);
drawAxes(100);
translate(width * .5, useVFlip ? (height-mouseY)*-1 : mouseY);
triangle(0,0,100,0,100,100);
}
void keyPressed(){ useVFlip = !useVFlip; }
void drawAxes(int size){
pushStyle();
strokeWeight(10);
stroke(192,0,0);
line(0,0,size,0);
stroke(0,192,0);
line(0,0,0,size);
popStyle();
}
void setup(){
size(400,400);
}
void draw(){
background(255);
if(useVFlip){
scale(1,-1);
translate(0,-height);
}
drawAxes(100);
translate(width * .5, useVFlip ? height-mouseY : mouseY);
triangle(0,0,100,0,100,100);
}
void keyPressed(){ useVFlip = !useVFlip; }
void drawAxes(int size){
pushStyle();
strokeWeight(10);
stroke(192,0,0);
line(0,0,size,0);
stroke(0,192,0);
line(0,0,0,size);
popStyle();
}
如果可以更容易地获取翻转的坐标,则可以使用以下方法翻转整个坐标系:
布尔useVFlip=true
void setup(){
size(400,400);
}
void draw(){
background(255);
if(useVFlip) translate(0,height);
drawAxes(100);
translate(width * .5, useVFlip ? (height-mouseY)*-1 : mouseY);
triangle(0,0,100,0,100,100);
}
void keyPressed(){ useVFlip = !useVFlip; }
void drawAxes(int size){
pushStyle();
strokeWeight(10);
stroke(192,0,0);
line(0,0,size,0);
stroke(0,192,0);
line(0,0,0,size);
popStyle();
}
void setup(){
size(400,400);
}
void draw(){
background(255);
if(useVFlip){
scale(1,-1);
translate(0,-height);
}
drawAxes(100);
translate(width * .5, useVFlip ? height-mouseY : mouseY);
triangle(0,0,100,0,100,100);
}
void keyPressed(){ useVFlip = !useVFlip; }
void drawAxes(int size){
pushStyle();
strokeWeight(10);
stroke(192,0,0);
line(0,0,size,0);
stroke(0,192,0);
line(0,0,0,size);
popStyle();
}
您也可以使用a,但不确定您对它们的熟悉程度:
布尔useCustomCS=true;
PMatrix2D客户
void setup(){
size(400,400);
customCS = new PMatrix2D( 1, 0, 0,
0, -1,height);
fill(0);
}
void draw(){
background(255);
if(useCustomCS) applyMatrix(customCS);
drawAxes(100);
translate(width * .5, useCustomCS ? height-mouseY : mouseY);
text("real Y:" + mouseY + " flipped Y: " + (height-mouseY),0,0);
triangle(0,0,100,0,100,100);
}
void keyPressed(){ useCustomCS = !useCustomCS; }
void drawAxes(int size){
pushStyle();
strokeWeight(10);
stroke(192,0,0);
line(0,0,size,0);
stroke(0,192,0);
line(0,0,0,size);
popStyle();
}
您可以简单地在不旋转的情况下进行平移:
transform(0, height);
并在翻转时处理坐标:
布尔useVFlip=true
void setup(){
size(400,400);
}
void draw(){
background(255);
if(useVFlip) translate(0,height);
drawAxes(100);
translate(width * .5, useVFlip ? (height-mouseY)*-1 : mouseY);
triangle(0,0,100,0,100,100);
}
void keyPressed(){ useVFlip = !useVFlip; }
void drawAxes(int size){
pushStyle();
strokeWeight(10);
stroke(192,0,0);
line(0,0,size,0);
stroke(0,192,0);
line(0,0,0,size);
popStyle();
}
void setup(){
size(400,400);
}
void draw(){
background(255);
if(useVFlip){
scale(1,-1);
translate(0,-height);
}
drawAxes(100);
translate(width * .5, useVFlip ? height-mouseY : mouseY);
triangle(0,0,100,0,100,100);
}
void keyPressed(){ useVFlip = !useVFlip; }
void drawAxes(int size){
pushStyle();
strokeWeight(10);
stroke(192,0,0);
line(0,0,size,0);
stroke(0,192,0);
line(0,0,0,size);
popStyle();
}
如果可以更容易地获取翻转的坐标,则可以使用以下方法翻转整个坐标系:
布尔useVFlip=true
void setup(){
size(400,400);
}
void draw(){
background(255);
if(useVFlip) translate(0,height);
drawAxes(100);
translate(width * .5, useVFlip ? (height-mouseY)*-1 : mouseY);
triangle(0,0,100,0,100,100);
}
void keyPressed(){ useVFlip = !useVFlip; }
void drawAxes(int size){
pushStyle();
strokeWeight(10);
stroke(192,0,0);
line(0,0,size,0);
stroke(0,192,0);
line(0,0,0,size);
popStyle();
}
void setup(){
size(400,400);
}
void draw(){
background(255);
if(useVFlip){
scale(1,-1);
translate(0,-height);
}
drawAxes(100);
translate(width * .5, useVFlip ? height-mouseY : mouseY);
triangle(0,0,100,0,100,100);
}
void keyPressed(){ useVFlip = !useVFlip; }
void drawAxes(int size){
pushStyle();
strokeWeight(10);
stroke(192,0,0);
line(0,0,size,0);
stroke(0,192,0);
line(0,0,0,size);
popStyle();
}
您也可以使用a,但不确定您对它们的熟悉程度:
布尔useCustomCS=true;
PMatrix2D客户
void setup(){
size(400,400);
customCS = new PMatrix2D( 1, 0, 0,
0, -1,height);
fill(0);
}
void draw(){
background(255);
if(useCustomCS) applyMatrix(customCS);
drawAxes(100);
translate(width * .5, useCustomCS ? height-mouseY : mouseY);
text("real Y:" + mouseY + " flipped Y: " + (height-mouseY),0,0);
triangle(0,0,100,0,100,100);
}
void keyPressed(){ useCustomCS = !useCustomCS; }
void drawAxes(int size){
pushStyle();
strokeWeight(10);
stroke(192,0,0);
line(0,0,size,0);
stroke(0,192,0);
line(0,0,0,size);
popStyle();
}
请尝试以下操作:
平移0,高度
标度1,-1 尝试以下操作:
平移0,高度
标度1,-1 你可以使用反射功能吗?你可以使用反射功能吗?哇!感谢您在这个问题将近一周年之际继续关注。我错过了另一个答案,它给出了与您之前的答案相同的解决方案,但是+1也是正确的!哇!感谢您在这个问题将近一周年之际继续关注。我错过了另一个答案,它给出了与您之前的答案相同的解决方案,但是+1也是正确的!