In [16]:
import PIL
from PIL import Image
import random
import os
import sys
import pandas as pd
import numpy as np
import scipy
import matplotlib.pyplot as plt
from __future__ import print_function
%matplotlib inline
In [8]:
#set scale to scale the resulting images in save_image(i) function
scale = 1
#set the length and width of the square image canvas
width = int(200)
length = int(200)
#number of steps that the ant will take on each walk
iterations = 100000
#for naming the image file below
number = str(iterations)
#Ininitialize a blank square image
im1 = Image.new('RGBA', (width,length),'red')
#color selection
white = (255,255,255,255)
red = (255,0,0,255)
color_choices = [white, red]
In [10]:
#captures series of pixels used for generating images
def get_pix_series():
global pix_series
pix_series = []
for x in range(len(pix_list)):
for y in range(len(pixel_colors)):
if pix_list[x][2] == y:
pixel = pixel_colors[y]
pix_series.append(pixel)
In [11]:
def save_image(i):
#give access to the image instantiated at the beginning of the script
global im1
#fill blank image canvas with pix_series pixel data
im1.putdata(pix_series)
#to rescale the image, set the scale variable in settings and call resize on im1
im1.resize((scale*im1.size[0],scale*im1.size[1])).save('%s.png' % (moves))
In [18]:
np.random()
Out[18]:
In [12]:
im1.show()