def create_level(self):
        """Convert a list of points to a the level circuit"""
        thickness = 10 # thickness of the grass
        friction = 2 # friction of the grass


        noise=perlin.Perlin(25)

        # Points to create the map.
        self.points = [[-20,SCREEN_HEIGHT]]
        for x in range(100):
            self.points.append([(x-1)*60, (noise.valueAt(x) * 200) +470])

        self.points[-1][1] = SCREEN_HEIGHT

        # create the circuit
        for i in range(1, len(self.points)):
            body = pymunk.Body(body_type=pymunk.Body.KINEMATIC)
            floor = pymunk.Segment(body, (self.points[i-1][0], self.points[i-1][1]), (self.points[i][0], self.points[i][1]), thickness)
            #floor = pymunk.Segment(body, (x+points[i-1][0]*2, y+points[i-1][1]), (x+points[i][0]*2, y+points[i][1]), thickness)
            floor.friction = friction
            floor.elasticity = 0.5
            space.add(body, floor)

        # create the points for the sky
        self.sky_points = self.points
        self.sky_points.insert(0, ([0,0]))
        self.sky_points.append([self.points[-1][0]+SCREEN_WIDTH,SCREEN_HEIGHT])
        self.sky_points.append([self.sky_points[-1][0],0])
예제 #2
0
def gouradRing(render, x, y, **kwargs):
    w,v,u = kwargs["bar"]
    nA, nB, nC = kwargs["normales"]

    luz = kwargs["light"]
    normx = nA.x*w + nB.x*v + nC.x*u 
    normy = nA.y*w + nB.y*v + nC.y*u 
    normz = nA.z*w + nB.z*v + nC.z*u 
    vnormal = Vector3(normx, normy, normz)
    intensity = prodPunto(vnormal, luz)
    if intensity < 0:
        intensity =0
    elif intensity >1:
        intensity =1
    
    intensity *= 2

    # color de anillo 
    ring = (107,109,96)

    pnoise = p.Perlin()
    for m in range(800):
        for n in range(800):
            col = [int((pnoise.value(x/200.0, y/200.0, 0)+1) *200), ] *3
            mul = [int((ring[0]/255.0*col[0])* intensity),int((ring[1]/255.0*col[1])* intensity),
            int((ring[2]/255.0*col[2])* intensity)]
            if mul[0] < 0: mul[0] =0
            if mul[1] < 0: mul[1] = 0
            if mul[2] < 0: mul[2] = 0
            return color(mul[0], mul[1], mul[2])
예제 #3
0
def getTerrain(size, vertices, regions, cell_type, dist_to_coast, seed=None):
    if seed is None:
        seed = datetime.now().microsecond

    print("Calculating large-scale terrain...")

    print("Large-scale terrain seed: %d" % seed)
    np.random.seed(seed)

    noise = perlin.Perlin(size, 2, 3)

    elevations = [noise[v] for v in vertices]

    min_elevation = min(elevations)

    elevations = [(el - min_elevation)**2 * dc**0.2 if dc >= 0 else -1
            for el, dc in zip(elevations, dist_to_coast)]

    max_elevation = max(elevations)

    colors = [
            np.mean(np.array(elevations)[r]) / max(elevations) * (1-LAND) + LAND 
                if cell_type[i] == LAND
                else cell_type[i]
            for i, r in enumerate(regions)
            ]

    return colors
예제 #4
0
 def __init__(self, width, height, scale, octaves, persistence):
     self._width = width
     self._height = height
     self._scale = scale
     self._octaves = octaves
     self._persistence = persistence
     self._gen = perlin.Perlin(self.octaves, self.persistence)
예제 #5
0
def show_perlin_noise():
    noise=perlin.Perlin(15)

    time=[i for i in range(200)]
    values=[noise.valueAt(i) for i in time]

    plt.title("Perlin Noise")
    plt.xlabel("Time")
    plt.ylabel("Value")
    plt.plot(time, values)
    plt.show()
예제 #6
0
def graph(intensity):
    noise=perlin.Perlin(intensity)

    time=[i for i in range(100)]
    values=[noise.valueAt(i) for i in time]
    titlestring = "Average "+words[0][random.randint(0,len(words[0]))]+" size by age in the UK"
    plt.title(titlestring)
    plt.xlabel("Age")
    plt.ylabel("Size")
    plt.plot(time, values)
    plt.show()
예제 #7
0
def show_perlin_noise():
    noise = perlin.Perlin(10)

    time = [i for i in range(200)]
    values = [noise.valueAt(i) for i in time]

    multiplied_list = [(element * 100) + 450 for element in values]

    plt.title("Perlin Noise")
    plt.xlabel("Time")
    plt.ylabel("Value")
    plt.plot(time, multiplied_list)
    plt.show()
