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 › Calculation problem.
Page Index Toggle Pages: 1
Calculation problem. (Read 524 times)
Calculation problem.
Apr 8th, 2009, 6:58pm
 
Hello, hoping to find some help.
I've grown quite fond of placing shapes in relation to the size of the screen (width and height), but have found that the calculations made to width and height doesn't add up to what i get on my calculator. This is a problem as the shapes i draw wind up in slightly wrong places.

375/6*5 = 312,5 and 500/8 = 62,5
but the println says otherwise. How can this be?

Code:
void setup() {
 size(375, 500);
 rectMode(CENTER);
}

void draw() {
 background(255);
 noStroke();
 fill(0, 50);
 rect(312.5, 62.5, 75, 75);
 rect(width/6*5, height/8, 75, 75);
 println(width/6*5 + " , " + height/8 + " ; " + 375/6*5 + " , " + 500/8);
}
Re: Calculation problem.
Reply #1 - Apr 8th, 2009, 7:11pm
 
just add .0 to one of them to make it float
http://processing.org/reference/troubleshooting/#integers


void setup() {
 size(375, 500);
 rectMode(CENTER);
}

void draw() {
 background(255);
 noStroke();
 fill(0, 50);
 rect(312.5, 62.5, 75, 75);
 rect(width/6.0*5.0, height/8.0, 75, 75);
 println(width/6*5.0 + " , " + height/8.0 + " ; " + 375/6*5.0 + " , " + 500/8.0);
}
Re: Calculation problem.
Reply #2 - Apr 8th, 2009, 7:19pm
 
aah, that's awfully simple. Many thanks.
Page Index Toggle Pages: 1