File:Perlin animation 6 octaves.gif

From testwiki
Jump to navigation Jump to search
    Original file (1,024 × 1,024 pixels, file size: 1.61 MB, MIME type: image/gif, looped, 6 frames, 9.0 s)

    This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

    Summary

    Description
    English: Animation of Perlin noise in which 6 octaves of 2-D noise are added together. At each step, noise frequency is doubled and amplitude is halved. The result is fractal noise.
    Date
    Source Own work
    Author Morn
    GIF development
    InfoField
     This GIF graphic was created with Python.
    Source code
    InfoField

    Python code

    Source code
    #!/usr/bin/env python3
    
    from numpy import *
    from PIL import Image, ImageDraw, ImageFont
    import random
    
    random.seed("Perlin")
    fnt = ImageFont.truetype('Courier Prime.ttf', 100)
    
    XDIM, YDIM = 100, 100     # gradient mesh size (must be big enough for highest octave)
    XDP, YDP = 1024, 1024     # Perlin noise array size
    
    phi = zeros((YDIM, XDIM))   # gradient phase angles
    perlin = zeros((YDP, XDP))  # Perlin noise array
    
    # choose random phase angles for gradients
    for y in range(YDIM):
        for x in range(XDIM):
            phi[y,x] = 2 * pi * random.random()
    
    def grad(x0, y0, dx, dy):
        "Compute the dot product between the gradient and position vector"
        gx, gy = cos(phi[y0,x0]), sin(phi[y0,x0])
        return gx * dx + gy * dy
    
    def inter(a, b, w):
        "Interpolate between a and b using weight w"
        return (b - a) * ((w * (w * 6 - 15) + 10) * w * w * w) + a  # smootherstep
    
    # compute Perlin noise in several octaves and add it together
    for nscale, SCALE in enumerate((512, 256, 128, 64, 32, 16)):
        for yi in range(YDP):
            for xi in range(XDP):
                x, y = xi / SCALE, yi / SCALE
                x0, y0 = int(x), int(y)
                dx, dy = x - x0, y - y0
    
                g1 = grad(x0, y0, dx, dy)
                g2 = grad(x0 + 1, y0, -1 + dx, dy)
                g3 = grad(x0, y0 + 1, dx, -1 + dy)
                g4 = grad(x0 + 1, y0 + 1, -1 + dx, -1 + dy)
    
                perlin[yi,xi] += (.5**nscale) * inter(inter(g1, g2, dx), inter(g3, g4, dx), dy)
    
        p2 = (perlin * 128 + 128).astype(uint8)
        im = Image.fromarray(p2, mode = "L")
        d = ImageDraw.Draw(im)
        d.text((0, 0), "%u" % (nscale + 1), font = fnt, fill = 255, align = "left")
        im.save("out%u.png" % nscale)
        print("saved out%u.png" % nscale)
    
    # Create GIF animation with ImageMagick:
    # convert -delay 150 out*.png -loop 0 perlin_animation_6_octaves.gif
    

    Licensing

    I, the copyright holder of this work, hereby publish it under the following license:
    Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
    The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

    Captions

    Add a one-line explanation of what this file represents

    Items portrayed in this file

    depicts

    3 December 2023

    1,689,447 byte

    1,024 pixel

    1,024 pixel

    image/gif

    c4eb3a4f6a85547b60c22685e115bf79997b40ab

    File history

    Click on a date/time to view the file as it appeared at that time.

    Date/TimeThumbnailDimensionsUserComment
    current15:45, 3 December 2023Thumbnail for version as of 15:45, 3 December 20231,024 × 1,024 (1.61 MB)wikimediacommons>MornUploaded own work with UploadWizard

    There are no pages that use this file.