def main(): from modules.boids import B from sand import Sand from fn import Fn fn = Fn(prefix='./res/', postfix='.png') sand = Sand(SIZE) sand.set_bg(BACK) sand.set_rgba(FRONT) b = B(INIT_NUM, SIZE, STP) for itt in range(1000000): b.step(separation=SEPARATION, cohesion=COHESION, alignment=ALIGNMENT) xy = b.xy for i, nearby in enumerate(b.get_nearby()): if not nearby: continue start = zeros((len(nearby), 2)) start[:, 0] = xy[i, 0] start[:, 1] = xy[i, 1] stop = xy[nearby, :] g = GRAINS * ones(len(nearby), 'int') sand.paint_strokes(start, stop, g) if not itt % DRAW_ITT: name = fn.name() print(itt, name) sand.write_to_png(name)
def random_bw_array(): size = 1000 rnd = random((size,size)) rnd[:,int(size/2):] = 0.0 s = Sand(size) s.set_bg_from_bw_array(rnd) s.write_to_png('./out_random_bw_array.png')
def random_rgb_array(): size = 1000 rnd = random((size,size,3)) rnd[:,int(size/2):,0] = 0.0 rnd[int(size/2):,:,2] = 0.0 s = Sand(size) s.set_bg_from_rgb_array(rnd) s.write_to_png('./out_random_rgb_array.png')
def main(): sand = Sand(SIZE) sand.set_bg(BG) sand.set_rgba(FRONT) fn = Fn(prefix='./res/', postfix='.png') for index, spline in enumerate(spline_iterator()): sand.paint_dots(spline) if not index % SIZE: print('Iteration {}'.format(index)) sand.write_to_png(fn.name(), GAMMA)
def main(): from sand import Sand from fn import Fn sand = Sand(SIZE) sand.set_rgba(FRONT) fn = Fn(prefix='./res/', postfix='.png') make_creatures(sand) name = fn.name() sand.write_to_png(name, GAMMA)
def main(): from sand import Sand size = 1000 s = Sand(size) t = time() xya = random((1000000,2)) xyb = random((1000000,2)) s.paint_strokes(xya, xyb, GRAINS, RED) s.write_to_png('./out.png') t1 = time()-t print('time', t1)
def main(): from sand import Sand from fn import Fn from iutils.ioOBJ import export_2d as export sand = Sand(SIZE) sand.set_rgba(FRONT) fn = Fn(prefix='./res/') vertices, lines = make_creatures(sand) name = fn.name() sand.write_to_png(name + '.png', GAMMA) export('scribbles', name + '.2obj', verts=vertices, lines=lines)
def main(): from modules.fracture import Fracture from numpy.random import random from numpy import linspace from iutils.random import darts_rect from time import time from numpy.random import seed from sand import Sand from fn import Fn fn = Fn(prefix='./res/') sand = Sand(SIZE) sand.set_bg(BACK) sand.set_rgba(FRONT) seed(1) start = time() initial_sources = darts_rect( SOURCES, 0.5, 0.5, 1.0-2.0*EDGE, 1.0-2.0*EDGE, FRAC_STP ) F = Fracture( FRAC_DOT, FRAC_DST, FRAC_STP, initial_sources=initial_sources, zone_leap=ZONE_LEAP, nmax=NMAX ) for _ in range(INIT_FRACS): F.blow(1, EDGE+random((1, 2))*(1.0-2.0*EDGE)) while True: res = F.step() F.frac_front(factor=SPAWN_FACTOR, angle=SPAWN_ANGLE, dbg=DBG) if not F.itt % ITT or not res: print('itt', F.itt, 'num', F.num, 'fnum', F.fnum, 'anum', F.anum, 'time', time()-start) if not res: print('done') break show(sand, F) name = fn.name()+'.png' print(name) sand.write_to_png(name)
def main(): from dunes import Dunes from sand import Sand from fn import Fn from time import time from modules.helpers import get_initial_rnd initial = get_initial_rnd(SIZE, n=4) bw = zeros(initial.shape,'float') dunes = Dunes(initial, DELTA, PROB) sand = Sand(SIZE) sand.set_rgba(FRONT) fn = Fn(prefix='./res/', postfix='.png') try: while True: t0 = time() itt = dunes.steps(LEAP) print(itt, time()-t0) dunes.get_normalized_sand_limit(bw, 10) # bw *= 0.8 # sand.set_bg_from_bw_array(bw) # dunes.get_shadow(shadow) # rgb = dstack((bw,bw,shadow)) # sand.set_bg_from_rgb_array(rgb) sand.set_bg_from_bw_array(bw) name = fn.name() sand.write_to_png(name) except KeyboardInterrupt: pass
def main(): from sand import Sand from fn import Fn sand = Sand(SIZE) sand.set_bg(BACK) sand.set_rgba(FRONT) fn = Fn(prefix='./res/', postfix='.png') run(sand) name = fn.name() sand.write_to_png(name, GAMMA)
def main(): from sand import Sand from fn import Fn from iutils.ioOBJ import export_2d as export sand = Sand(SIZE) sand.set_bg(BACK) sand.set_rgba(FRONT) fn = Fn(prefix='./res/') vertices, lines = write(sand) name = fn.name() sand.write_to_png(name + '.png', GAMMA) export('glyphs', name + '.2obj', verts=vertices, lines=lines)
def random_bw_array(): size = 1000 rnd = random((size, size)) rnd[:, int(size / 2):] = 0.0 s = Sand(size) s.set_bg_from_bw_array(rnd) s.write_to_png('./out_random_bw_array.png')
def main(): import sys, traceback from fn import Fn from sand import Sand sand = Sand(SIZE) sand.set_bg(BG) sand.set_rgba(FRONT) fn = Fn(prefix='./res/', postfix='.png') si = spline_iterator() while True: try: itt, w, xy = next(si) sand.paint_dots(xy) if not itt % (SIZE): print(itt) # sand.write_to_png(fn.name(), GAMMA) except Exception as e: print(e) sand.write_to_png(fn.name(), GAMMA) traceback.print_exc(file=sys.stdout) return
def random_rgb_array(): size = 1000 rnd = random((size, size, 3)) rnd[:, int(size / 2):, 0] = 0.0 rnd[int(size / 2):, :, 2] = 0.0 s = Sand(size) s.set_bg_from_rgb_array(rnd) s.write_to_png('./out_random_rgb_array.png')
def main(): from sand import Sand from fn import Fn sand = Sand(SIZE) sand.set_rgba(FRONT) fn = Fn(prefix='./res/', postfix='.png') make_creatures(sand) # sand.set_bg_from_bw_array(bw) name = fn.name() sand.write_to_png(name, GAMMA)
def main(): import sys, traceback from fn import Fn from sand import Sand sand = Sand(SIZE) sand.set_bg(BG) sand.set_rgba(FRONT) fn = Fn(prefix='./res/', postfix='.png') si = spline_iterator() while True: try: itt, w, xy = next(si) sand.paint_dots(xy) if not itt%(SIZE): print(itt) # sand.write_to_png(fn.name(), GAMMA) except Exception as e: print(e) sand.write_to_png(fn.name(), GAMMA) traceback.print_exc(file=sys.stdout) return
def app(environ, response): # initialize API sand_app = Sand('./templates', './static') # add routes setup_routes(sand_app) # add exception handler sand_app.add_exception_handler(custom_exception_handler) # add middleware sand_app.add_middleware(LogMiddleware) # return WSGI compatible app return sand_app(environ, response)
def random_dots(): size = 1000 num = 10000000 s = Sand(size) s.set_bg(BACK) aa = random((num, 2)) aa[:, 0] *= 0.5 bb = random((num, 2)) bb[:, 1] *= 0.5 cc = random((num, 2)) * 0.5 cc[:, 0] += 0.1 s.set_rgba(GREEN) s.paint_dots(aa) s.set_rgba(RED) s.paint_dots(bb) s.set_rgba(BLUE) s.paint_dots(cc) s.write_to_png('./out_random.png')
from myplane import Plane from mywindow import Window from sand import Sand import mycolors import math SAND_NUMBER = 10 sand = [Sand.random(9e-1, 11e-1) for i in range(SAND_NUMBER)] window = Window() plane = Plane(offset=[window.w/2, window.h/2], zoom=min(window.size)/10) angle = 0 while window.open: window.check() window.clear(mycolors.WHITE) angle += 0.01 angle %= 2*math.pi xoffset = math.cos(angle) yoffset = math.sin(angle) for grain in sand: x, y = plane.getToScreen(grain.center)
from sand import Sand app = Sand() @app.route("/") def home(req, resp): resp.text = "Welcome home" @app.route("/about") def about(req, resp): resp.text = "This is what it's about"
def main(): import sys, traceback from fn import Fn from sand import Sand from modules.helpers import get_colors sand = Sand(SIZE) sand.set_bg(BG) sand.set_rgba(FRONT) colors = get_colors('colors/dark_cyan_white_black.gif') nc = len(colors) fn = Fn(prefix='./res/', postfix='.png') si = spline_iterator() while True: try: itt, w, xy = next(si) rgba = colors[w%nc] + [0.005] sand.set_rgba(rgba) sand.paint_dots(xy) if not itt%(50): print("ci:"+str(itt)) if not itt%(5000): if os.path.isfile("./res/dump1.png"): print("printing to dump2:"+str(itt)) sand.write_to_png("./res/dump2.png", GAMMA) os.remove("./res/dump1.png") else: print("printing to dump1:"+str(itt)) sand.write_to_png("./res/dump1.png", GAMMA) if os.path.isfile("./res/dump2.png"): os.remove("./res/dump2.png") except Exception as e: print(e) sand.write_to_png("./res/current.png", GAMMA) traceback.print_exc(file=sys.stdout)
def random_dots(): size = 1000 num = 10000000 s = Sand(size) s.set_bg(BACK) aa = random((num,2)) aa[:,0]*=0.5 bb = random((num,2)) bb[:,1]*=0.5 cc = random((num,2))*0.5 cc[:,0] += 0.1 s.set_rgba(GREEN) s.paint_dots(aa) s.set_rgba(RED) s.paint_dots(bb) s.set_rgba(BLUE) s.paint_dots(cc) s.write_to_png('./out_random.png')
def main(): parser = argparse.ArgumentParser() parser.add_argument('--4-int-colour-list', nargs='+', type=int) import sys, traceback from fn import Fn from sand import Sand rgba_list = parser.parse_args()._get_args() sand = Sand(SIZE) sand.set_bg(BG) sand.set_rgba(rgba_list) fn = Fn(prefix='./res/', postfix='.png') si = spline_iterator() while True: try: itt, xy = next(si) sand.paint_dots(xy) if not itt % (5000 * GRID_Y): print(itt) sand.write_to_png(fn.name(), GAMMA) except Exception as e: print(e) sand.write_to_png(fn.name(), GAMMA) traceback.print_exc(file=sys.stdout)
#! /usr/bin/env python from sand import Sand from fault import Fault if __name__ == "__main__": print "At the beach." sand = Sand() print "Number of sand castles is ", sand.numberOfCastles() print "Names:" print sand.namesOfCastles() print fault = Fault() fault.add_msg("test message Line 1\n"); fault.add_msg("test message Line 2\n"); print fault.msg(), print try: print "Calling castleFault" sand.castleFault() except Fault,f: print "Fault caught, message is:" print f.msg()
def main(): from fn import Fn from modules.differentialLattice import DifferentialLattice from modules.helpers import get_colors from modules.helpers import spawn_circle from numpy import array from numpy import cumsum from numpy import sqrt from numpy import linspace from numpy import sort from numpy import ones from numpy.random import random from numpy.random import seed from sand import Sand from numpy import pi from numpy import sin from numpy import cos TWOPI = pi*2.0 fn = Fn(prefix='./res/') size = 512 one = 1.0/size threads = 512 zone_leap = 512 grains = 20 init_num = 20 stp = one*0.03 spring_stp = 5 reject_stp = 0.1 cohesion_stp = 1.0 max_capacity = 30 node_rad = 4*one spring_reject_rad = node_rad*1.9 spring_attract_rad = node_rad*2.0 outer_influence_rad = 10.0*node_rad link_ignore_rad = 0.5*outer_influence_rad colors = get_colors('../colors/black_t.gif') # colors = get_colors('../colors/ir.jpg') nc = len(colors) sand = Sand(size) sand.set_bg(BACK) sand.set_rgba(FRONT) DL = DifferentialLattice( size, stp, spring_stp, reject_stp, cohesion_stp, max_capacity, node_rad, spring_reject_rad, spring_attract_rad, outer_influence_rad, link_ignore_rad, threads=threads, zone_leap=zone_leap, nmax=50000000 ) spawn_circle(DL, init_num, xy=array([[0.5, 0.5]]), dst=node_rad*0.8, rad=0.01) itt = 0 while True: itt += 1 DL.step() DL.spawn(ratio=0.1, age=1000) if not itt%20: print(('itt', DL.itt, 'num', DL.num)) vertices, edges = DL.link_export() # sand.set_rgba(FRONT) # sand.paint_strokes( # vertices[edges[:,0],:].astype('double'), # vertices[edges[:,1],:].astype('double'), # grains # ) # sand.paint_circles( # vertices.astype('double'), # random(len(vertices))*one*4.0, # grains # ) # for k,(a,b) in enumerate(edges): # w = a*nc+b # rgba = colors[w%nc]+[0.001] # sand.set_rgba(rgba) # sand.paint_strokes( # vertices[a:a+1,:].astype('double'), # vertices[b:b+1,:].astype('double'), # grains # ) n = 20 for k, (x, y) in enumerate(vertices): rgba = colors[k%nc]+[0.0005] sand.set_rgba(rgba) o = ones((n, 2), 'float') o[:,0] *= x o[:,1] *= y r = (1.0-2.0*random(n))*4*one sand.paint_filled_circles( o, r, grains ) if not itt%5: # vertices, edges = DL.link_export() # n = 1000 # sand.set_bg(BACK) # seed(1) # for k, (x, y) in enumerate(vertices): # rgba = colors[k%nc]+[0.005] # sand.set_rgba(rgba) # o = ones((n, 2), 'float') # o[:,0] *= x # o[:,1] *= y # r = random()*one*3+cumsum(random(n)*random()*10)*one*0.002 # # r = sqrt(linspace(2.0, 10.0, n))*one # # r = ones(n, 'float')*one* # sand.paint_circles( # o, # r, # grains # ) name = fn.name() + '.png' print(name) sand.write_to_png(name, 2)
def main(): import sys, traceback from fn import Fn from sand import Sand from modules.helpers import get_colors sand = Sand(SIZE) sand.set_bg(BG) sand.set_rgba(FRONT) colors = get_colors('../colors/dark_cyan_white_black2.gif') nc = len(colors) fn = Fn(prefix='./res/', postfix='.png') si = spline_iterator() while True: try: itt, w, xy = next(si) rgba = colors[w%nc] + [0.0005] sand.set_rgba(rgba) sand.paint_dots(xy) if not itt%(40000): print(itt) sand.write_to_png(fn.name(), GAMMA) except Exception as e: print(e) sand.write_to_png(fn.name(), GAMMA) traceback.print_exc(file=sys.stdout)
def main(): import sys, traceback from fn import Fn from sand import Sand sand = Sand(SIZE) sand.set_bg_from_rgb_array(img) sand.set_rgba(FRONT) fn = Fn(prefix='./res/', postfix='.png') si = spline_iterator() while True: try: itt, xy = next(si) # sand.distort_dots_swap(xy) sand.distort_dots_wind(xy) if not itt%5000: print(itt) sand.write_to_png(fn.name()) except Exception: sand.write_to_png(fn.name()) traceback.print_exc(file=sys.stdout) return
def main(): from sand import Sand size = 1000 s = Sand(size) s.set_bg(BACK) t = time() aa = random((1000000,2)) aa[:,0]*=0.5 bb = random((1000000,2)) bb[:,1]*=0.5 cc = random((1000000,2))*0.5 cc[:,0] += 0.1 s.paint_dots(aa, GREEN) s.paint_dots(bb, BLUE) s.paint_dots(cc, RED) s.write_to_png('./out.png') t1 = time()-t print('time', t1) from iutils.render import Render render = Render(size, BACK, FRONT) t = time() render.set_front(GREEN) for x,y in aa: render.dot(x,y) render.set_front(BLUE) for x,y in bb: render.dot(x,y) render.set_front(RED) for x,y in cc: render.dot(x,y) render.write_to_png('./out2.png') t2 = time()-t print('time2', t2) print('speedup', t2/t1)
import numpy as np import matplotlib import matplotlib.pyplot as pyplot import networkx as nx from sand import Sand, SandGraph if __name__ == '__main__': #generate the text # I don't really know how s = Sand(n=3000, critLevel=4) s.loop(steps=1500) grph = SandGraph(s.graphs) take the graph make words out of it with a markov-like process? associate centralities with frequencies, then randomly walk the chain maybe grammar will come spiralling out of it
def main(): import sys, traceback from fn import Fn from sand import Sand from modules.helpers import get_colors sand = Sand(SIZE) sand.set_bg(BG) sand.set_rgba(FRONT) colors = get_colors('../colors/dark_cyan_white_black2.gif') nc = len(colors) fn = Fn(prefix='./res/', postfix='.png') si = spline_iterator() while True: try: itt, w, xy = next(si) rgba = colors[w % nc] + [0.0005] sand.set_rgba(rgba) sand.paint_dots(xy) if not itt % (40000): print(itt) sand.write_to_png(fn.name(), GAMMA) except Exception as e: print(e) sand.write_to_png(fn.name(), GAMMA) traceback.print_exc(file=sys.stdout)
def app(): return Sand()