예제 #8
0
def getBasicShape(size, neighbors, vertices, regions, seed=None):
    if seed is None:
        seed = datetime.now().microsecond

    print("Calculating landmass shape...")

    print("Landmass shape seed: %d" % seed)
    np.random.seed(seed)

    noise = perlin.Perlin(size, 8)

    cell_type = []

    def isLand(c):
        v = [int(t) for t in c]

        x = 2. * c[0] / size - 1
        y = 2. * c[1] / size - 1

        return noise[v[0], v[1]] > 0.316 * (1 + x**2 + y**2)

    for r in regions:
        land = 0
        thresh = 0.7 * len(r)
        for v in vertices[r]:
            if np.any([v == 0, v == size]):
                land = 0
                break
            if dist(v, (1756, 666)) < 25:
                land = 0
                break
            land += 1 if isLand(v) else 0
        cell_type.append(LAND if land > thresh else WATER)

    corner = np.where(np.all(vertices == [0,0], axis=1))[0][0]

    flood = [corner]

    cur_index = 0

    while cur_index < len(flood):
        current = flood[cur_index]
        cell_type[current] = OCEAN
        cur_index += 1

        for n in neighbors[current]:
            if cell_type[n] == WATER and n not in flood:
                flood.append(n)

    return cell_type
예제 #9
0
def map_create():
    newMap = [[strucTile(0) for y in range(0, mapY)] for x in range(0, mapX)]
    noise = perlin.Perlin(6)
    time = [i for i in range(80)]
    values = [noise.valueAt(i) for i in time]
    values = [values[i] * 12 for i in time]
    values = [abs(round(values[i])) for i in time]
    for y in range(0, mapY):
        for x in range(0, mapX):
            if y < 12:
                newMap[x][values[x] + 13 + y].blockType = 3
            if newMap[x][y].blockType == 3 and newMap[x][y - 1].blockType == 0:
                newMap[x][y].blockType = 5
            if newMap[x][y].blockType == 3 and newMap[x][y + 1].blockType == 0:
                newMap[x][y].blockType = 4
            if newMap[x][y].blockType == 4 and y < mapY - 1:
                newMap[x][y + 1].blockType = 4
    return newMap
예제 #10
0
파일: sun.py 프로젝트: vojtatom/planets
def apply_noise(image, setup):
    generator = perlin.Perlin()
    octaves = 5
    persistence = 5
    coef = 30
    width, height = setup['canvas'][0], setup['canvas'][1]

    list_of_pixels = list(image.getdata())
    for i, pixel in enumerate(list_of_pixels):
        if pixel != (0, 0, 0, 0):
            noise = generator.OctavePerlin((i % width) / coef,
                                           i / (height * coef), 0, 1, 5)
            new_pixel = [int(x * (1 + noise)) for x in pixel[:3]]
            new_pixel.append(pixel[3])
            list_of_pixels[i] = tuple(new_pixel)

    image = Image.new(image.mode, image.size)
    image.putdata(list_of_pixels)
    return image
예제 #11
0
def gouradPlanet(render, x, y, **kwargs):
    w,v,u = kwargs["bar"]
    nA, nB, nC = kwargs["normales"]
    luz = kwargs["light"]
    normx = nA.x*w + nB.x*v + nC.x*u 
    normy = nA.y*w + nB.y*v + nC.y*u 
    normz = nA.z*w + nB.z*v + nC.z*u 
    vnormal = Vector3(normx, normy, normz)
    intensity = prodPunto(vnormal, luz)
    if intensity < 0:
        intensity =0
    elif intensity >1:
        intensity =1
    
    #lista de colores a utilizar, con su valor rgb. 
    dark_wood =(80,64,51)
    light_wood = (147,129,107)
    greywood = (105,95,85)
    grey =(136,127,118)
    light_grey = (143,144,139)
    near_white = (183,183,181)


    #aqui se crea el ruido (mediante perlin noise) para la generación de colores 
    pnoise = p.Perlin()
    for m in range(800):
        for n in range(800):
            col = [int((pnoise.value(x/800.0, y/11.0, 0)+1) *200), ] *3

            if col[1] > 220:
                mul = [int((near_white[0]/255.0*col[0])* intensity),int((near_white[1]/255.0*col[1])* intensity),
                int((near_white[2]/255.0*col[2])* intensity)]
                if mul[0] < 0: mul[0] =0
                if mul[1] < 0: mul[1] = 0
                if mul[2] < 0: mul[2] = 0
                return color(mul[0], mul[1], mul[2])

            if col[1] >210: 
                mul = [int((light_grey[0]/255.0*col[0])* intensity),int((light_grey[1]/255.0*col[1])* intensity),
                    int((light_grey[2]/255.0*col[2])* intensity)]
                if mul[0] < 0: mul[0] =0
                if mul[1] < 0: mul[1] = 0
                if mul[2] < 0: mul[2] = 0
                return color(mul[0], mul[1], mul[2])

            if col[1] >205: 
                mul = [int((greywood[0]/255.0*col[0])* intensity),int((greywood[1]/255.0*col[1])* intensity),
                    int((greywood[2]/255.0*col[2])* intensity)]
                if mul[0] < 0: mul[0] =0
                if mul[1] < 0: mul[1] = 0
                if mul[2] < 0: mul[2] = 0
                return color(mul[0], mul[1], mul[2])
            
            if col[1] >170: 
                mul = [int((light_wood[0]/255.0*col[0])* intensity),int((light_wood[1]/255.0*col[1])* intensity),
                    int((light_wood[2]/255.0*col[2])* intensity)]
                if mul[0] < 0: mul[0] =0
                if mul[1] < 0: mul[1] = 0
                if mul[2] < 0: mul[2] = 0
                return color(mul[0], mul[1], mul[2])

            if col[1] >150:
                mul = [int((dark_wood[0]/255.0*col[0])* intensity),int((dark_wood[1]/255.0*col[1])* intensity),
                    int((dark_wood[2]/255.0*col[2])* intensity)]
                if mul[0] < 0: mul[0] =0
                if mul[1] < 0: mul[1] = 0
                if mul[2] < 0: mul[2] = 0
                return color(mul[0], mul[1], mul[2])

            else:
                mul = [int((grey[0]/255.0*col[0])* intensity),int((grey[1]/255.0*col[1])* intensity),
                    int((grey[2]/255.0*col[2])* intensity)]
                if mul[0] < 0: mul[0] =0
                if mul[1] < 0: mul[1] = 0
                if mul[2] < 0: mul[2] = 0
                return color(mul[0], mul[1], mul[2])
