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 › Help with classes, program isn't running
Pages: 1 2 
Help with classes, program isn't running (Read 2836 times)
Re: Help with classes, program isn't running
Reply #15 - Mar 10th, 2010, 8:12am
 
I changed this bit:

Code:
void move() {
ypos=ypos+speed;
speed=speed+gravity;
if (ypos>=groundlevel && speed>0) {
speed=speed*-.6; //This achieves the gravity effect. Mulitplying by -.95 decreases the bounce level each bounce.
}
}


What was happening is that the balls were getting below the ground  - draw takes place at certain intervals, so between these intervals the balls can get slightly below the ground. What then happens is that the ball's speed is repeatedly multiplied by the deceleration factor, so they get stuck.

I changed the code so that the deceleration factor can only be applied if the balls are moving down - so this can only happen once, and then the ball has to bounce up and come down before it can happen again.

I also reduced the factor from 0.95 to 0.6 which makes the balls bounce lower. You can also reduce gravity to 0.03 (or lower) so that they have less speed when hitting the ground (and bounce even lower).
Re: Help with classes, program isn't running
Reply #16 - Mar 10th, 2010, 12:09pm
 
Thanks; I like what that did to my program. I'm trying to get all the faces to come to together wherever my mouse is when I click. I tried this having a followmouse() function, and this being the function in the class:
Code:
  void followmouse() {
if (mousePressed==true){
xpos=mouseX;
ypos=mouseY;
}
}


But of course that just brought them all together at the same time when I clicked. What I'm trying to achieve is more of a follow-the-mouse sort of thing. Such as "if mouse clicked, then xpos get closer but do not surpass mouseX and ypos get closer but do not surpass mouseY." Yet I can't figure out how to transform that into code. I don't think a constrain() function is what I'm looking for.  Huh
Re: Help with classes, program isn't running
Reply #17 - Mar 10th, 2010, 2:38pm
 
Here's a program you can modify/incorporate to achieve this (this is a modification from "ravenous triangle" in Ira Greenberg's excellent processing book).

Code:
float x, y;

void setup()
{
background(255);
size(400,400);
x=width/2;
y=height/2;
smooth();
}

void draw()
{
fill(255, 40);
//rect(0,0, width, height);
float deltaX= (pmouseX-x);
float deltaY= (pmouseY-y);

x+=deltaX/10;
y+=deltaY/10;
ellipse(x,y, 15, 15);
}
Pages: 1 2