Exemple #1
0
def makeImage(height, width, imageName):
    k = 4
    numSamples = 100000000

    imageWidth = min(width, height)
    imageHeight = max(width, height)

    data = [0] * imageHeight * imageWidth

    cx = imageWidth / 2
    cy = imageHeight / 2
    radius = imageWidth / 2 * .85

    for i in range(numSamples):
        theta = uniform(0, 2 * pi)

        pA_x, pA_y = rose(theta, radius, 4, cx, cy)
        pB_x, pB_y = rose(k * theta, radius, 4, cx, cy)

        # pick a random point on the line segment [pA, pB]
        r = uniform(0, 1)
        pC_x = (1 - r) * pA_x + r * pB_x
        pC_y = (1 - r) * pA_y + r * pB_y

        i = int(pC_x + .5)
        j = int(pC_y + .5)

        data[j * imageWidth + i] += 1

    saveImage(data, imageName, imageWidth, imageHeight, fg=[128, 0, 64])
Exemple #2
0
def makeImage(height, width, imageName):
    imageWidth = min(width, height)
    imageHeight = max(width, height)

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, imageWidth, imageHeight)
    ctx = cairo.Context(surface)
    ctx.set_tolerance(.1)
    ctx.set_antialias(False)

    cx = imageWidth / 2
    cy = imageHeight / 2
    radius = imageWidth / 2 * .95

    # background
    ctx.set_source_rgb(1, 1, 1)
    ctx.rectangle(0, 0, imageWidth, imageHeight)
    ctx.fill()
    ctx.stroke()

    # lines
    ctx.set_line_width(STROKE)
    ctx.set_source_rgb(0, 0, 0)

    N = 360
    for d in range(8 * N):
        theta = d * 2 * pi / N

        x, y = rose(theta, radius, 2 / 5, cx, cy)

        if d == 0:
            ctx.move_to(x, y)
        else:
            ctx.line_to(x, y)
    ctx.stroke()
    surface.write_to_png(imageName)
def makeImage(height, width, imageName):
    kA = 4
    kB = 3
    numSamples = 100000000

    imageWidth = width
    imageHeight = height

    data = [0] * imageHeight * imageWidth

    cx = imageWidth / 2
    cy = imageHeight / 2
    radius = imageWidth / 2 * .95

    radius2 = radius * .9

    for i in range(numSamples):
        theta = uniform(0, 32 * pi)

        pA_x, pA_y = rose(kA * theta, radius, 4 / 5, cx, cy)
        pB_x, pB_y = rose(kB * theta, radius2, 2 / 5, cx, cy)

        # pick a random point on the line segment [pA, pB]
        r = uniform(0, 1)
        pC_x = (1 - r) * pA_x + r * pB_x
        pC_y = (1 - r) * pA_y + r * pB_y

        i = int(pC_x + .5)
        j = int(pC_y + .5)

        data[j * imageWidth + i] += 1

    saveImage(data,
              imageName,
              imageWidth,
              imageHeight,
              bg=[255, 255, 255],
              fg=[96, 43, 25],
              alphaMultiplier=5)
def makeImage(height, width, imageName):
    k = 4
    numSamples = 100000000

    imageWidth = min(width, height)
    imageHeight = max(width, height)

    data = [0] * imageHeight * imageWidth

    cx = imageWidth / 2
    cy = imageHeight / 2
    radius = imageWidth / 2 * .95

    for i in range(numSamples):
        # need to increase range for complete curve
        theta = uniform(0, 10 * pi)

        pA_x, pA_y = rose(theta, radius, .4, cx, cy)
        pB_x, pB_y = rose(k * theta, radius, .4, cx, cy)

        # pick a random point on the line segment [pA, pB]
        r = uniform(0, 1)
        pC_x = (1 - r) * pA_x + r * pB_x
        pC_y = (1 - r) * pA_y + r * pB_y

        i = int(pC_x + .5)
        j = int(pC_y + .5)

        data[j * imageWidth + i] += 1

    saveImage(data,
              imageName,
              imageWidth,
              imageHeight,
              bg=[255, 255, 255],
              fg=[0, 128, 64],
              alphaMultiplier=20)
def makeImage(height, width, imageName):
    kA = 1
    kB = 2
    numSamples = 100000000

    imageWidth = min(width, height)
    imageHeight = max(width, height)

    data = [0] * imageHeight * imageWidth

    cx = imageWidth / 2
    cy = imageHeight / 2
    radius = imageWidth / 2 * .85

    for i in range(numSamples):
        # Note: using 10 * pi.  If only 2 * pi, whole image is not drawn
        theta = uniform(0, 10 * pi)

        pA_x, pA_y = rose(kA * theta, radius * .9, 1.2, cx, cy)
        pB_x, pB_y = circle(kB * theta, radius, cx, cy)

        # pick a random point on the line segment [pA, pB]
        r = uniform(0, 1)
        pC_x = (1 - r) * pA_x + r * pB_x
        pC_y = (1 - r) * pA_y + r * pB_y

        i = int(pC_x + .5)
        j = int(pC_y + .5)

        data[j * imageWidth + i] += 1

    saveImage(data,
              imageName,
              imageWidth,
              imageHeight,
              fg=[0, 128, 128],
              alphaMultiplier=6)