Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Good god my code is shite
- # Kind Regards
- import numpy as np
- import math
- import Image
- def dofilter(array1):
- xsize, ysize = array1.shape
- a0 = np.zeros(size)
- diffx = np.diff(array1)
- diffy = np.diff(array1,axis=0)
- a0[:,:xsize-1] += diffx
- a0[:,1:] -= diffx
- a0[:ysize-1] += diffy
- a0[1:] -= diffy
- return a0*0.5
- def step_forward(a1,a1v,n=1,action=None):
- for bx in xrange(n):
- if action:
- a1 = action(a1)
- a1v += dofilter(a1)*k_const
- a1 += a1v
- return a1, a1v
- def action_1(x):
- x[ox-1:ox+1,oy-1:oy+1] = 0.9
- return x
- size = (200,200)
- k_const = 0.25
- speed = 3
- a1 = np.zeros(size)
- a1v = np.zeros(size)
- for imnum in xrange(400):
- ox = int(100 + (math.sin(imnum*0.2)*20))
- oy = int(100 - (math.cos(imnum*0.2)*20))
- if imnum < 75:
- a1, a1v = step_forward(a1,a1v,n=speed,action=action_1)
- else:
- a1, a1v = step_forward(a1,a1v,n=speed)
- im = Image.fromarray(np.uint8((a1+1)*128))
- im.save("output_k_" + format(imnum,"03d") + ".png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement