Example #1
0
def Initialize():
    global WORLD_SIZE_X, WORLD_SIZE_Y, mapData, tileMaskData, wallTileMaskData, clientWorld
    WORLD_SIZE_X = 0
    WORLD_SIZE_Y = 0

    mapData = []
    tileMaskData = []
    wallTileMaskData = []

    clientWorld = None

    global BORDER_SOUTH, BORDER_NORTH, BORDER_WEST, BORDER_EAST
    BORDER_SOUTH = 0
    BORDER_NORTH = 0
    BORDER_WEST = 0
    BORDER_EAST = 0

    global WORLD_NAME
    WORLD_NAME = 0

    global NOISE, NOISE_OFFSETS
    NOISE = perlin.SimplexNoise()
    #create NOISE object
    NOISE_OFFSETS = [
        random.random() * 1000,
        random.random() * 1000,
        random.random() * 1000
    ]
    #randomly generate offsets

    global GRASS_GROW_TICK, GRASS_GROW_DELAY
    GRASS_GROW_DELAY = 2.5
    GRASS_GROW_TICK = GRASS_GROW_DELAY
Example #2
0
 def render(self):
     if (utils.sum_points_inside_flat_poly(*self.parent.canvas) <= 4):
         return
     color = random.choice(self.colors)
     for x in utils.iterate_points_inside_flat_poly(*self.parent.canvas):
         self.parent.parent.setblock(x + self.parent.loc, self.mat)
         if ((x.x + x.z) & 1 == 1):
             self.parent.parent.blocks[x + self.parent.loc].data = color[0]
         else:
             self.parent.parent.blocks[x + self.parent.loc].data = color[1]
     # Runined
     if (self.ruin is False):
         return
     pn = perlin.SimplexNoise(256)
     c = self.parent.canvasCenter()
     y = self.parent.canvasHeight()
     r = random.randint(1, 1000)
     maxd = max(1, self.parent.canvasWidth(), self.parent.canvasLength())
     for x in utils.iterate_points_inside_flat_poly(*self.parent.canvas):
         p = x + self.parent.loc
         d = ((Vec2f(x.x, x.z) - c).mag()) / maxd
         n = (pn.noise3((p.x + r) / 4.0, y / 4.0, p.z / 4.0) + 1.0) / 2.0
         if (n < d):
             self.parent.parent.setblock(p, materials._floor)
             self.parent.parent.blocks[p].data = 0
Example #3
0
class meta_class_mossystonebrick(MetaMaterial):
    name = 'meta_mossystonebrick'
    val = StoneBrick.val
    data = StoneBrick.data
    c = StoneBrick.c
    pn = perlin.SimplexNoise(256)

    def update(self, x, y, z, maxx, maxy, maxz):
        if random.randint(1, 100) < 7:
            self.val = CrackedStoneBrick.val
            self.data = CrackedStoneBrick.data
            self.c = CrackedStoneBrick.c
            return

        if random.randint(0, 100) < 2:
            self.val = ChiseledStoneBrick.val
            self.data = ChiseledStoneBrick.data
            self.c = ChiseledStoneBrick.c
            return

        if self.pn.noise3(x / 4.0, y / 4.0, z / 4.0) < 0:
            self.val = MossyStoneBrick.val
            self.data = MossyStoneBrick.data
            self.c = MossyStoneBrick.c
        else:
            self.val = StoneBrick.val
            self.data = StoneBrick.data
            self.c = StoneBrick.c
Example #4
0
class meta_class_stonedungeon(MetaMaterial):
    name = 'meta_stonedungeon'
    val = StoneBrick.val
    data = StoneBrick.data
    c = StoneBrick.c
    pn = perlin.SimplexNoise(256)

    def update(self, x, y, z, maxx, maxy, maxz):
        n = self.pn.noise3(x / 100.0, y / 100.0, z / 100.0)
        n = n + (float(y) / float(maxy)) * 2

        # Random broken stone brick in stone brick and cobble zones.
        if n <= 1.5:
            broken = .1 + (float(y) / float(maxy)) * .5
            if random.randint(1, 100) < broken * 10 + 5:
                self.val = CrackedStoneBrick.val
                self.data = CrackedStoneBrick.data
                self.c = CrackedStoneBrick.c
                return

        # Random circle stone in stone brick zones
        if n <= 1.0:
            if random.randint(0, 100) < 2:
                self.val = ChiseledStoneBrick.val
                self.data = ChiseledStoneBrick.data
                self.c = ChiseledStoneBrick.c
                return

        # Deepest areas are mossy cobble
        if (n > 1.5):
            if self.pn.noise3(x / 4.0, y / 4.0, z / 4.0) < 0:
                self.val = MossStone.val
                self.data = MossStone.data
                self.c = MossStone.c
            else:
                self.val = Cobblestone.val
                self.data = Cobblestone.data
                self.c = Cobblestone.c
        # Deep areas are cobble
        elif (n > 1.0):
            self.val = Cobblestone.val
            self.data = Cobblestone.data
            self.c = Cobblestone.c
        # lower areas as mossy brick
        elif (n > 0.5):
            if self.pn.noise3(x / 4.0, y / 4.0, z / 4.0) < 0:
                self.val = MossyStoneBrick.val
                self.data = MossyStoneBrick.data
                self.c = MossyStoneBrick.c
            else:
                self.val = StoneBrick.val
                self.data = StoneBrick.data
                self.c = StoneBrick.c
        # High areas are stone brick
        else:
            self.val = StoneBrick.val
            self.data = StoneBrick.data
            self.c = StoneBrick.c
Example #5
0
def zip_tuples_with_1D_perlin_noise(tuples: list) -> list:
    baseNoise = perlin.BaseNoise()
    simplexNoise = perlin.SimplexNoise()
    zipped_tuples = []
    for index, item in enumerate(tuples):
        noise = simplexNoise.noise2(index, 0)
        new_tuple = (*item, noise)
        zipped_tuples.append(new_tuple)
    return zipped_tuples
Example #6
0
 def world_gen(self):
     simplices = [(perlin.SimplexNoise(), 3**i) for i in range(1, 4)]
     for i in range(self.size_x):
         for j in range(self.size_y):
             self.tiles[i][j].land_height = sum([
                 simp[0].noise2(i / (16 * simp[1]), j / (16 * simp[1])) *
                 simp[1] for simp in simplices
             ])
             if self.tiles[i][j].land_height <= self.sea_level:
                 self.tiles[i][
                     j].water_height = self.sea_level - self.tiles[i][
                         j].land_height
             else:
                 self.tiles[i][j].water_height = 0
Example #7
0
 def ruinrender(self, ruinfactor=2.0):
     c = self.parent.canvasCenter()
     y = self.parent.canvasHeight()
     r = random.randint(1, 1000)
     maxd = max(1, self.parent.canvasWidth(), self.parent.canvasLength())
     pn = perlin.SimplexNoise(256)
     for x in utils.iterate_points_inside_flat_poly(*self.parent.canvas):
         p = x + self.parent.loc
         d = ((Vec2f(x.x, x.z) - c).mag()) / maxd
         n = (pn.noise3((p.x + r) / 4.0, y / 4.0, p.z / 4.0) + 1.0)
         n = n / ruinfactor
         if (n < d):
             self.parent.parent.setblock(p, materials._floor)
             self.parent.parent.blocks[p].data = 0
