Esempio n. 1
0
def anchors_noise_offsets(anchors, offsets, rows, cols, spacing, z_step, x_indices_str, y_indices_str, x_minscale, y_minscale, x_maxscale, y_maxscale):
    from noise import pnoise3
    from plat.interpolate import lerp

    only_anchor = None
    if len(anchors) == 1:
        only_anchor = anchors[0]

    dim = len(anchors[0])
    x_offset = offset_from_string(x_indices_str, offsets, dim)
    y_offset = offset_from_string(y_indices_str, offsets, dim)

    num_row_anchors = (rows + spacing - 1) / spacing
    num_col_anchors = (cols + spacing - 1) / spacing

    newanchors = []
    cur_anchor_index = 0
    for j in range(num_row_anchors):
        y_frac = float(j) / num_row_anchors
        for i in range(num_col_anchors):
            if only_anchor is None:
                cur_anchor = anchors[cur_anchor_index]
                cur_anchor_index += 1
            else:
                cur_anchor = only_anchor
            x_frac = float(i) / num_col_anchors
            n1 = 0.5 * (1.0 + pnoise3(x_frac, y_frac, z_step, octaves=4, repeatz=2))
            n2 = 0.5 * (1.0 + pnoise3(100+x_frac, 100+y_frac, z_step, octaves=4, repeatz=2))
            x_scale = lerp(n1, x_minscale, x_maxscale)
            y_scale = lerp(n2, y_minscale, y_maxscale)
            # print("{}, {} produced {} -> {}, {} = {}".format(i,j,n1,x_minscale, x_maxscale,x_scale))
            newanchors.append(cur_anchor + x_scale * x_offset + y_scale * y_offset)
    return np.array(newanchors)
Esempio n. 2
0
def anchors_json_offsets(anchors, offsets, rows, cols, spacing, z_step,
                         x_indices_str, y_indices_str, x_minscale, y_minscale,
                         x_maxscale, y_maxscale, range_data):
    only_anchor = None
    if len(anchors) == 1:
        only_anchor = anchors[0]

    dim = len(anchors[0])
    x_offset = offset_from_string(x_indices_str, offsets, dim)
    y_offset = offset_from_string(y_indices_str, offsets, dim)

    num_row_anchors = (rows + spacing - 1) / spacing
    num_col_anchors = (cols + spacing - 1) / spacing

    newanchors = []
    cur_anchor_index = 0
    for j in range(num_row_anchors):
        y_frac = float(j) / num_row_anchors
        for i in range(num_col_anchors):
            if only_anchor is None:
                cur_anchor = anchors[cur_anchor_index]
                cur_anchor_index += 1
            else:
                cur_anchor = only_anchor
            x_frac = float(i) / num_col_anchors
            n1 = range_data[z_step][0]
            n2 = range_data[z_step][1]
            x_scale = lerp(n1, x_minscale, x_maxscale)
            y_scale = lerp(n2, y_minscale, y_maxscale)
            # print("{}, {} produced {} -> {}, {} = {}".format(i,j,n1,x_minscale, x_maxscale,x_scale))
            newanchors.append(cur_anchor + x_scale * x_offset +
                              y_scale * y_offset)
    return np.array(newanchors)
Esempio n. 3
0
 def cur_pos(self, is_s):
     if is_s:
         if self.s_cur_frame >= self.num_anim_frames:
             return self.s_dest_x, self.s_dest_y
         v = float(self.s_cur_frame) / self.num_anim_frames
         x = lerp(v, self.s_x, self.s_dest_x)
         y = lerp(v, self.s_y, self.s_dest_y)
         return x, y
     else:
         if self.d_cur_frame >= self.num_anim_frames:
             return self.d_dest_x, self.d_dest_y
         v = float(self.d_cur_frame) / self.num_anim_frames
         x = lerp(v, self.d_x, self.d_dest_x)
         y = lerp(v, self.d_y, self.d_dest_y)
         return x, y
Esempio n. 4
0
def anchors_noise_offsets(anchors, offsets, rows, cols, spacing, z_step,
                          x_indices_str, y_indices_str, x_minscale, y_minscale,
                          x_maxscale, y_maxscale):
    from noise import pnoise3
    from plat.interpolate import lerp

    only_anchor = None
    if len(anchors) == 1:
        only_anchor = anchors[0]

    dim = len(anchors[0])
    x_offset = offset_from_string(x_indices_str, offsets, dim)
    y_offset = offset_from_string(y_indices_str, offsets, dim)

    num_row_anchors = (rows + spacing - 1) / spacing
    num_col_anchors = (cols + spacing - 1) / spacing

    newanchors = []
    cur_anchor_index = 0
    for j in range(num_row_anchors):
        y_frac = float(j) / num_row_anchors
        for i in range(num_col_anchors):
            if only_anchor is None:
                cur_anchor = anchors[cur_anchor_index]
                cur_anchor_index += 1
            else:
                cur_anchor = only_anchor
            x_frac = float(i) / num_col_anchors
            n1 = 0.5 * (1.0 +
                        pnoise3(x_frac, y_frac, z_step, octaves=4, repeatz=2))
            n2 = 0.5 * (1.0 + pnoise3(
                100 + x_frac, 100 + y_frac, z_step, octaves=4, repeatz=2))
            x_scale = lerp(n1, x_minscale, x_maxscale)
            y_scale = lerp(n2, y_minscale, y_maxscale)
            # print("{}, {} produced {} -> {}, {} = {}".format(i,j,n1,x_minscale, x_maxscale,x_scale))
            newanchors.append(cur_anchor + x_scale * x_offset +
                              y_scale * y_offset)
    return np.array(newanchors)
Esempio n. 5
0
def anchors_wave_offsets(anchors, offsets, rows, cols, spacing, radial_wave,
                         clip_wave, z_step, x_indices_str, x_minscale,
                         x_maxscale):
    only_anchor = None
    if len(anchors) == 1:
        only_anchor = anchors[0]

    dim = len(anchors[0])
    x_offset = offset_from_string(x_indices_str, offsets, dim)

    num_row_anchors = (rows + spacing - 1) / spacing
    num_col_anchors = (cols + spacing - 1) / spacing

    newanchors = []
    cur_anchor_index = 0
    center_pt = [(num_col_anchors - 1) / 2.0, (num_row_anchors - 1) / 2.0]
    max_dist = distance_2d([0, 0], center_pt)
    for j in range(num_row_anchors):
        for i in range(num_col_anchors):
            if only_anchor is None:
                cur_anchor = anchors[cur_anchor_index]
                cur_anchor_index += 1
            else:
                cur_anchor = only_anchor
            cur_dist = distance_2d([i, j], center_pt)
            if radial_wave:
                x_frac = (max_dist - cur_dist) / max_dist
            else:
                x_frac = float(i) / num_col_anchors
            wave_val = z_step + x_frac
            n1 = compute_wave(wave_val, clip_wave)
            x_scale = lerp(n1, x_minscale, x_maxscale)
            # if wave_val < 0.0 or wave_val > 1.0:
            #     x_scale = x_minscale
            # else:
            #     if wave_val < 0.5:
            #         n1 = wave_val * 2
            #     else:
            #         n1 = (1.0 - wave_val) * 2
            #     x_scale = lerp(n1, x_minscale, x_maxscale)
            # print("{}, {} produced {} -> {}, {} = {}".format(i,j,n1,x_minscale, x_maxscale,x_scale))
            newanchors.append(cur_anchor + x_scale * x_offset)
    return np.array(newanchors)