Why this would draw the trip?

I’m reading the following class

class Trips {

 int tripFrames;
 int startFrame;
 int endFrame;
 Location start;
 Location end;
 Location currentLocation;
 ScreenPosition currentPosition;
 int s;
 float bearing;
 float radians;
 float xscale = 1.8;
 float yscale = 0.8;

 // class constructor
 Trips(int duration, int start_frame, int end_frame, Location startLocation, Location endLocation, float _bearing) {
       tripFrames = duration;
       startFrame = start_frame;
       endFrame = end_frame;
       start = startLocation;
       end = endLocation;
       bearing = _bearing;
       radians = radians(bearing);
     }

   // function to draw each trip
   void plotRide(){
     if (frameCount >= startFrame && frameCount < endFrame){
       float percentTravelled = (float(frameCount) - float(startFrame)) / float(tripFrames);

       currentLocation = new Location(

         lerp(start.x, end.x, percentTravelled),
         lerp(start.y, end.y, percentTravelled));

       currentPosition = map.getScreenPosition(currentLocation);

       // Zoom dependent ellipse size
       float z = map.getZoom();
       if (z <= 32.0){ s = 2;
       } else if (z == 64.0){ s = 2;
       } else if (z == 128.0){ s = 2;
       } else if (z == 256.0){ s = 3;
       } else if (z == 512.0){ s = 4;
       } else if (z == 1024.0){ s = 5;
       } else if (z == 2048.0){ s = 6;
       } else if (z == 4096.0){ s = 7;
       } else if (z == 8192.0){ s = 8;
       } else if (z >= 16384.0){ s = 10;
       }


       if (rotateBearing == false) ellipse(currentPosition.x, currentPosition.y, s, s);
       else {
         pushMatrix();
         pushStyle();
           translate(currentPosition.x, currentPosition.y);
           rotate(radians + PI/2);
           rectMode(CENTER);
           rect(0, 0, s*xscale, s*yscale, 7);
         popStyle();
         popMatrix();
       }
    }
  }

  void plotBus(){
     if (frameCount >= startFrame && frameCount < endFrame){
       float percentTravelled = (float(frameCount) - float(startFrame)) / float(tripFrames);

       currentLocation = new Location(

         lerp(start.x, end.x, percentTravelled),
         lerp(start.y, end.y, percentTravelled));

       currentPosition = map.getScreenPosition(currentLocation);

       // Zoom dependent ellipse size
       float z = map.getZoom();
       if (z <= 32.0){ s = 2;
       } else if (z == 64.0){ s = 2;
       } else if (z == 128.0){ s = 2;
       } else if (z == 256.0){ s = 3;
       } else if (z == 512.0){ s = 4;
       } else if (z == 1024.0){ s = 5;
       } else if (z == 2048.0){ s = 5;
       } else if (z == 4096.0){ s = 6;
       } else if (z == 8192.0){ s = 7;
       } else if (z >= 16384.0){ s = 9;
       }
       if (rotateBearing == false) ellipse(currentPosition.x, currentPosition.y, s, s);
       else {
         pushMatrix();
         pushStyle();
           translate(currentPosition.x, currentPosition.y);
           rotate(radians + PI/2);
           rectMode(CENTER);
           rect(0, 0, s*xscale, s*yscale, 7);
         popStyle();
         popMatrix();
       }
   }
  }
}

I do not understand that, why this would draw the route/trip in a map? Could anyone explain a bit more about it?

A class is only the cookie maker, not the cookies

You need a program that makes the cookie and displays it

The lerp lines calculate the current position on a straight line between start point and end point of the bus tour

1 Like

Thank you for your quick reply. I know what you mentioned. I just did not quite see the logic/idea/thought to draw the trip/route along a given map.

Yeah… maybe the class doesn’t represent the whole bus trip but rather only the trip between 2 bus stops on a bus trip of about 20 stops

Then you would make an ArrayList of this class holding multiple stops and follow the ArrayList and inside this follow the path between 2 stops

ArrayList<Trips> busTour = new ArrayList();

https://www.processing.org/reference/ArrayList.html

but sure, one could also expect that the resolution (so to speak) is in the data so that the bus would follow exactly the streets and not go from start to end with a straight line

Chrisir

1 Like