def makeImage(height, width, imageName): k = 1.5 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 = circle(theta, radius, cx, cy) pB_x, pB_y = circle(k * 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=[255, 0, 0])
def computeData(processId, imageWidth, imageHeight, numSamples, kA, kB): data = initializeData(imageWidth, imageHeight) cx = imageWidth / 2 cy = imageHeight / 2 radius = imageWidth / 2 * .85 for i in range(numSamples): theta = uniform(0, 2 * pi) pA_x, pA_y = circle(kA * theta, radius, 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 print("Finished process {}".format(processId)) return data
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) # circle N = 360 for d in range(N + 1): theta = d * 2 * pi / N x, y = circle(theta, radius, cx, cy) if d == 0: ctx.move_to(x, y) else: ctx.line_to(x, y) ctx.stroke() numSquares = 8 squareRadius = radius / 2 * .9 for s in range(numSquares): N = 4 rotAng = s * pi / 4 cx_s = cos(pi / 4 * s) * radius / 2 + cx cy_s = sin(pi / 4 * s) * radius / 2 + cy for d in range(N + 2): theta = d * 2 * pi / N x, y = square(theta, squareRadius, cx_s, cy_s, rotAng) 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 = 9 kB = 17 numSamples = 100000000 imageWidth = width imageHeight = height data = [0] * imageHeight * imageWidth cxA = imageWidth / 4 cyA = imageHeight / 4 cxB = 3 * imageWidth / 4 cyB = 3 * imageHeight / 4 radius = imageWidth / 4.5 for i in range(numSamples): theta = uniform(0, 2 * pi) pA_x, pA_y = circle(kA * theta, radius, cxA, cyA) pB_x, pB_y = circle(kB * theta, radius, cxB, cyB) # 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, 64, 0], alphaMultiplier=5)
def makeImage(height, width, imageName): kA = 9 kB = 17 numSamples = 100000000 imageWidth = width imageHeight = height data = [0] * imageHeight * imageWidth cx = imageWidth / 2 cy = imageHeight / 2 radius = imageWidth / 2 * .95 offsetCx = cx + radius / 3 offsetRadius = radius / 1.5 for i in range(numSamples): theta = uniform(0, 2 * pi) pA_x, pA_y = circle(kA * theta, radius, cx, cy) pB_x, pB_y = circle(kB * theta, offsetRadius, offsetCx, 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=[128, 0, 0], alphaMultiplier=10)
def makeImage(height, width, imageName): kA = 7.9 kB = 11 numSamples = 100000 imageWidth = min(width, height) imageHeight = max(width, height) for numSamples in (100000, 100000000): data = [0] * imageHeight * imageWidth cx = imageWidth / 2 cy = imageHeight / 2 radius = imageWidth / 2 * .95 for i in range(numSamples): theta = uniform(0, 2 * pi) pA_x, pA_y = circle(kA * theta, radius, 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 imageNameCnt = re.sub(r"image", f"image_{numSamples}", imageName) saveImage(data, imageNameCnt, imageWidth, imageHeight, bg=[255, 255, 255], fg=[0, 0, 0])
def makeImage(height, width, imageName): kA = 101 kB = 2 numSamples = 1000000000 imageWidth = width imageHeight = height data = [0] * imageHeight * imageWidth cx = imageWidth / 2 cy = imageHeight / 2 radius = imageWidth / 2 circRadius = radius * .9 hypoRadius = radius * .0275 for i in range(numSamples): theta = uniform(0, 2 * pi) pA_x, pA_y = circle(kA * theta, circRadius, cx, cy) pB_x, pB_y = hypotrochoid(kB * theta, hypoRadius, hypoRadius, 1 / 17 * hypoRadius, 1.1 * hypoRadius, 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, 0, 159], [228, 171, 0]], alphaMultiplier=4)
def makeImage(height, width, imageName): kA = 5 kB = -3 numSamples = 100000000 imageWidth = width imageHeight = height data = [0] * imageHeight * imageWidth cx = imageWidth/2 cy = imageHeight/2 radius = imageWidth/2 * .95 numSquares = 8 squareRadius = radius/2 for s in range(numSquares): rotAng = s * pi/4 cx_s = cos(pi/4 * s) * radius/2 + cx cy_s = sin(pi/4 * s) * radius/2 + cy for i in range(numSamples): theta = uniform(0, 2 * pi) pA_x, pA_y = circle(kA * theta, radius, cx, cy) pB_x, pB_y = square(kB * theta, squareRadius, cx, cy, rotAng) # 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, 110, 137], alphaMultiplier=4)
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)
def draw(): helper.circle()