class line {
color a;
float xpos;
float ypos;
float x2pos;
float y2pos;
float xspeed;
righteye(color tempA,float tempXpos,float tempYpos,float tempXspeed) {
a = tempA;
xpos = tempXpos;
ypos = tempYpos;
x2pos = xpos - 10;
y2pos =ypos + 10;
xspeed =tempXspeed;
}
void display() {
stroke(0);
fill(a);
line(xpos,ypos,x2pos,y2pos);
}
void drive() {
xpos = xpos + xspeed;
x2pos = x2pos + xspeed;
if (xpos>width){
xpos =10;
x2pos = 0;
}
}
}
.....
.....
line myline;
void setup() {
size (200,200);
myline = new line(color(255,0,0),10,100,1);
}
void draw() {
background(255);
myline.display();
myline.drive();
}
i'm a beginner,not good at computer. i want to let a line horizontal move on the editor window , i tried to use the "class" to do it ,but it doesn't work....
i'm stupid, haven't any conception about it....
what's the right way?
color a;
float xpos;
float ypos;
float x2pos;
float y2pos;
float xspeed;
righteye(color tempA,float tempXpos,float tempYpos,float tempXspeed) {
a = tempA;
xpos = tempXpos;
ypos = tempYpos;
x2pos = xpos - 10;
y2pos =ypos + 10;
xspeed =tempXspeed;
}
void display() {
stroke(0);
fill(a);
line(xpos,ypos,x2pos,y2pos);
}
void drive() {
xpos = xpos + xspeed;
x2pos = x2pos + xspeed;
if (xpos>width){
xpos =10;
x2pos = 0;
}
}
}
.....
.....
line myline;
void setup() {
size (200,200);
myline = new line(color(255,0,0),10,100,1);
}
void draw() {
background(255);
myline.display();
myline.drive();
}
i'm a beginner,not good at computer. i want to let a line horizontal move on the editor window , i tried to use the "class" to do it ,but it doesn't work....
i'm stupid, haven't any conception about it....
what's the right way?
1