def main(): info() log("log", "PyViDb was executed!")
def plotmap(w=2560, h=-1, s=0, connect=True, connectfact=75): if h == -1: h = int(w / 16.0 * 9.0) img = Image.new("RGB", (w, h), (s, s, s)) draw = ImageDraw.Draw(img) citiesFile = open("import/cities.json", "r") cities = json.load(citiesFile) length = len(cities) debug = False if debug: coordVal = {"max0": -1, "min0": 1, "max1": -1, "min1": 1} reltoVal = {"max0": -1, "min0": 1, "max1": -1, "min1": 1} lines = 0 dld=[] for x in range(length): try: coord = cityCoords(cities[x]) relto = [intmap(-1 * coord[1], -180.0, 180.0, float(w), float(0)), intmap(coord[0], -90.0, 90.0, float(h), float(0))] if debug: if coord[0] > coordVal["max0"]: coordVal["max0"] = coord[0] if coord[0] < coordVal["min0"]: coordVal["min0"] = coord[0] if coord[1] > coordVal["max1"]: coordVal["max1"] = coord[1] if coord[1] < coordVal["min1"]: coordVal["min1"] = coord[1] if relto[0] > reltoVal["max0"]: reltoVal["max0"] = relto[0] if relto[0] < reltoVal["min0"]: reltoVal["min0"] = relto[0] if relto[1] > reltoVal["max1"]: reltoVal["max1"] = relto[1] if relto[1] < reltoVal["min1"]: reltoVal["min1"] = relto[1] if connect: fact = connectfact # smaller = more! mindist = dist([w,h],[0,0])/fact for y in range(x, length): ndcoord = cityCoords(cities[y]) ndrelto = [intmap(-1 * ndcoord[1], -180.0, 180.0, float(w), float(0)), intmap(ndcoord[0], -90.0, 90.0, float(h), float(0))] diffdist = dist(relto, ndrelto) if diffdist < mindist: print("Point {:>5x}x{:<5x} == {:7.2%}".format(x,y,x/length)) gc = int(255.0-255.0*math.pow(diffdist/mindist,4)) dld.append([ (relto[0], relto[1], ndrelto[0], ndrelto[1]) , "rgb(0, {:}, 0)".format(gc if gc > 0 else 0), gc]) lines += 1 for point in neighbor(relto): img.putpixel((point[0], point[1]), "rgb(43, 213, 0)") except Exception: pass try: os.mkdir(scriptDir + "gui") except FileExistsError: pass dld.sort(key=colorvalue) for line in dld: draw.line(line[0], fill=line[1]) log("GUI", "Created PlotMap (gui/plotmap.png)") del draw img.save(scriptDir + "gui/plotmap.png")