processing OOP
- Started
- Last post
- 5 Responses
- DeIntegro
I'm having trouble with some objects in processing.
the code should have two objects displayed and moving. but i only see one object displayed and moving. maybe there's something i'm missing. check out the code.Rule myRule;
Rule myRule1;void setup() {
size(200,200);
smooth();//Initialize rule objects
myRule = new Rule(0,100,1);
myRule1 = new Rule(0,110,1);
}void draw() {
background(255);
//int x1 = 0;
//int y1 = 0;
//Operate Rule object
myRule.move();
myRule.display();
myRule1.move();
myRule1.display();
}class Rule {
float x;
float y;
float spacing;
float speed;Rule(float x1, float y1, float s1) {
x = x1;
y = y1;
spacing = 10;
speed = s1;
}void move() {
x = x + speed;
if((x > width) || (x < 0)) {
speed = speed * -1;
}}
//Display lines at x location
void display() {
stroke(0);
fill(175);
line(x, height/2, width/2, height/2);
}}
- Anders0
Something like this:
//Initialize rule objects
myRule = new Rule(0,100,1);
myRule1 = new Rule(110,140,2);
}
- DeIntegro0
@ Anders still didn't work!
@acescence they're 10 pixels apart, or they're supposed to be. but moving at same speed.
- DeIntegro0
ok guys...solved it! apparently the y of point B in the line was sitting on top of the y when i gave it a location of height/2...
//Display lines at x location
void display() {
stroke(0);
fill(175);
line(x, y, width/2, y);
}}
- i think that i couldn't pass any values into the function because of height/2 will still like to understand it, but not sure i doDeIntegro