コード例 #1
0
ファイル: main.py プロジェクト: mattbat131/PianoSongGenerator
 def __init__(self, beats):
     self.beat = list()
     for i in range(64):
         # generate beat
         play_sound = pnoise1(0, 1)
         amplitude = pnoise1(1, 100)
         duration = random.uniform(0.01, 1)
         self.beat.append((play_sound, amplitude, duration))
コード例 #2
0
ファイル: follow.py プロジェクト: PeteRichardson/follow
 def move(self):
     ''' move according to Perlin noise'''
     self.currentx += 1
     self.currenty += 1
     n = pnoise1(self.currentx * self.delta, 1) 
     m = pnoise1(self.currenty * self.delta, 1) 
     self.x = int(n/2 * self.maxx + self.maxx/2)
     self.y = int(m/2 * self.maxy + self.maxy/2)
コード例 #3
0
ファイル: pygame_demo2.py プロジェクト: gunny26/pygame
 def draw(self):
     if self.vel < 0 :
         self.beans.remove(self)
     self.x_off += 0.0007
     self.y_off += 0.0007
     self.vel += self.accel
     self.x += abs(noise.pnoise1(self.x_off) * self.vel) - self.vel / 2
     self.y += abs(noise.pnoise1(self.y_off) * self.vel) - self.vel / 2
     self.surface.set_at((int(self.x), int(self.y)), self.get_color())
コード例 #4
0
ファイル: PerlinTest.py プロジェクト: TkkrLab/py-ledart
 def generate(self):
     # self.fill(BLACK)
     x = noise.pnoise1(self.t) + 1
     y = noise.pnoise1(self.t + self.y_offset) + 1
     x = translate(x, 0, 2., 10, self.width - 10)
     y = translate(y, 0, 2., 10, self.height - 10)
     # self.draw_circle(x, y, 10, GREEN)
     color = [int(0xff * c) for c in colorsys.hsv_to_rgb(self.t, 1, 1)]
     self.draw_pixel(x, y, color)
     self.t += 0.001
コード例 #5
0
 def addNoise(self, pasadas, potencia):
     for j in  range( len(self.points) ):
       self.points[j].dx = self.points[j].ix
       self.points[j].dy = self.points[j].iy
       for i in range( pasadas ):
         rx = pnoise1(random.random() + self.points[j].ix) * potencia
         ry = pnoise1(random.random() + self.points[j].iy) * potencia
         # print(str(rx))
         self.points[j].dx = self.points[j].dx + rx
         self.points[j].dy = self.points[j].dy + ry
コード例 #6
0
ファイル: river.py プロジェクト: eykd/orphan
 def draw(self, row, col, noise_base, fill):
     mod_up = int(round(5 * pnoise1(col * 0.01, base=noise_base)))
     mod_down = int(round(5 * pnoise1(col * 0.01, base=-noise_base)))
     width_2 = 20
     top_row = row - (width_2 + mod_up)
     bot_row = row + (width_2 + mod_down)
     try:
         self.block[top_row : bot_row + 1, col : col + 1] = fill
     except IndexError:
         logger.exception('Bad terrain index (shape %s): %s : %s, %s : %s', self.block.terrain.shape, top_row, bot_row, col, col)
         raise
コード例 #7
0
ファイル: perlin-score.py プロジェクト: hecanjog/buchla-score
def make_vary(index, length, freq):
    def i(index, offset):
        return ((index + offset) % nump) / float(nump) 

    pulsewidth = int(pnoise1(i(index, 100), 2) * (length / 2))
    
    snd = dsp.tone(pulsewidth, freq, amp=pnoise1(i(index, 99), 3) * 0.5)
    snd = dsp.env(snd, 'sine')

    snd = dsp.pad(snd, 0, length - pulsewidth)

    return snd
コード例 #8
0
ファイル: CoffeeBean.py プロジェクト: Plan-V/python-demoscene
 def draw(self):
     """draw line"""
     if self.vel < 0 :
         # remove self
         self.beans.remove(self)
     # original 0.0007
     self.x_off += 0.0007
     self.y_off += 0.0007
     self.vel += self.accel
     self.x += noise.pnoise1(self.x_off, octaves=8) * self.vel - self.vel / 2
     self.y += noise.pnoise1(self.y_off, octaves=8) * self.vel - self.vel / 2
     # set color
     h = abs(noise.pnoise1((self.x_off + self.y_off) / 2)) * 360
     self.color.hsva = (h, 100, 100, 4)
     pygame.gfxdraw.pixel(self.surface, int(self.x) % self.width, int(self.y) % self.height, self.color)
コード例 #9
0
def addNoise():
    global points, gp
    # Add noise
    counter = -1

    # Noise params
    base = random.randint( 0, 100)
    octaves = random.randint( 9, 12 )
    persistence = random.uniform( 1.2, 5.8 )
    lacunarity = random.uniform( 2.1, 2.9 )

    print('b:'+str(base)+' o:'+str(octaves)+' p:'+str(persistence)+' l:'+str(lacunarity) )

    gp['params']['b'] = base
    gp['params']['o'] = octaves
    gp['params']['p'] = persistence
    gp['params']['l'] = lacunarity

    for line in points:
        for j in range(len(line)):
            counter += 1
            pn1 = pnoise1(
                counter / segments_total * 0.25,
                octaves,     # octaves 9 - 12
                persistence, # persistence 1.2 - 6.2
                lacunarity,  # lacunarity 2.1 - 3.15
                64,          # repeat 1024
                base         # base 0.0
            )
            line_inc[j][1] += pn1 * 8
            line[j][1] += line_inc[j][1]

            line_inc[j][0] += pn1 * 3
            line[j][0] += line_inc[j][0]
コード例 #10
0
ファイル: pygame_demo2.py プロジェクト: gunny26/pygame
 def update(self):
     self.framecount += 1
     x_off = self.framecount * 0.0003
     y_off = x_off + 20
     x = noise.pnoise1(x_off) * self.surface.get_width()
     y = noise.pnoise1(y_off) * self.surface.get_height()
     # every 8th frame a new bean
     print len(self.beans)
     if self.framecount % 8 == 0:
         self.beans.append(Bean(self.surface, self.beans, { 
             "x" : x, 
             "y" : y, 
             "x_off" : x_off, 
             "y_off" : y_off}))
     for bean in self.beans:
         bean.draw()
コード例 #11
0
ファイル: test.py プロジェクト: Connor124/Gran-Theft-Crop-Toe
 def test_perlin_1d_octaves_range(self):
     from noise import pnoise1
     for i in range(-1000, 1000):
         for o in range(10):
             x = i * 0.49
             n = pnoise1(x, octaves=o + 1)
             self.assertTrue(-1.0 <= n <= 1.0, (x, n))
コード例 #12
0
ファイル: stationary_noise.py プロジェクト: DiNAi/hueperlin
 def value(self,t):
     p = noise.pnoise1(t*self.frequency,
                       octaves=self.octaves,
                       lacunarity=self.lacunarity,
                       persistence = self.persistence,
                       repeat = self.repeat,
                       base=self.base)
     return self.mean + self.amplitude*p
コード例 #13
0
ファイル: perlin_experiments.py プロジェクト: DiNAi/hueperlin
def p(x):
    return noise.pnoise1(x+base,
                         octaves=octaves,
                         lacunarity=lacunarity,
                         base=0,
                         repeat=repeat,
                         persistence=persistence
                        )
コード例 #14
0
ファイル: noisetest.py プロジェクト: joshleejosh/melodomatic
def test_noise(base, step, viz=False):
    global pdist, qdist
    for i in range(ITERATIONSIZE):
        p = noise.pnoise1(base + step * i)
        q = generators._noise1(base + step * i)
        if viz:
            print '%+0.4f | %s | %s | %+0.4f'%(p, _fmt(p), _fmt(q), q)
        pdist[_rmap(p, -1.0, 1.0, DISTRIBUTION_BUCKETS)] += 1
        qdist[_rmap(q, -1.0, 1.0, DISTRIBUTION_BUCKETS)] += 1
コード例 #15
0
ファイル: 1dnoise_example.py プロジェクト: Exodus111/Projects
def on_draw():
    global min,max
    window.clear()
    glLoadIdentity()
    glTranslatef(0, 0, -1)
    r = range(256)
    glBegin(GL_LINE_STRIP)
    for i in r:
        x = float(i) * span / points - 0.5 * span
        y = pnoise1(x + base, octaves)
        glVertex3f(x * 2.0 / span, y, 0)
    glEnd()
コード例 #16
0
def noise_color(illuminators, color, step, amplitude):
    base_color = Color(color.r, color.g, color.b)
    temp_color = colorsys.rgb_to_hls(remap(base_color.r, 0, 255, 0, 1), remap(base_color.g, 0, 255, 0, 1), remap(base_color.b, 0, 255, 0, 1))

    while True:
        lightness = min(0.1+temp_color[1]*pnoise1(time.clock()*step)*amplitude*0.1, 1)

        final_color_rgb = colorsys.hls_to_rgb(temp_color[0], lightness, temp_color[2])

        final_color = Color(int(remap(final_color_rgb[0], 0, 1, 0, 255)), int(remap(final_color_rgb[1], 0, 1, 0, 255)), int(remap(final_color_rgb[2], 0, 1, 0, 255)))

        for illuminator in illuminators:
            illuminator.set(final_color)

        time.sleep(0.001)
コード例 #17
0
    def render(self, ctx):
        self.current_x = cx
        self.current_y = cy
        self.prev_x = cx
        self.prev_y = cy
        self.angle = 0 # random.random() * math.pi*2

        for i in range(self.segments):

            pn1 = pnoise1 (
                self.noise_seed + ( (i / self.segments) * self.noise_speed ),
                2,
                0.2,  # persintence 0.2
                4.0,  # Lacunarity 2.0
                1024,   # repeat 1024
                self.noise_base
            )
            # print(str(pn1))

            _cos = math.cos(self.angle)
            _sin = math.sin(self.angle)
            self.current_x = self.current_x + self.dis * _cos
            self.current_y = self.current_y + self.dis * _sin

            self.angle += pn1 / 60.0

            self.segment_w_current = self.segment_w * pn1 * 2

            col.a = ( 0.5 + ( pn1 * 0.5 ) ) * self.alpha_correction
            col.rotateHue( pn1 / self.rotate_hue )
            # col.setSat( 0.0 )
            ctx.set_source_rgba( *col.rgba)
            # draw.plot( ctx, self.current_x, self.current_y, 1)

            ABx =  self.current_x - self.prev_x
            ABy =  self.current_y - self.prev_y
            NABx = ABx / self.dis
            NABy = ABy / self.dis
            PNABx = -NABy
            PNABy =  NABx
            Dx1 = self.current_x + self.segment_w_current * PNABx
            Dy1 = self.current_y + self.segment_w_current * PNABy
            Dx2 = self.current_x - self.segment_w_current * PNABx
            Dy2 = self.current_y - self.segment_w_current * PNABy
            draw.line( ctx, Dx1, Dy1, Dx2, Dy2)

            self.prev_x = self.current_x
            self.prev_y = self.current_y
コード例 #18
0
ファイル: mapgen.py プロジェクト: Art9681/TerrainApp
    def horizon(self):
        print "Parsing map_template for horizon gen"
        '''This method divides ground and sky. It opens and parses the xml
        file generated previously.'''

        ###Begin column height noise, generates hills and valleys at horizon###
        self.hpoints = 256
        self.hspan = 15.0
        self.hoctaves = 8 #Determines variation in peaks and valleys. Lower numbers produce better results.
        self.hbase = 0 #Not sure what this does but it still changes stuff.

        for i in xrange(self.columns):
            x = float(i) * self.hspan / self.hpoints - 0.5 * self.hspan
            y = pnoise1(x + self.hbase, self.hoctaves)
            self.column_height_offset.append(y*3)
        ###End column height noise###

        #Open and parse the xml file to change cells according to noise#
        tree = ET.parse("map_template.xml")
        root = tree.getroot()

        print "Finished root parsing"

        #The counters that iterate for every column and cell.
        self.col_counter = 0
        self.cell_counter = 0

        for column in root.iter('column'):
            self.col_height = self.col_height + self.column_height_offset[self.col_counter]
            self.column_height_values.append(self.col_height-1)
            self.col_counter += 1
            self.cell_counter = 0

            for cell in column:
                self.cell_counter += 1
                if self.cell_counter > self.col_height:
                    cell.set('tile', 'air')

        tree.write("terrain.xml")
        root.clear()
        self.ground_layers()
コード例 #19
0
ファイル: noiseTest.py プロジェクト: pleekMan/petroLumen
def on_draw():
    global x

    window.clear()
    #glLoadIdentity()

    scale = pnoise1(time,octaves=1) # pnoise1(time,octaves)  range: -1 -> 1
    scale = (scale + 1) * 0.5 # range: 0 -> 1
    #print scale
    scale *= window.height
    y = scale;
    size = 2

    # DRAW LITTLE SQUARE
    glColor4f(1,0,0,1.0)
    glBegin(GL_QUADS)

    glVertex2f(x,y)
    glVertex2f(x + size,y)
    glVertex2f(x + size, y + size)
    glVertex2f(x,y + size)

    glEnd()

    # DRAW BLACK RECTANGLE TO CLEAR THE WAY
    glColor4f(0,0,0,1.0)
    glBegin(GL_QUADS)

    glVertex2f(x+size,0)
    glVertex2f(x + 30,0)
    glVertex2f(x + 30,window.height)
    glVertex2f(x+size,window.height)

    glEnd()

    #glColor4f(1,1,1,1.0)
    #pyglet.text.Label(str(scale),x=100,y=100)

    x+= 1
    if x>window.width:
        x = 0
コード例 #20
0
ファイル: test.py プロジェクト: Connor124/Gran-Theft-Crop-Toe
 def test_perlin_1d_base(self):
     from noise import pnoise1
     self.assertEqual(pnoise1(0.5), pnoise1(0.5, base=0))
     self.assertNotEqual(pnoise1(0.5), pnoise1(0.5, base=5))
     self.assertNotEqual(pnoise1(0.5, base=5), pnoise1(0.5, base=1))
コード例 #21
0
ファイル: test.py プロジェクト: Connor124/Gran-Theft-Crop-Toe
 def test_perlin_1d_range(self):
     from noise import pnoise1
     for i in range(-10000, 10000):
         x = i * 0.49
         n = pnoise1(x)
         self.assertTrue(-1.0 <= n <= 1.0, (x, n))
コード例 #22
0
def render():

    req = requests.get(url=CONFIG['palett_esAPI']['url'])
    palette = req.json()
    print(palette)
    print(('http://palett.es/' + '-'.join(palette)).replace('#', ''))
    # palette = ['#2b2c27', '#ff5279', '#fdaad0', '#e4def8', '#f8faff']

    w = 600
    h = 600
    cx = w / 2
    cy = h / 2
    r = w / 2 - 40
    num_stains = 6
    points = []

    ims = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h) # Simple Surface
    ctx = cairo.Context(ims)

    # Clear
    ctx.rectangle(0, 0, w, h) # Rectangle(x0, y0, x1, y1)
    ctx.set_source_rgb(0.1, 0.1, 0.1)
    ctx.fill ()

    for j in range(num_stains):

        ctx.set_line_width(random.random() + 0.5)

        r = w / 2 - random.randint(0, w / 4)

        c1 = Colz()
        c1.setHex(random.choice(palette))
        c2 = Colz()
        c2.setHex(random.choice(palette))

        cx, cy = random.randint(0, w), random.randint(0, h)

        ctx.set_operator(cairo.OPERATOR_SOURCE)
        effect = random.randint(1, 10)
        global_alpha = 1.0
        if effect == 1:
            ctx.set_operator(cairo.OPERATOR_OVERLAY)
            points.append([cx, cy])
        if effect == 2:
            global_alpha = 0.5
            ctx.set_operator(cairo.OPERATOR_ADD)
            points.append([cx, cy])

        ctx.save()
        ctx.translate(cx, cy)
        ctx.rotate(random.random() * math.pi * 2)
        ctx.translate(-cx, -cy)
        ctx.restore()

        num_lines = 512
        noise_offset = random.randint(0, num_lines)

        for i in range(num_lines):
            percent = i / num_lines

            pn1 = pnoise1(
                percent,
                2,    # octaves
                1.1,  # persistence, amplitude of each succesive octave
                8.0,  # lacunarity, frecuency
                1,    # repeat
                noise_offset # initial offset
            )
            # print(str(pn1))

            cmix = Colz.interpolate(c1, c2, percent)
            if percent < 0.5:
                cmix = Colz.interpolate(c1, c2, percent * 2)
            else:
                cmix = Colz.interpolate(c2, c1, (percent - 0.5) * 2)

            ctx.set_source_rgba(*cmix.rgb, global_alpha)

            temp_r = r + (pn1 * random.randint(1, 250))

            a = math.pi * 2
            dx = cx + temp_r * math.cos(a * percent)
            dy = cy + temp_r * math.sin(a * percent)
            draw.line(ctx, cx, cy, dx, dy)

    gp = collections.OrderedDict()
    gp['name'] = 'flowight'
    gp['params'] = collections.OrderedDict()
    gp['params']['flowers'] = num_stains
    gp['params']['lines'] = num_lines

    footline = name.footline(gp)
    draw.footline(ctx, footline, 8, h - 10)
    filename = name.filename(gp)

    return ims, filename, footline
コード例 #23
0
"""generated 2D terrain"""
import noise


def get_terrain(top_margin, width_margin, (screen_width, screen_height),
                itter_width, distance):
    """gets random terrainNN"""
    pos_wght = 0.01/2.0
    dist_wght = 0.01/2.0
    height_amp = 70.0
    width_margin = int(width_margin)
    gen_terrain = lambda x: (x, top_margin +
                             noise.pnoise1(x*pos_wght+distance*dist_wght)
                             * height_amp)
    terrain = [gen_terrain(x) for x in xrange
               (-width_margin, screen_width+width_margin, itter_width)]
    # round of bottom
    terrain.append((screen_width+width_margin, screen_height))
    terrain.append((-width_margin, screen_height))
    return [terrain]
コード例 #24
0
ファイル: generators.py プロジェクト: wg4568/TerrariaClone
def noise1D(val, seed):
	seed = parse_seed(seed)
	return pnoise1((val/100.) + seed)
コード例 #25
0
ファイル: effecteval.py プロジェクト: drewp/light9
def noise(t):
    return pnoise1(t % 1000.0, 2)
コード例 #26
0
ファイル: 006.py プロジェクト: kellegous/sketching
def main():
	parser = optparse.OptionParser()
	parser.add_option('--seed', default=create_seed(), dest='seed', help='')
	parser.add_option('--fmt', default='pdf', dest='fmt', help='')
	parser.add_option('--nx', default=100, dest='nx', type='int', help='')
	opts, args = parser.parse_args()

	print('seed = %s' % opts.seed)	
	random.seed(opts.seed)

	w, h = 16 * 72, 10 * 72

	surface = lib.create_surface(opts.fmt, os.path.basename(__file__), w, h)
	context = cairo.Context(surface)

	context.rectangle(0, 0, w, h)
	context.set_source_rgb(1, 1, 1)
	context.fill()

	pad = w/16.0
	pa = Pt(pad, pad + (h - 2*pad) * random.random())
	pb = Pt(w - pad, pad + (h - 2*pad) * random.random())

	dx = pb.x - pa.x
	dy = pb.y - pa.y
	n = math.sqrt(dx*dx + dy*dy)
	m = dy / dx

	context.move_to(pa.x, pa.y)
	context.line_to(pb.x, pb.y)
	context.set_source_rgb(*color_of(0xaa, 0xaa, 0xaa))
	context.stroke()

	di = dx / opts.nx
	context.set_line_width(1.0)
	context.set_source_rgb(*color_of(0xee, 0xee, 0xee))
	for i in range(opts.nx + 1):
		context.move_to(pa.x + di*i, pad)
		context.line_to(pa.x + di*i, h - 2*pad)
		context.stroke()

	dj = 0.0
	r = 5

	pts = []
	for i in range(opts.nx + 1):
		x = di*i
		pts.append(Pt(pa.x + x, x*m + pa.y + r*noise.pnoise1(x/10.0, 1)))
		#pts.append(Pt(pa.x + x, x*m + pa.y + dj))
		#dj = max(min(dj + random.random()*r - r/2.0, r), -r)

	context.move_to(pts[0].x, pts[0].y)
	for i in range(1, len(pts)):
		# context.line_to(pts[i].x, pts[i].y)
		a = pts[i - 1]
		b = pts[i]
		context.curve_to(
			a.x + di/2.0, a.y,
			b.x - di/2.0, b.y,
			b.x, b.y)
	context.set_source_rgb(*color_of(0xff, 0x00, 0xff))
	context.stroke()


	lib.commit(surface, os.path.basename(__file__) + '.png')
コード例 #27
0
 def random2D_vector(self):
   v = PVector(noise.pnoise1(PVector.tx), noise.pnoise1(PVector.ty))
   PVector.tx += 0.01
   PVector.ty += 0.01
   v.normalize()
   return v
コード例 #28
0
ファイル: helpers.py プロジェクト: wg4568/Spaaaace
def noise1D(val, seed, sharp=100.):
	seed = parse_seed(seed)
	return pnoise1((val/sharp) + seed)
コード例 #29
0
ファイル: pygame_demo2.py プロジェクト: gunny26/pygame
 def get_color(self):
     h = abs(noise.pnoise1((self.x_off + self.y_off) / 2)) * 360
     color = pygame.Color(0, 255, 0, 100)
     print color
     # color.hsva = (h, 100, 100, 4)
     return(color)
コード例 #30
0
ファイル: dojo.py プロジェクト: jdoig/dojo-3-music
def wave():
    return  [int(pnoise1((i/100.0) * base, 4) * 100) for i in range(0, 128)]