예제 #12
0
from PIL import Image
import perlin

perlin_generator = perlin.Perlin(frequency=50)
noise_image = Image.new("RGB", (500, 500))

for x in xrange(500):
    for y in xrange(500):
        colour = (int((perlin_generator.value(x / 500.0, y / 500.0, 0.0) + 1) *
                      128), ) * 3
        noise_image.putpixel((x, y), colour)

out = open("perlin.png", "w")
noise_image.save(out)
out.close()
예제 #13
0
    pip install perlin
Restart kernel

"""
import turtle
import perlin, random, math

panel = turtle.Screen()
w = 600
h = 600
panel.setup(width=w, height=h)

# perlin generates noise based on a seed (start point)
# we'll use a random  value so that each iteration of a path is different!

y = perlin.Perlin(random.randint(0, 6000))
x = perlin.Perlin(random.randint(0, 6000))
perl = turtle.Turtle()


# 1D path
def perlinTrace(steps=10000):

    for i in range(steps):
        perl.goto(i, x.one(i))


# 2D path
def perlin2D(steps=10000):
    for i in range(steps):
        perl.goto(x.one(i), y.one(i))
예제 #14
0
파일: gui.py 프로젝트: MarioV03/Math
    img = PhotoImage(width=W, height=H)
    can.create_image((W / 2, H / 2), image=img, state="normal")

    for x in range(W):
        for y in range(H):
            img.put(value_color(get_noise_value(x / 32, y / 32)),
                    (x + 1, y + 1))

    window.mainloop()


def clip(value, limit):
    return min(value, limit) / limit


def get_noise_value(x, y):
    v1 = noise.get_value(x / 2, 1.5 + y / 30)
    v2 = noise.get_value(0.5 + x / 30, y)
    v = v1 * v2
    if (v < 0.5):
        v = 0
    else:
        v = (v - 0.5) * 2
    v = int(v * 0xff)
    return v


noise = perlin.Perlin(int(input("Seed: ")))
#print(noise.get_value(4.5, 4.5))
show(noise)
# There will be three star colors: red, yellow, and blue.
star_colors = {
    0: (255,0,0), # Red
    1: (213,213,0), # Yellow
    2: (0,0,255) # Blue
}

# Stars come in three sizes: dwarf, normal, and giant.
star_sizes = {
    0: 5,
    1: 10,
    2: 25
}

# We have three noise generators: first for finding the star size, one for finding the star color, one for finding planet colors
color_noise = perlin.Perlin()
size_noise = perlin.Perlin()
planet_noise = perlin.Perlin()

# Ask the user what seed to use for the simulation.
seed = float(input('Enter the numerical seed: '))   

pygame.display.flip()
# Game loop
running = True
while running:
    # Clear the screen
    screen.fill((0,0,0))
    
    # Show the galaxy screen
    if view_mode is 'galaxy':
예제 #16
0
 def _reloadGen(self):
     '''Recreate the noise generator with the current parameters.'''
     self._gen = perlin.Perlin(self.octaves, self.persistence)
pygame.init()
screen = pygame.display.set_mode((500, 500))
pygame.display.set_caption('Biome Generation')

# We will see 50x50 blocks at any given time.
grid = [[0] * 50] * 50

# There will be three biomes in the terrain: desert, grass, and snowy. Each one is represented by its own color.
biome_colors = {
    0: (255, 255, 0),  # Yellow
    1: (38, 108, 46),  # Forest green
    2: (255, 255, 255)  # White
}

# Import an instance of our Perlin noise generator.
noise = perlin.Perlin()

# Ask the user what seed to use for the simulation.
seed = float(input('Enter the numerical seed: '))

screen.fill((255, 255, 255))
pygame.display.flip()
# Game loop
running = True
while running:
    # Iterate through the biome list and determine the biome.
    for x in range(left, 50 + left):
        for y in range(top, 50 + top):
            ans = noise.getNoise(x / 2, y / 2, seed)
            if ans < .25:  # Deserts should be relatively uncommon
                color = biome_colors[0]