Counting a Charakter
in
Programming Questions
•
2 years ago
Hey Guys,
I'm new to Processing and working on the Tutorials. After watching the the tutorials until the "OOP" Part, i tried to play with the things i've learned.
The Code is about creating two Cars with one Constructor. You may see that it is quite the same code as in the tutorial:
I know how to solve the problem. I've just to copy this 3 lines and rename it to myCar2 && myCar3.
But my question is,... can i actually count it? On line 4 I created an array with 3 integer.
and on line 15 I created an counter. I thougt something like
But it will not work for line 17-19:
Thanks a lot :)
I'm new to Processing and working on the Tutorials. After watching the the tutorials until the "OOP" Part, i tried to play with the things i've learned.
The Code is about creating two Cars with one Constructor. You may see that it is quite the same code as in the tutorial:
- Car myCar1;
- Car myCar2;
- Car myCar3;
- int[] numbers = { 90, 100, 30 };
- void setup() {
- size(200,200);
- smooth();
- frameRate(100);
- // Parameters go inside the parentheses when the object is constructed.
- myCar1 = new Car(color(255,0,0),0,numbers[0],2);
- myCar2 = new Car(color(0,0,255),0,numbers[1],PI/2);
- myCar3 = new Car(color(0,255,255),0,numbers[2],PI/2/PI*2);
- }
- void draw() {
- for (int go_on = 0; go_on < 3; go_on++){
- background(255);
- myCar1.colour();
- myCar1.drive();
- myCar1.display();
- }
- }
- class Car {
- color c;
- float xpos;
- float ypos;
- float xspeed;
- // The Constructor is defined with arguments.
- Car(color tempC, float tempXpos, float tempYpos, float tempXspeed) {
- c = tempC;
- xpos = tempXpos;
- ypos = tempYpos;
- xspeed = tempXspeed;
- }
- void display() {
- stroke(0);
- ellipseMode(CENTER);
- ellipse(xpos,ypos,20,10);
- }
- void colour() {
- fill(255-mouseY,0,0);
- }
- void drive() {
- xpos = xpos + xspeed;
- if (xpos > width) {
- xpos = 0;
- }
- }
- }
I know how to solve the problem. I've just to copy this 3 lines and rename it to myCar2 && myCar3.
But my question is,... can i actually count it? On line 4 I created an array with 3 integer.
and on line 15 I created an counter. I thougt something like
- String ncount = "myCar" + go_on;
But it will not work for line 17-19:
- ncount.colour();
- ncount.drive();
- ncount.display();
Thanks a lot :)
1
