kopia lustrzana https://github.com/inkstitch/inkstitch
rodzic
85f921cd33
commit
e2965e78f0
|
@ -783,7 +783,7 @@ class SatinColumn(EmbroideryElement):
|
||||||
|
|
||||||
# pre-cache ramdomised parameters to avoid property calls in loop
|
# pre-cache ramdomised parameters to avoid property calls in loop
|
||||||
if use_random:
|
if use_random:
|
||||||
seed = prng.joinArgs(self.random_seed, "satin-points")
|
seed = prng.join_args(self.random_seed, "satin-points")
|
||||||
offset_proportional_min = np.array(offset_proportional) - self.random_width_decrease
|
offset_proportional_min = np.array(offset_proportional) - self.random_width_decrease
|
||||||
offset_range = (self.random_width_increase + self.random_width_decrease)
|
offset_range = (self.random_width_increase + self.random_width_decrease)
|
||||||
spacing_sigma = spacing * self.random_zigzag_spacing
|
spacing_sigma = spacing * self.random_zigzag_spacing
|
||||||
|
@ -857,7 +857,7 @@ class SatinColumn(EmbroideryElement):
|
||||||
|
|
||||||
if to_travel <= 0:
|
if to_travel <= 0:
|
||||||
if use_random:
|
if use_random:
|
||||||
roll = prng.uniformFloats(seed, cycle)
|
roll = prng.uniform_floats(seed, cycle)
|
||||||
offset_prop = offset_proportional_min + roll[0:2] * offset_range
|
offset_prop = offset_proportional_min + roll[0:2] * offset_range
|
||||||
to_travel = spacing + ((roll[2] - 0.5) * 2 * spacing_sigma)
|
to_travel = spacing + ((roll[2] - 0.5) * 2 * spacing_sigma)
|
||||||
else:
|
else:
|
||||||
|
@ -987,7 +987,7 @@ class SatinColumn(EmbroideryElement):
|
||||||
if last_point is not None:
|
if last_point is not None:
|
||||||
split_points, _ = self.get_split_points(
|
split_points, _ = self.get_split_points(
|
||||||
last_point, a, last_short_point, a_short, max_stitch_length, last_count,
|
last_point, a, last_short_point, a_short, max_stitch_length, last_count,
|
||||||
length_sigma, random_phase, min_split_length, prng.joinArgs(seed, 'satin-split', 2*i))
|
length_sigma, random_phase, min_split_length, prng.join_args(seed, 'satin-split', 2 * i))
|
||||||
patch.add_stitches(split_points, ("satin_column", "satin_split_stitch"))
|
patch.add_stitches(split_points, ("satin_column", "satin_split_stitch"))
|
||||||
|
|
||||||
patch.add_stitch(a_short)
|
patch.add_stitch(a_short)
|
||||||
|
@ -995,7 +995,7 @@ class SatinColumn(EmbroideryElement):
|
||||||
|
|
||||||
split_points, last_count = self.get_split_points(
|
split_points, last_count = self.get_split_points(
|
||||||
a, b, a_short, b_short, max_stitch_length, None,
|
a, b, a_short, b_short, max_stitch_length, None,
|
||||||
length_sigma, random_phase, min_split_length, prng.joinArgs(seed, 'satin-split', 2*i+1))
|
length_sigma, random_phase, min_split_length, prng.join_args(seed, 'satin-split', 2 * i + 1))
|
||||||
patch.add_stitches(split_points, ("satin_column", "satin_split_stitch"))
|
patch.add_stitches(split_points, ("satin_column", "satin_split_stitch"))
|
||||||
|
|
||||||
patch.add_stitch(b_short)
|
patch.add_stitch(b_short)
|
||||||
|
|
|
@ -24,7 +24,7 @@ def split_segment_even_n(a, b, segments: int, jitter_sigma: float = 0.0, random_
|
||||||
|
|
||||||
splits = np.array(range(1, segments)) / segments
|
splits = np.array(range(1, segments)) / segments
|
||||||
if random_seed is not None:
|
if random_seed is not None:
|
||||||
jitters = (prng.nUniformFloats(len(splits), random_seed) * 2) - 1
|
jitters = (prng.n_uniform_floats(len(splits), random_seed) * 2) - 1
|
||||||
splits = splits + jitters * (jitter_sigma / segments)
|
splits = splits + jitters * (jitter_sigma / segments)
|
||||||
|
|
||||||
# sort the splits in case a bad roll transposes any of them
|
# sort the splits in case a bad roll transposes any of them
|
||||||
|
@ -39,12 +39,12 @@ def split_segment_even_dist(a, b, max_length: float, jitter_sigma: float = 0.0,
|
||||||
|
|
||||||
def split_segment_random_phase(a, b, length: float, length_sigma: float, random_seed: str) -> typing.List[shgeo.Point]:
|
def split_segment_random_phase(a, b, length: float, length_sigma: float, random_seed: str) -> typing.List[shgeo.Point]:
|
||||||
line = shgeo.LineString([a, b])
|
line = shgeo.LineString([a, b])
|
||||||
progress = length * prng.uniformFloats(random_seed, "phase")[0]
|
progress = length * prng.uniform_floats(random_seed, "phase")[0]
|
||||||
splits = [progress]
|
splits = [progress]
|
||||||
distance = line.length
|
distance = line.length
|
||||||
if progress >= distance:
|
if progress >= distance:
|
||||||
return []
|
return []
|
||||||
for x in prng.iterUniformFloats(random_seed):
|
for x in prng.iter_uniform_floats(random_seed):
|
||||||
progress += length * (1 + length_sigma * (x - 0.5) * 2)
|
progress += length * (1 + length_sigma * (x - 0.5) * 2)
|
||||||
if progress >= distance:
|
if progress >= distance:
|
||||||
break
|
break
|
||||||
|
|
|
@ -13,7 +13,7 @@ import numpy as np
|
||||||
# Using multiple counters for n-dimentional random streams is also possible and is useful for grid-like structures.
|
# Using multiple counters for n-dimentional random streams is also possible and is useful for grid-like structures.
|
||||||
|
|
||||||
|
|
||||||
def joinArgs(*args):
|
def join_args(*args):
|
||||||
# Stringifies parameters into a slash-separated string for use in hash keys.
|
# Stringifies parameters into a slash-separated string for use in hash keys.
|
||||||
# Idempotent and associative.
|
# Idempotent and associative.
|
||||||
return "/".join([str(x) for x in args])
|
return "/".join([str(x) for x in args])
|
||||||
|
@ -22,37 +22,37 @@ def joinArgs(*args):
|
||||||
MAX_UNIFORM_INT = 2 ** 32 - 1
|
MAX_UNIFORM_INT = 2 ** 32 - 1
|
||||||
|
|
||||||
|
|
||||||
def uniformInts(*args):
|
def uniform_ints(*args):
|
||||||
# Single pseudo-random drawing determined by the joined parameters.
|
# Single pseudo-random drawing determined by the joined parameters.
|
||||||
# To get a longer sequence of random numbers, call this loop with a counter as one of the parameters.
|
# To get a longer sequence of random numbers, call this loop with a counter as one of the parameters.
|
||||||
# Returns 8 uniformly random uint32.
|
# Returns 8 uniformly random uint32.
|
||||||
|
|
||||||
s = joinArgs(*args)
|
s = join_args(*args)
|
||||||
# blake2s is python's fastest hash algorithm for small inputs and is designed to be usable as a PRNG.
|
# blake2s is python's fastest hash algorithm for small inputs and is designed to be usable as a PRNG.
|
||||||
h = blake2s(s.encode()).hexdigest()
|
h = blake2s(s.encode()).hexdigest()
|
||||||
nums = []
|
nums = []
|
||||||
for i in range(0, 64, 8):
|
for i in range(0, 64, 8):
|
||||||
nums.append(int(h[i:i+8], 16))
|
nums.append(int(h[i:i + 8], 16))
|
||||||
return np.array(nums)
|
return np.array(nums)
|
||||||
|
|
||||||
|
|
||||||
def uniformFloats(*args):
|
def uniform_floats(*args):
|
||||||
# Single pseudo-random drawing determined by the joined parameters.
|
# Single pseudo-random drawing determined by the joined parameters.
|
||||||
# To get a longer sequence of random numbers, call this loop with a counter as one of the parameters.
|
# To get a longer sequence of random numbers, call this loop with a counter as one of the parameters.
|
||||||
# Returns an array of 8 floats in the range [0,1]
|
# Returns an array of 8 floats in the range [0,1]
|
||||||
return uniformInts(*args) / MAX_UNIFORM_INT
|
return uniform_ints(*args) / MAX_UNIFORM_INT
|
||||||
|
|
||||||
|
|
||||||
def nUniformFloats(n: int, *args):
|
def n_uniform_floats(n: int, *args):
|
||||||
# returns a fixed number (which may exceed 8) of floats in the range [0,1]
|
# returns a fixed number (which may exceed 8) of floats in the range [0,1]
|
||||||
seed = joinArgs(*args)
|
seed = join_args(*args)
|
||||||
nBlocks = ceil(n/8)
|
nBlocks = ceil(n / 8)
|
||||||
blocks = [uniformFloats(seed, x) for x in range(nBlocks)]
|
blocks = [uniform_floats(seed, x) for x in range(nBlocks)]
|
||||||
return np.concatenate(blocks)[0:n]
|
return np.concatenate(blocks)[0:n]
|
||||||
|
|
||||||
|
|
||||||
def iterUniformFloats(*args):
|
def iter_uniform_floats(*args):
|
||||||
# returns an infinite sequence of floats in the range [0,1]
|
# returns an infinite sequence of floats in the range [0,1]
|
||||||
seed = joinArgs(*args)
|
seed = join_args(*args)
|
||||||
blocks = map(lambda x: list(uniformFloats(seed, x)), count(0))
|
blocks = map(lambda x: list(uniform_floats(seed, x)), count(0))
|
||||||
return chain.from_iterable(blocks)
|
return chain.from_iterable(blocks)
|
||||||
|
|
Ładowanie…
Reference in New Issue