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 › use class with "for"
Page Index Toggle Pages: 1
use class with "for" (Read 707 times)
use class with "for"
Jan 8th, 2010, 1:46pm
 
hello
first i'm sorry for my bad english
i'm started with processing. i was in a workshop with simon Geilfus (Kinesis) in Brussel. now i want to work.

I try to use a class in a "for"
my class is ok, but i don't know how to use it with "for".

this is my code:

//-------------------------------------------------

class Tri {

 float x;
 float y;
 float h;
 float w;
 float c1;
 float c2;
 float c3;
 float c4;
 float x2;
 float y2;

 Tri(float _x, float _y, float _h, float _w, float _c1, float _c2, float _c3, float _c4){

   x = _x;
   y = _y;
   h = _h;
   w = _w;
   c1 = _c1;
   c2 = _c2;
   c3 = _c3;
   c4 = _c4;

 }

 void dessinerTri(){

   float centerX = mouseX;
   float centerY = mouseY;

   if(mouseX < x) centerX = x;
   if(mouseX > x+w) centerX = x+w;
   if(mouseY < y) centerY = y;
   if(mouseY > y+h) centerY = y+h;    

   fill(c1, random(mouseY), random(mouseX));
   triangle(centerX, centerY, x, y, x+w, y);
   fill(c2, random(mouseY), random(mouseX));
   triangle(centerX, centerY, x+w, y, x+w, y+h);
   fill(c3, random(mouseY), random(mouseX));
   triangle( x+w, y+h, centerX, centerY, x, y+h);
   fill(c4, random(mouseY), random(mouseX));
   triangle( x, y+h, centerX, centerY, x, y);

 }

}


//--------------------------------------------------------



void setup(){

 size(500,500);

}

void draw(){

 background(130);


 Tri tri01;
 tri01 = new Tri(10, 10, 30, 30, 10, 10, 10, 10);
 tri01.dessinerTri();


 //THIS IS THE "FOR" THAT I WANT USE
 
 /*

  for(int i=0;i<=500;i+=50){
  for(int j=0; j<= 500; j+=50){
  dessinerTri(i, j);
  }
  }
 
  */

}


i'm enjoy to integrate the processing community
thanks






Re: use class with "for"
Reply #1 - Jan 8th, 2010, 2:10pm
 
Should be tri01.dessinerTri(i, j);
Note: since the method is in Tri class, you can just call it dessiner(), since it will always be called in context.
Now, you also need to create a dessinerTri() method (or dessiner()) in Tri class, that accepts two arguments and does something with them...
Re: use class with "for"
Reply #2 - Jan 8th, 2010, 2:49pm
 
ok for tri01.dessinerTri(i, j);
But i don't understand how to create a dessinerTri() in Tri class, i thought already create it. and i don't know what is an argument. i'm a ultra novice.
Re: use class with "for"
Reply #3 - Jan 9th, 2010, 1:30am
 
Arguments are variables you pass to a function.
Code:

class Tri
{

 //This is a method without arguments
 void dessiner()
 {
    //...
 }

 //This is a method with arguments
 void dessiner(int x, int y)
 {
    //...
 }
}


You can then call a function of that class:

Code:

Tri tri = new Tri();
tri.dessiner(); //No arguments
tri.dessiner(50, 50); //With arguments
Page Index Toggle Pages: 1