Example #8
0
def make_sign(template: Image.Image) -> Image.Image:
    """Generate the signage using the given template."""
    template = template.resize(SIZE, Image.BICUBIC)
    if template.mode == 'RGBA':
        template = template.split()[3]
    else:
        template = template.convert('L')

    BORDER = 6
    mask = Image.new('L', SIZE)
    middle = (BORDER, BORDER, 128 - BORDER, 128 - BORDER)
    mask.paste(template.crop(middle), middle)

    etching = Image.new('RGB', SIZE,
                        (ETCH_COLOR_R, ETCH_COLOR_G, ETCH_COLOR_B))

    per_r = perlin.SimplexNoise(32)
    per_g = perlin.SimplexNoise(32)
    per_b = perlin.SimplexNoise(32)

    for x in range(128):
        for y in range(128):
            etching.putpixel((x, y), (
                int(round(ETCH_COLOR_R + 5 * per_r.noise2(5 * x, 5 * y))),
                int(round(ETCH_COLOR_G + 5 * per_g.noise2(5 * x, 5 * y))),
                int(round(ETCH_COLOR_B + 5 * per_b.noise2(5 * x, 5 * y))),
            ))

    spin = random.choice(SPINS)
    if spin is not None:
        color = TEMPLATE_BG.transpose(spin)
    else:
        color = TEMPLATE_BG.copy()

    color.paste(etching, (0, 0, 128, 128), mask)

    return Image.merge('RGBA', color.split() + (TEMPLATE_ALPHA, ))
Example #9
0
class meta_class_mossycobblewall(MetaMaterial):
    name = 'meta_mossycobblewall'
    val = CobblestoneWall.val
    data = CobblestoneWall.data
    c = CobblestoneWall.c
    pn = perlin.SimplexNoise(256)

    def update(self, x, y, z, maxx, maxy, maxz):
        if self.pn.noise3(x / 4.0, y / 4.0, z / 4.0) < 0:
            self.val = MossStoneWall.val
            self.data = MossStoneWall.data
            self.c = MossStoneWall.c
        else:
            self.val = CobblestoneWall.val
            self.data = CobblestoneWall.data
            self.c = CobblestoneWall.c
Example #10
0
 def render(self):
     pn = perlin.SimplexNoise(256)
     if (utils.sum_points_inside_flat_poly(*self.parent.canvas) <= 4):
         return
     c = self.parent.canvasCenter()
     y = self.parent.canvasHeight()
     r = random.randint(1, 1000)
     maxd = max(1, self.parent.canvasWidth(), self.parent.canvasLength())
     for x in utils.iterate_points_inside_flat_poly(*self.parent.canvas):
         p = x + self.parent.loc
         d = ((Vec2f(x.x, x.z) - c).mag()) / maxd
         n = (pn.noise3((p.x + r) / 4.0, y / 4.0, p.z / 4.0) + 1.0) / 2.0
         if (n >= d + .20):
             self.parent.parent.setblock(p, materials.Sand)
         elif (n >= d + .10):
             self.parent.parent.setblock(p, materials.Sandstone)
         elif (n >= d):
             self.parent.parent.setblock(p, materials.Gravel)
Example #11
0
 def render(self):
     pn = perlin.SimplexNoise(256)
     if (utils.sum_points_inside_flat_poly(*self.parent.canvas) <= 4):
         return
     c = self.parent.canvasCenter()
     y = self.parent.canvasHeight()
     r = random.randint(1, 1000)
     maxd = max(1, self.parent.canvasWidth(), self.parent.canvasLength())
     for x in utils.iterate_points_inside_flat_poly(*self.parent.canvas):
         p = x + self.parent.loc
         d = ((Vec2f(x.x, x.z) - c).mag()) / maxd
         n = (pn.noise3((p.x + r) / 4.0, y / 4.0, p.z / 4.0) + 1.0) / 2.0
         if (n >= d + .50):
             self.parent.parent.setblock(p, materials.Water)
         elif (n >= d + .30):
             self.parent.parent.setblock(p, materials.SoulSand)
         elif (n >= d + .20):
             self.parent.parent.setblock(p, materials.Farmland)
             self.parent.parent.blocks[p].data = random.randint(0, 1)
         elif (n >= d + .10):
             self.parent.parent.setblock(p, materials.Podzol)
             self.parent.parent.blocks[p].data = 2  # Podzol data val
         elif (n >= d):
             self.parent.parent.setblock(p, materials.Dirt)
