This commit is contained in:
parent
fe84c73459
commit
1d216288db
17
lsca.uni.py
17
lsca.uni.py
|
@ -12,7 +12,7 @@ def colorize(x):
|
||||||
return x * 17 % 256
|
return x * 17 % 256
|
||||||
|
|
||||||
|
|
||||||
def render(row):
|
def render(row, scale):
|
||||||
grays = colorize(row)
|
grays = colorize(row)
|
||||||
if scale > 1:
|
if scale > 1:
|
||||||
grays = np.repeat(grays, scale)
|
grays = np.repeat(grays, scale)
|
||||||
|
@ -27,14 +27,13 @@ def limit(row): # in-place
|
||||||
return row
|
return row
|
||||||
|
|
||||||
|
|
||||||
def initialize():
|
def initialize(width):
|
||||||
row = np.zeros(width, int)
|
row = np.zeros(width, int)
|
||||||
prev, here = 0, 0
|
value = 0
|
||||||
for i in range(width):
|
for i in range(width):
|
||||||
if np.random.randint(0, 8) == 0:
|
if np.random.randint(8) == 0: # only change values occasionally
|
||||||
here = np.random.randint(16)
|
value = np.random.randint(16)
|
||||||
row[i] = here
|
row[i] = value
|
||||||
prev = here
|
|
||||||
limit(row)
|
limit(row)
|
||||||
return row
|
return row
|
||||||
|
|
||||||
|
@ -63,7 +62,7 @@ print("P2") # magic code for an ascii Portable GrayMap (PGM) file
|
||||||
print(width * scale, height * scale)
|
print(width * scale, height * scale)
|
||||||
print(255) # maximum color value
|
print(255) # maximum color value
|
||||||
|
|
||||||
row = initialize()
|
row = initialize(width)
|
||||||
|
|
||||||
for i in range(height):
|
for i in range(height):
|
||||||
# left, center, right:
|
# left, center, right:
|
||||||
|
@ -81,4 +80,4 @@ for i in range(height):
|
||||||
row = diffusion + delta
|
row = diffusion + delta
|
||||||
|
|
||||||
limit(row)
|
limit(row)
|
||||||
render(row)
|
render(row, scale)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user