Two classes in one sketch?
in
Programming Questions
•
1 year ago
Hi,
Is writing two classes in one sketch not allowed?
I get the error:
Shane
Is writing two classes in one sketch not allowed?
I get the error:
expecting TRIPLE_DOT, found',
- Control mouse; //Declare the object called mouse
- Field vectors;
- int r, g, b;
- void setup() {
- size(600, 300);
- smooth();
- noStroke();
- //x, y, r, g, b, count, diameter... the fields
- mouse = new Control(300, 150, 0, 0, 255, 1, 150); //Construct the object mouse
- // x1, y1, x2, y2
- vectors = new Field(100, 100, 300, 300);
- }
- void draw() {
- frameRate(24);
- background(#36B5F2);
- mouse.move();
- mouse.display();
- }
- void vectors() {
- vectors.plot();
- }
- void mouseReleased() {
- if (mouseButton == CENTER) {
- mouse.released();
- }
- }
- class Control {
- float x, y, r, g, b, diameter;
- int count;
- //Constructor
- Control(float xpos, float ypos, float rpos, float gpos, float bpos, int countpos, float diameterpos) {
- x = xpos;
- y = ypos;
- r = rpos;
- g = gpos;
- b = bpos;
- count = countpos;
- diameter = diameterpos;
- }
- void move() {
- if (((dist(mouseX, mouseY, x, y))<(diameter/2))&&(mousePressed == true)) {//tests to see if mouse is on charge
- if (mouseButton == LEFT) {
- x = mouseX;
- y = mouseY;
- }
- else if (mouseButton == RIGHT) {//dragging mouse toward centre decreases size of charge
- if (((dist(mouseX, mouseY, x, y))-(dist(pmouseX, pmouseY, x, y)))>(0)) {
- diameter = diameter + 5; //increases size of diameter
- } //dragging mouse away from center increases size of charge
- else if (((dist(mouseX, mouseY, x, y))-(dist(pmouseX, pmouseY, x, y)))<(0)) {
- if (diameter > 20) {//prevents diameter getting too small and circle disappearing
- diameter = diameter - 5; // decreases size of diameter
- }
- }
- }
- }
- }
- void display() {
- fill(r, g, b);//fills the circle with colours red, green, blue
- ellipse(x, y, diameter, diameter);
- }
- void released() {
- if (((dist(mouseX, mouseY, x, y))<(diameter/2))) {//tests to see if mouse is on charge
- count = (count + 1) % 2;
- if (count == 1) {//sets colour to blue once
- r = 0;
- b = 255;
- }
- else if (count == 0) {//set colour red to blue
- r = 255;
- b = 0;
- }
- }
- }
- }
- class Field {
- float x1, y1, x2, y2;
- //Constructor
- Control(float x1pos, float y1pos, float x2pos, float, y2pos) {
- x1 = x1pos;
- y1 = y1pos;
- x2 = x2pos;
- y2 = y2pos;
- void vectors() {
- line(x1, y1, x2, y2);//this is just as an example
- }
- }
Shane
1