We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › New coordinates reference
Page Index Toggle Pages: 1
New coordinates reference (Read 491 times)
New coordinates reference
Aug 26th, 2009, 1:31pm
 
Hi. As a newbie I have a lot of questions...

Is there the possibility to change PERMANENTLY the coordinates system for the screen? Normally the (0,0) is upper left, (width-1,height-1) lower right.

I found a partial solution by means of translate()+scale() in draw() but they are far from being intuitive. You even need to resize strokeWeight().
I was think of something to set once for all in setup().

Sometimes it would be nice to use different systems: i.e. if you want to visualize the sin() function it would be nice to redefine the screen as y+1.1 up, y-1.1 down, x-5 left, x+5 right. Every point() and strokeWeight() would be resized accordingly.

Is there any library available to provide this function?
Apok
Re: New coordinates reference
Reply #1 - Aug 26th, 2009, 2:15pm
 
Scale affects strokeWeight for me...not sure what you mean.

Example:

Quote:
int scaleNum=1;

void setup(){
  size(640,480);
  background(255);
  strokeWeight(10);
}

void draw(){
  scale(scaleNum);
  line(pmouseX,pmouseY,mouseX,mouseY);
}

void keyPressed(){
  if (key=='1') scaleNum=1;
  else if (key=='2') scaleNum=2;
  else if (key=='3') scaleNum=3;
  else if (key=='4') scaleNum=4;
  else if (key=='c') background(255); // clear
}


if you need to flip coordinates or map them to a subsection of your area, check out map().

--Ben
Re: New coordinates reference
Reply #2 - Aug 27th, 2009, 2:29pm
 
Definitely: scale() changes strokeWeight().

Apok wrote on Aug 26th, 2009, 1:31pm:
I found a partial solution by means of translate()+scale() in draw() but they are far from being intuitive. You even need to resize strokeWeight().
I was think of something to set once for all in setup().


My "problem": I was visualizing y=sin(x) and my code contained "ugly" scale corrections to represent the function in a 400x400 screen.

So I used map() but every time I wanted to print a point, line, etc I had to remember to use map(). Not elegant at all.

Last try: I used a combination of translate() and scale() to represent correctly my interval (y=+1 top, y=-1 bottom, x=-1 left, x=+1 right) but then I needed to remember to correct strokeWeight() around the code because of the changed scale factor.
Code:
translate(0, height);
scale(width/2, -height/2); // this is to scale x&y and reverse y
translate(1.0, 1.0);  // (0,0) is screen center
strokeWeight(1.0/width);  // stroke has to be compensate
                            // for the scale change

Wouldn't it be better to have a single function in setup() to define which part of screen to magnify (with or without stroke magnification)?
It would be great to study mathematical functions. As soon as a function is "out of screen" you just change a parameter and automatically the rest of the code is ok.

Is there any library that provides it?

Apok
Page Index Toggle Pages: 1