''' Created on Jul 24, 2018 @author: Brett Paufler Copyright Brett Paufler Getting Tired There is a serious mismatch between horizontal and vertical what does this mean Eh, seems to work OK I am tired RAW CODE NEVER PUBLISHED And is messy Used in the 182 (or so) rant 182_test_pattern (maybe) At this remove, it looks to be a one shot deal ''' import numpy as np from random import randint from skimage.io import imsave from itertools import product from skimage.draw import circle from scipy.ndimage.interpolation import rotate W = WIDTH = 1000 #2500 H = HEIGHT = 1000 def sin_linespace( num_curves, #number of waves vertical=True, #if vertical or not circles=True, #Columns or circles ): if vertical: num = HEIGHT else: num = WIDTH if num_curves == 0: return 1 else: s = np.sin( np.linspace( start=0, stop=num_curves*np.pi, num=num, endpoint=True, dtype=np.float64) ) if vertical: s = s.reshape((HEIGHT, 1)) s = np.absolute(s) if circles: #If want cirlces, this should be five s = np.power(s, 5) #columns #if sharp #s = np.power(s, 5) #circles return s def sin_mask(hor=0, ver=0, circles=True, plus=False): ''' hor = number of horizontal columns ver = number of vertical columns circles: if true, shaves more space of edges for circular look False is better for colum effects ''' a = np.ones((HEIGHT, WIDTH), dtype=np.float64) x = sin_linespace(ver, vertical=False, circles=circles) y = sin_linespace(hor, vertical=True, circles=circles) #How the masks are combined #Multi gives smoother circles if plus: a = (a + x + y) / 3.0 else: a = a * x * y return a def sin_mask_test(hor=0, ver=0): circle_plus = product([True, False], repeat=2) for circle, plus in circle_plus: #print circle, plus circle_text = 'circle' if circle else 'column' plus_text = 'plus' if plus else 'multi' save_name = './output/sin_%d_%d_%s_%s.jpg' % ( hor, ver, circle_text, plus_text) img = sin_mask( hor=hor, ver=ver, circles=circle, plus=plus) imsave(save_name, img) def sin_circles_final( background='sin_wave', #TODO size=100, #integer or list of len(n) placement='random', #or 'grid' =equally spaced shape='circle', #TODO n=100 ): if background == 'sin_wave': img = sin_mask( hor=150, ver=0, circles=True, plus=False) elif background == 'checkered': img = np.asarray([[1.0,0]*500, 500*[0,1.0]]*500) elif background == 'checkerboard': a = 10 * [[1.0] * 10 + [0.0] * 10] b = 10 * [[0.0] * 10 + [1.0] * 10] ab = np.vstack((a, b))#img *= 50 img = np.tile(ab, (50,50))#asarray(ab) #img = np.asarray([[1.0,0]*50, 50*[0,1.0]]*50) #img = np.kron(img, (10,10))#img = np.kron(a, a) #print img #print img.shape #imsave('./output/test.jpg', img) #Longer than a slice, but requires no thought img_copy = np.copy(img) #Constants are Converted to Lists if isinstance(size, int): r = [size] * n else: r = size if placement == 'random': #Random Placement x_center = [randint(100, 900) for _ in range(n)] y_center = [randint(100, 900) for _ in range(n)] a = [randint(0, 360) for _ in range(n)] #r = [randint(5, 25) for _ in range(n)] elif placement == 'grid': #Constant Spacing in a Grid xy = list(product(range(100, 1000, 100), repeat=2)) x_center = [x for x, _ in xy] y_center = [y for _, y in xy] #x, y = zip(*xy) a = [(x + y + 25) for x, y in xy] #r = list(np.linspace( # start=5, stop=50, num=n, endpoint=True)) #print 'In Grid' #print xy #print x_center #print y_center #print a #print r #Converts to Four Tuple xyar = zip( x_center, #x placement (of center) y_center, #y placement (of center) a, #angle (of rotation) r # radius (of circle) ) for x,y,a,r in xyar: if shape == 'circle': rr, cc = circle(x, y, r, img.shape) img_rot = rotate(img_copy, a) img[rr, cc] = img_rot[rr + 500 - x, cc + 500 - y]#+0.0 #img_rot[rr, cc] img = np.copy(img) elif shape == 'square': #print r, y, x #print y-r, y+r, 2*r img[x-r:x+r, y-r:y+r] = rotate(img_copy, a)[500-r:500+r, 500-r:500+r] img = np.copy(img) save_name = './output/%s_%s_%s_%d.jpg' % ( background, shape, placement, n) print save_name img = np.where(img>1.0, 1.0, img) img = np.where(img<0.0, 0.0, img) #np.where imsave(save_name, img) if __name__ == '__main__': #sin_mask_test(hor=100, ver=0) ''' sin_circles_final( background='sin_wave', shape='circle', placement='random', size=list(range(1,101,1)), n=100) ''' ''' sin_circles_final( background='sin_wave', shape='square', placement='grid', size=25, n=100) ''' ''' #Way Long Time sin_circles_final( background='sin_wave', shape='square', placement='random', size=33, n=1000) ''' ''' #Variable Size sin_circles_final( background='checkerboard', shape='circle', placement='random', size=list(range(10,60,10))*20, n=100) '''