Example #12
0
 def render(self):
     pn = perlin.SimplexNoise(256)
     # Find all the valid halls. These are halls with a size > 0.
     # We'll store a random position within the range of the hall.
     halls = [0, 0, 0, 0]
     hallcount = 0
     wires = set()
     #wirehooks = set()
     for h in xrange(4):
         if (self.parent.halls[h].size > 0):
             halls[h] = \
                 self.parent.halls[h].offset + 1 + \
                 random.randint(0, self.parent.halls[h].size - 3)
             hallcount += 1
     # We won't draw just half a bridge, unless this is a sandpit. (yet)
     if (hallcount < 2 and self.sandpit is False):
         return
     midpoint = self.parent.parent.room_size / 2
     y = self.parent.canvasHeight()
     offset = self.parent.loc
     # Look for the X bounds between halls.
     if (halls[0] != 0 and halls[2] != 0):
         x1 = halls[0]
         x2 = halls[2]
     elif (halls[0] != 0):
         x1 = halls[0]
         x2 = x1
     elif (halls[2] != 0):
         x2 = halls[2]
         x1 = x2
     else:
         x1 = midpoint
         x2 = midpoint
     # Look for the Z bounds between halls.
     if (halls[1] != 0 and halls[3] != 0):
         z1 = halls[1]
         z2 = halls[3]
     elif (halls[1] != 0):
         z1 = halls[1]
         z2 = z1
     elif (halls[3] != 0):
         z2 = halls[3]
         z1 = z2
     else:
         z1 = midpoint
         z2 = midpoint
     # Now construct our points.
     # c1-4 are the corners of the connecting
     # box. h0-3 are the start points of the halls.
     c1 = Vec(x1, y, z1)
     c2 = Vec(x2, y, z1)
     c3 = Vec(x2, y, z2)
     c4 = Vec(x1, y, z2)
     h0 = Vec(x1, y, self.parent.hallLength[0])
     h1 = Vec(self.parent.parent.room_size - self.parent.hallLength[1] - 1,
              y, z1)
     h2 = Vec(x2, y,
              self.parent.parent.room_size - self.parent.hallLength[2] - 1)
     h3 = Vec(self.parent.hallLength[3], y, z2)
     # Sandpit?
     mat = random.choice(self.slabtypes)
     if (self.sandpit is True):
         # Draw the false sand floor
         mat = materials.Sand
         c = self.parent.canvasCenter()
         y = self.parent.canvasHeight()
         r = random.randint(1, 1000)
         maxd = max(1, self.parent.canvasWidth(),
                    self.parent.canvasLength())
         for x in utils.iterate_points_inside_flat_poly(
                 *self.parent.canvas):
             p = x + self.parent.loc
             d = ((Vec2f(x.x, x.z) - c).mag()) / maxd
             n = (pn.noise3(
                 (p.x + r) / 4.0, y / 4.0, p.z / 4.0) + 1.0) / 2.0
             if (n >= d + .10):
                 self.parent.parent.setblock(p, materials.Sand)
             elif (n >= d):
                 self.parent.parent.setblock(p, materials.Gravel)
             else:
                 self.parent.parent.setblock(p, materials._floor)
         # Find wire locations
         # h0
         # Cool fact: in 12w30c tripwires will trigger sand without hooks.
         if (halls[0] != 0):
             for x in xrange(1, self.parent.halls[0].size - 1):
                 p = Vec(self.parent.halls[0].offset + x, y - 1,
                         self.parent.hallLength[0])
                 # if x == 0:
                 #    wirehooks.add((p, 4+3))
                 # elif x == self.parent.halls[0].size-1:
                 #    wirehooks.add((p, 4+1))
                 # else:
                 #    wires.add(p)
                 wires.add(p)
         # h1
         if (halls[1] != 0):
             for x in xrange(1, self.parent.halls[1].size - 1):
                 wires.add(
                     Vec((self.parent.parent.room_size -
                          self.parent.hallLength[1] - 1), y - 1,
                         self.parent.halls[1].offset + x))
         # h2
         if (halls[2] != 0):
             for x in xrange(1, self.parent.halls[2].size - 1):
                 wires.add(
                     Vec(self.parent.halls[2].offset + x, y - 1,
                         (self.parent.parent.room_size -
                          self.parent.hallLength[2] - 1)))
         # h3
         if (halls[3] != 0):
             for x in xrange(1, self.parent.halls[3].size - 1):
                 wires.add(
                     Vec(self.parent.hallLength[3], y - 1,
                         self.parent.halls[3].offset + x))
         for p in wires:
             self.parent.parent.setblock(offset + p.down(1),
                                         materials.Gravel,
                                         lock=True)
             self.parent.parent.setblock(offset + p,
                                         materials.Tripwire,
                                         hide=True)
         # for p in wirehooks:
         #    self.parent.parent.setblock(offset+p[0].down(1), mat)
         #    self.parent.parent.setblock(offset+p[0],
         #                                materials.TripwireHook, p[1])
     # Draw the bridges, if a hallway exists.
     # h0 -> c1
     # h1 -> c2
     # h2 -> c3
     # h3 -> c4
     if (halls[0] != 0):
         for p in utils.iterate_cube(offset + h0, offset + c1):
             self.parent.parent.setblock(p, mat)
     if (halls[1] != 0):
         for p in utils.iterate_cube(offset + h1, offset + c2):
             self.parent.parent.setblock(p, mat)
     if (halls[2] != 0):
         for p in utils.iterate_cube(offset + h2, offset + c3):
             self.parent.parent.setblock(p, mat)
     if (halls[3] != 0):
         for p in utils.iterate_cube(offset + h3, offset + c4):
             self.parent.parent.setblock(p, mat)
     # Draw the connecting bridges.
     # c1 -> c2
     # c2 -> c3
     # c3 -> c4
     for p in utils.iterate_cube(offset + c1, offset + c2):
         self.parent.parent.setblock(p, mat)
     for p in utils.iterate_cube(offset + c2, offset + c3):
         self.parent.parent.setblock(p, mat)
     for p in utils.iterate_cube(offset + c3, offset + c4):
         self.parent.parent.setblock(p, mat)
