code: def river_erosion(self, river, world):
          
  
          # erosion around river, create river valley
          for r in river:
              rx, ry = r
              radius = 2
              for x in range(rx - radius, rx + radius):
                  for y in range(ry - radius, ry + radius):
                      if not self.wrap and not world.contains(
                              (x, y)):  # ignore edges of map
                          continue
                      x, y = overflow(x, world.width), overflow(y, world.height)
                      curve = 1.0
                      if [x, y] == [0, 0]:  # ignore center
                          continue
                      if [x, y] in river:  # ignore river itself
                          continue
                      if world.layers['elevation'].data[y, x] <= world.layers['elevation'].data[ry, rx]:
                          # ignore areas lower than river itself
                          continue
                      if not in_circle(radius, rx, ry, x,
                                       y):  # ignore things outside a circle
                          continue
  
                      adx, ady = math.fabs(rx - x), math.fabs(ry - y)
                      if adx == 1 or ady == 1:
                          curve = 0.2
                      elif adx == 2 or ady == 2:
                          curve = 0.05
  
                      diff = world.layers['elevation'].data[ry, rx] - world.layers['elevation'].data[y, x]
                      newElevation = world.layers['elevation'].data[y, x] + (
                          diff * curve)
                      if newElevation <= world.layers['elevation'].data[ry, rx]:
                          print('newElevation is <= than river, fix me...')
                          newElevation = world.layers['elevation'].data[r, x]
                      world.layers['elevation'].data[y, x] = newElevation
          return
docs: Simulate erosion in heightmap based on river path.
              * current location must be equal to or less than previous location
              * riverbed is carved out by % of volume/flow
              * sides of river are also eroded to slope into riverbed.