I am trying to make a program where the size of my screen is a bit to small.
I am trying to make it so that when I pusch a button or scroll a scrollbar the X coordinate of the canvas moves. This would mean that the left side of my screen is no longer x = 0; but for example x = 100;
How do I change the X variable of my screen?
I understand what you mean but I am still a bit confused.
Lets suppose I am placing squares on my screen which currently ranges from x = 0 to x = 1600, now my screen is filled with squares and I want to go further to the right and fill it from x = 1600 to x = 3200. How would I use translate(); or map(); to do this?
Your original problem statement is not clear to me.
A small snippet of code that you are working through helps.
You can plot beyond your canvas (this may be your screen size) but you will not see this.
You can map() values from 0 to 3200 to 0 to 1600 and plot those on your canvas; this is just scaling it down which can also be done by dividing by 2 in this case.
You may want to do a bit more exploration into the resources available to you first and work through some of the examples and functions.
One of the best tools in a programmer’s tool chest is knowing the resources available to you and learning to navigate, filter, and use them.
A short list of resources to peruse:
Resources < Click here to expand !
Explore the resources available here:
The Processing website has references, examples, tutorials, links to resources, etc. https://processing.org/
The Processing PDE (IDE) has lots to offer!
An exploration of the menu bar will reveal what is available; libraries, tools, local examples, and other goodies are in there.
ArrayList<Tegenstander> tegenstanders;
void setup(){
fullScreen();
background(0);
tegenstanders = new ArrayList<Tegenstander>();
tegenstanders.add(new Tegenstander());
}
void draw(){
background(0);
for (int i = tegenstanders.size() - 1; i >= 0; i--) {
Tegenstander t = tegenstanders.get(i);
t.update();
t.getX();
t.getY();
}
println(tegenstanders.size());
if(keyPressed && key == 'v'){
tegenstanders.add(new Tegenstander());
}
}
class Tegenstander{
int x;
int y;
Tegenstander(){
x = 100;
y =100;
}
void update(){
fill(100);
rect(x, y, 100, 100);
if(mouseX> x && mouseX < x+100 && mouseY > y && mouseY < y+100){
cursor(HAND);
stroke(255);
if(mousePressed){
strokeWeight(5);
x = mouseX-50;
y = mouseY-50;
}
else{
strokeWeight(2);
}
}
else{
cursor(ARROW);
noStroke();
}
}
int getX(){
return x;
}
int getY(){
return y;
}
}
I can store the objects on any coordinates I want even outside my computer window wich means I cant see them. The coordinates range from 0 to 16k I read somewhere, however I can only see x from 0 to 1600 on my screen. What I am trying to do is make it so that I can scroll and see X from 0 all the way to 16k. for example by pressing a button which changes the view from x 0-1600 to x 1600-3200. That way I can store objects on a much larger scale and still interact with them. I understand I can use translate(): or map(): but how do I connect those comands to the point of view on a canvas. example:
start screen: you can see X: 0 to X: 1600. I press a button/mouse and now I can see X: 1600 to X: 3200
I used your code and played around with it. This is what I am trying to do thanks!
But how does xPos connect with x, how does the program know it has to change x? Suppose I make a lot of variables how does translate connect with the right variable?