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 in processing
Page Index Toggle Pages: 1
new in processing (Read 602 times)
new in processing
Mar 21st, 2006, 4:38pm
 
hi guys,

i m sooon here and i just started to pick up processing.

i m working on some very basic stuff but it seems to be some error somewhere but i don't know how to resolve it. may be some of you can help. thanks!

i try to build a small apps that create a rect to follow mouse movement. what i want is to have a little delay(or friction) for the box while moving towards the mouse. here is what i have:

-------------------------
mouseFlw m1;

void setup(){
size(400,400);
rectMode(CENTER);
fill(100,200);
noStroke();
m1 = new mouseFlw(100,100);
}

void draw(){
background(100);
m1.delayXY(mouseX,mouseY,30);
}

class mouseFlw{
float xpos;
float ypos;

mouseFlw(float xx, float yy){
xpos=xx;
ypos=yy;
}
}

void delayXY(float posX, float posY, float friction){
float diffX= xpos - posX;
if(abs(diffX)>1){
 xpos -=diffX/friction;
}
float diffY= ypos - posY;
if(abs(diffY)>1){
 ypos -=diffY/friction;
}
rect(xpos,ypos,30,30);
}

------------------------------

it keeps telling me that ypos is not accessible or something. any idea?? thanks!

sooon.process
Re: new in processing
Reply #1 - Mar 22nd, 2006, 8:54am
 
your problem is here
Code:

class mouseFlw{
float xpos;
float ypos;

mouseFlw(float xx, float yy){
xpos=xx;
ypos=yy;
}
}

void delayXY(float posX, float posY, float friction){
float diffX= xpos - posX;
if(abs(diffX)>1){
xpos -=diffX/friction;
}
float diffY= ypos - posY;
if(abs(diffY)>1){
ypos -=diffY/friction;
}
rect(xpos,ypos,30,30);
}


in function delayXY you are referring to (I assume) the ypos in the object. Yet you've passed no instance of the object into the function from which to work. What you are looking for should be:

OBJECTNAME.ypos;

That should return the ypos for that object only, where OBJECTNAME is the instance name of the object you've passed it. It is a common early OOP mistake :]
Re: new in processing
Reply #2 - Mar 25th, 2006, 4:43am
 
thanks mflux.

i kind of confuse here Tongue.

ok, first, the objeccname you refered to is it the class name? or the instance name?

because i guess the reason i use the delayXY is i wanted it to be dynamic so that i can assign it to other instances.

do you have an example how i can declare the objectname and use it dynamically??

thanks!

sooon
Re: new in processing
Reply #3 - Mar 25th, 2006, 6:00am
 
yes,

i figured out the problem:

here is my latest code:

-------------------------------------
//a very simple delay movement
mousesquare ms1,ms2,ms3,ms4;

void setup(){
size(400,400);
rectMode(CENTER);
fill(120);
noStroke();
framerate(60);
ms1=new mousesquare(100,100);
ms2=new mousesquare(100,100);
ms3=new mousesquare(100,100);
ms4=new mousesquare(100,100);
}
//for loop,
void draw(){
 background(200);
 ms1.display();
 ms2.display();
 ms3.display();
 ms4.display();
 ms1.moveto(mouseX,mouseY,2);
 ms2.moveto(mouseX,mouseY,5);
 ms3.moveto(mouseX,mouseY,10);
 ms4.moveto(mouseX,mouseY,20);
}

class mousesquare{
float xpos;
float ypos;

mousesquare(float xx,float yy){
  xpos=xx;
  ypos=yy;
}


void moveto(float tarX,float tarY,int friction){
  float difx=tarX-xpos;
 if(abs(difx)>1.0){
  xpos +=difx/friction;
 }
 float dify=tarY-ypos;
 if(abs(dify)>1.0){
  ypos +=dify/friction;
 }
}

void display(){
  rect(xpos,ypos,30,30);
 }
}
-------------------------

the mistake is i void the display() outside of the object class, that is why the xpos and ypos is not defined so that cannot be access.

ok, good lesson finally. thanks to mflux for enlightening Smiley

sooon
Re: new in processing
Reply #4 - Mar 25th, 2006, 7:15pm
 
Quick tidbit for you.  You might consider making a mousesquare array so you can easily change the number of squares without having to make calls to each one specifically.

Code:

mousesquare[] ms;
int totalsquares;

void setup(){
size(400,400);
rectMode(CENTER);
fill(120);
noStroke();
framerate(60);

totalsquares = 15;
ms = new mousesquare[totalsquares];

for (int i=0; i<totalsquares; i++){
ms[i] = new mousesquare(100,100);
}
}

void draw(){
background(200);
for (int i=0; i<totalsquares; i++){
ms[i].display();
ms[i].moveto(mouseX,mouseY,((i*3)+2));
}
}


This way, you can change the number of squares and see the effect without having to code out each 'display' and 'moveto'.  Thought it might help.

-robert
Re: new in processing
Reply #5 - Mar 26th, 2006, 5:31am
 
hi flight404,

wow! i don't expect you to answer Tongue

i m a big fans of yours. i love your version 7 which i find is the sexiest website i ever seen.

anyway, i kind of study your version 8 website and have no idea how you manage to get the processing running fullscreen in browser still make it run smoothly. how did you do that?? and did you splited up processing into small pieces so that it loaded faster or is just 1 .jar file to process the entire website??

and how to do the loading...xx% thingy?? sorry that i have so many questions for you but i just the beginner scripter here so i guess i got a lot more to learn.

but thanks for helping.

sooon
Re: new in processing
Reply #6 - Mar 26th, 2006, 9:25am
 
Well, its easy enough to answer.  The website is Flash.  Just remember that Processing isn't a substitute for Flash nor is it an easy way to make websites. I dont even know how to implement a Java preloader.  

But thanks for the kind words.  Good luck to you and I hope you find Processing to be as rewarding as I have.  Be careful though... it can be quite addictive.  Wink
Re: new in processing
Reply #7 - Mar 26th, 2006, 4:41pm
 
i really speechless...

hahahaha. i was cheated by your processing stuff in it. hmm... ok. now i know.

yes i started to enjoy like those day when i started to learn actionscript in flash. and now i make myself try to learn a thing everyday. so that 3 months later i can already build stuff with it.

sooon
Page Index Toggle Pages: 1