Skip to content

Instantly share code, notes, and snippets.

@mousetail
Created November 29, 2017 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mousetail/98c42b16a576acd2936555c37e242d76 to your computer and use it in GitHub Desktop.
Save mousetail/98c42b16a576acd2936555c37e242d76 to your computer and use it in GitHub Desktop.
#python 3.5
#requires pygame and numpy
#loads a map from "Interactive website/worldMapBlue.png"
#saves result to "Interactive website/blue-world-map.png"
import pygame
import pygame.gfxdraw
import numpy
import math
from math import cos, sin
width=4000
height=2000
fgcolor = (0x66, 0xea, 0xff)
bgcolor = (0x00, 0x63, 0x84)
finalwidth = 2000
finalheight = 1000
radius = 3
anglex = math.radians(13)
angley = math.radians(77)
surf1 = pygame.surface.Surface((width, height), pygame.SRCALPHA)
surf1.fill((0,0,0,0))
surf2 = pygame.surface.Surface((width, height), pygame.SRCALPHA)
surf2.fill((0,0,0,0))
matrix = numpy.dot([[1, 0, 0], [0, cos(anglex), sin(anglex)], [0, -sin(anglex), cos(anglex)]],
[[cos(angley), 0, sin(angley)], [0, 1, 0], [-sin(angley), 0, cos(angley)]])
img = pygame.image.load("Interactive website/worldMapBlue.png")
imgsize=img.get_size()
def fromPolar(theta, phi):
return (math.sin(theta)*math.cos(phi),
math.cos(theta)*math.cos(phi),
math.sin(phi))
def toPolar(vector):
return (math.atan2(vector[0],vector[1]),
math.atan2(vector[2],
math.sqrt(vector[0]*vector[0]+vector[1]*vector[1]))
)
def getImageCoords(pos):
return int(rad2[0]*imgsize[0]/360) % imgsize[0], int((rad2[1]+90)*imgsize[1]/180) % imgsize[1]
for i in range(width):
if (i%100 == 0):
print ("row", i)
for j in range(height):
rad = (i*2*math.pi/(width) - math.pi, j * math.pi/height - math.pi/2)
vec = list(fromPolar(*rad))
vec=numpy.dot(vec, matrix)
rad2 = tuple(math.degrees(i) for i in toPolar(vec))
imgcoords = getImageCoords(rad2)
try:
if img.get_at(imgcoords)[2]>0x85:
pygame.draw.circle(surf1, (0,0,0), (i,j), radius)
except IndexError:
raise IndexError(imgcoords)
if (int(rad2[0])//2)%10 == 0 or (int(rad2[1])//2)%10 == 0:
pygame.draw.circle(surf2, fgcolor, (i, j), radius)
surf1.blit(surf2,(0,0))
pygame.image.save(pygame.transform.smoothscale(surf1, (finalwidth, finalheight)), "Interactive website/blue-world-map.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment