# Why this would draw the trip?

**URL:** <https://discourse.processing.org/t/why-this-would-draw-the-trip/9086>\
**Category:** Coding Questions\
**Created:** [March 7, 2019, 4:56pm UTC](https://discourse.processing.org/t/why-this-would-draw-the-trip/9086 "2019-03-07T16:56:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kkxxbdm](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@kkxxbdm](https://discourse.processing.org/u/kkxxbdm)\
**Post date:** [March 7, 2019, 4:56pm UTC](https://discourse.processing.org/t/why-this-would-draw-the-trip/9086/1 "2019-03-07T16:56:19Z")

</div>

I’m reading the following class

```auto
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?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 7, 2019, 5:11pm UTC](https://discourse.processing.org/t/why-this-would-draw-the-trip/9086/2 "2019-03-07T17:11:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kkxxbdm](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@kkxxbdm](https://discourse.processing.org/u/kkxxbdm)\
**Post date:** [March 7, 2019, 5:18pm UTC](https://discourse.processing.org/t/why-this-would-draw-the-trip/9086/3 "2019-03-07T17:18:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 7, 2019, 5:36pm UTC](https://discourse.processing.org/t/why-this-would-draw-the-trip/9086/4 "2019-03-07T17:36:47Z")

</div>

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](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