Example #13
0
    def render(self):
        if (utils.sum_points_inside_flat_poly(*self.parent.canvas) <= 4):
            return
        color_profile = random.choice(self.colors)

        min_x = utils.floor(min([p.x for p in self.parent.canvas]))
        max_x = utils.ceil(max([p.x for p in self.parent.canvas]))
        min_z = utils.floor(min([p.z for p in self.parent.canvas]))
        max_z = utils.ceil(max([p.z for p in self.parent.canvas]))
        min_y = utils.floor(min([p.y for p in self.parent.canvas]))

        # Cut the canvas into quarters and fill one quarter with colors.
        # Then, copy that quarter into the other three quarters.
        width = utils.floor(((max_x - min_x + 1) + 1) / 2)
        depth = utils.floor(((max_z - min_z + 1) + 1) / 2)

        points = [[-1 for j in xrange(depth)] for i in xrange(width)]
        points_left = []
        for i in xrange(width):
            for j in xrange(depth):
                points_left.append((i, j))
        bounds = utils.Box(Vec(0, 0, 0), width, 1, depth)
        p = Vec(0, 0, 0)
        color_num = 0
        prev_dir = random.randint(0, 3)
        next_dir = random.randint(0, 3)
        while len(points_left) > 0:
            # pick random starting point and walk around the matrix
            point_index = random.randint(0, len(points_left) - 1)
            p = Vec(points_left[point_index][0], 0,
                    points_left[point_index][1])

            while (bounds.containsPoint(p) and points[p.x][p.z] == -1
                   and len(points_left) > 0):
                points[p.x][p.z] = color_num
                points_left.remove((p.x, p.z))

                # pick random direction to walk, try to keep walking same
                # direction
                if random.randint(0, self._walk_weight) != 0:
                    next_dir = prev_dir
                else:
                    while next_dir == prev_dir:
                        next_dir = random.randint(0, 3)
                if next_dir == 0:  # right
                    p += Vec(1, 0, 0)
                elif next_dir == 1:  # down
                    p += Vec(0, 0, 1)
                elif next_dir == 2:  # left
                    p += Vec(-1, 0, 0)
                else:  # up
                    p += Vec(0, 0, -1)
                prev_dir = next_dir
            color_num = (color_num + 1) % len(color_profile)

        for j in xrange(max_z - min_z + 1):
            for i in xrange(max_x - min_x + 1):
                p = self.parent.loc + Vec(min_x + i, min_y, min_z + j)
                self.parent.parent.setblock(p, self.mat)
                if i < width:
                    i_adj = i
                else:
                    i_adj = 2 * width - 1 - i
                if j < depth:
                    j_adj = j
                else:
                    j_adj = 2 * depth - 1 - j
                self.parent.parent.blocks[p].data = \
                    color_profile[points[i_adj][j_adj]]

        if not self.ruin:
            return
        # this chunk of code is copied from CheckerRug's render() method
        pn = perlin.SimplexNoise(256)
        c = self.parent.canvasCenter()
        y = self.parent.canvasHeight()
        r = random.randint(1, 1000)
        maxd = max(1, self.parent.canvasWidth(), self.parent.canvasLength())
        for x in utils.iterate_points_inside_flat_poly(*self.parent.canvas):
            p = x + self.parent.loc
            d = ((Vec2f(x.x, x.z) - c).mag()) / maxd
            n = (pn.noise3((p.x + r) / 4.0, y / 4.0, p.z / 4.0) + 1.0) / 2.0
            if (n < d):
                self.parent.parent.setblock(p, materials._floor)
                self.parent.parent.blocks[p].data = 0
