Skip to content
This repository was archived by the owner on Mar 19, 2018. It is now read-only.

Commit a9608f9

Browse files
committed
tons of damage
1 parent 4cd20ab commit a9608f9

13 files changed

+246
-168
lines changed

Classes.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Color:
2+
3+
# 0 -> 255
4+
5+
r = 0.0;
6+
g = 0.0;
7+
b = 0.0;
8+
a = 1.0;
9+
10+
def __init__(self, r = 0.0, g = 0.0, b = 0.0):
11+
self.r = r;
12+
self.g = g;
13+
self.b = b;
14+
self.a = 1;
15+
def GetTuple(self):
16+
return (int(self.r),int(self.g),int(self.b));
17+
def SetColor(self, r, g, b):
18+
self.r = r;
19+
self.g = g;
20+
self.b = b;
21+
def Copy(self, color):
22+
self.r = color.r;
23+
self.g = color.g;
24+
self.b = color.b;
25+
def SetWhite(self):
26+
self.SetColor(1,1,1);
27+
def SetBlack(self):
28+
self.SetColor(0,0,0);
29+
def SetColorFromGrayscale(self, f = 0.0):
30+
self.SetColor(f,f,f);
31+
32+
paperColor = Color(212, 161, 104);
33+
waterColor = Color(0, 20, 28);
34+

Map.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from Classes import *
2+
import random
3+
4+
perlinOffset = random.random()*2048; # random offset
5+
6+
mapSize = 2048; # size in pixels
7+
perlinScale = 0.0025;
8+
mapCenter = (mapSize/2, mapSize/2);
9+
10+
landThreshold = 0.1;
11+
12+
heightMap = [[0]*mapSize for x in range(mapSize)]
13+
colorMap = [[Color() for j in range(mapSize)] for i in range(mapSize)]
14+
15+
randomColorRange = 10;
16+
colorPerlinScale = 0.025;

MapGenerator.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
print("Setting up... \n");
2+
3+
from PIL import Image
4+
5+
from Map import *
6+
from _Generators import *
7+
from Classes import *
8+
from VectorMath import *
9+
10+
image = Image.new("RGB", (mapSize,mapSize))
11+
targetGenerator = None
12+
13+
# future multiproc stuff
14+
15+
#import multiprocessing
16+
#
17+
#
18+
#def worker(index):
19+
# print("worker spawned ",index)
20+
# while(True):
21+
# if (targetGenerator == None or targetGenerator.isFinished):
22+
# break;
23+
# targetGenerator.GenerateAutomated();
24+
# for x in range(0, mapSize):
25+
# for y in range(0, mapSize):
26+
# im.putpixel((x,y), colorMap[x][y].GetTuple());
27+
28+
#threadsAmount = 1
29+
#threads = []
30+
31+
#if __name__ == '__main__':
32+
33+
# for i in range(threadsAmount):
34+
# print("starting process ", i);
35+
# t = multiprocessing.Process(target=worker, args=(i,))
36+
# threads.append(t)
37+
# t.start()
38+
39+
# for i in range(threadsAmount):
40+
# threads[i].join();
41+
42+
targetGenerator = MapGen_Main();
43+
44+
print("Generating... \n");
45+
46+
targetGenerator.GenerateFull();
47+
48+
print("\n\nGeneration finished. Saving output as Generated.png.");
49+
50+
for x in range(0, mapSize):
51+
for y in range(0, mapSize):
52+
image.putpixel((x,y), colorMap[x][y].GetTuple());
53+
54+
image.save("Generated.png");
55+
image.show();

PythonApplication2.py

-166
This file was deleted.

PythonApplication2.pyproj

+14-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<SchemaVersion>2.0</SchemaVersion>
66
<ProjectGuid>4510984d-d54c-4d27-afaf-8170b3504e71</ProjectGuid>
77
<ProjectHome>.</ProjectHome>
8-
<StartupFile>PythonApplication2.py</StartupFile>
8+
<StartupFile>MapGenerator.py</StartupFile>
99
<SearchPath>
1010
</SearchPath>
1111
<WorkingDirectory>.</WorkingDirectory>
@@ -22,7 +22,19 @@
2222
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
2323
</PropertyGroup>
2424
<ItemGroup>
25-
<Compile Include="PythonApplication2.py" />
25+
<Compile Include="Classes.py">
26+
<SubType>Code</SubType>
27+
</Compile>
28+
<Compile Include="Map.py">
29+
<SubType>Code</SubType>
30+
</Compile>
31+
<Compile Include="_Generators.py">
32+
<SubType>Code</SubType>
33+
</Compile>
34+
<Compile Include="MapGenerator.py" />
35+
<Compile Include="VectorMath.py">
36+
<SubType>Code</SubType>
37+
</Compile>
2638
</ItemGroup>
2739
<PropertyGroup>
2840
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>

VectorMath.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import math
2+
3+
def Distance(ax = 0.0, ay = 0.0, bx = 0.0, by = 0.0):
4+
x = ax - bx;
5+
x *= x;
6+
y = ay - by;
7+
y*= y;
8+
return (math.sqrt(x + y));
9+
10+
def DistanceNormalized(ax = 0.0, ay = 0.0, bx = 0.0, by = 0.0, size = 256):
11+
dist = Distance(ax, ay, bx, by);
12+
dist /= size;
13+
return dist;

0 commit comments

Comments
 (0)