Setting up the coordinates

Computer technology determines the coordinates that processing uses. The distance between two pixels is the unit length and the origin lies at the upper left corner. This is not what we need in geometry and mathematics. Fortunately, processing has all tools needed to correct this.

With “translate(width/2,height/2)” we can put the origin in the center of the screen. With “scale(unitLength,-unitLength)” we can choose how many pixels correspond to one unit of length. Using a negative sign for the second parameter of “scale” we get a y-axis that goes up for increasing y, as usual. The only catch is that the width of the lines gets scaled too. We can correct this with a compensating division in “strokeWeight(…)”.

Finally, it is important to know which points are visible on the screen. Their x-coordinates go from -xRange to +xRange, where xRange=(width/2)/unitLength. The visible range of the y-axis is similarly defined.

And this is it:

float unitLength;
float xRange,yRange;     // visible coordinates from -(xy)Range to +(xy)Range

void setup(){

void draw(){

void setupCoordinates(){  

void trueStrokeWeight(float weight){



This entry was posted in programming and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.