Example #14
0
#!/usr/bin/env python
size = 16
factor = float(size) * 0.25
i = [' ', '.', ',', 'o', 'O', '@', '#']
import perlin

pn = perlin.SimplexNoise(256)
for y in xrange(size):
    for x in xrange(size):
        print i[int((pn.noise3(x / factor, 0, y / factor) + 1.0) / 2 * 6)],
    print
Example #15
0
from math import pi, sin, cos, sqrt
import random
import numpy
from numpy.linalg import norm
import perlin
import pyglet
from pyglet.gl import *

simplex = perlin.SimplexNoise()


def vec(*args):
    return (GLfloat * len(args))(*args)


def unit(v):
    return v / numpy.linalg.norm(v)


def spherePoint(yaw, pitch):
    x = cos(yaw) * cos(pitch)
    y = sin(pitch)
    z = sin(yaw) * cos(pitch)
    u = yaw / (2 * pi)
    v = (pitch + pi / 2) / pi
    return x, y, z, u, v


def buildSphere(resolution):
    vertices = []
    uvs = []
Example #16
0
RAD2DEG = 57.2957795
DEG2RAD = 0.0174532925
MINISCALE = 20.0
SEGLEN = 50
FRONT = 0
REAR = 1
PASS_BEHIND_CAR = 0
PASS_ALONG_CAR = 1
PASS_INFRONT_CAR = 2
PASS_COMPLETE = 3
LEFT_BLINKER = 1
RIGHT_BLINKER = 2

flow = Flow()
db = {}  # database list

hasWheel = False
joysticks = pyglet.input.get_joysticks()
joystick = 0

if joysticks:
    # x-axis: steering wheel left/right
    # y-axis: gass & brake
    joystick = joysticks[0]
    joystick.open()
    hasWheel = True

noise = perlin.SimplexNoise()
texture = []
scrubs = []