Пример #1
0
    def draw(self):
        steps = int(lerp(1, 1024, self.step))
        x_density = int(lerp(self.w / 256, self.w / 4, self.param_a))
        y_density = int(lerp(self.h / 256, self.h / 4, self.param_a))
        padding = lerp(0, 0.75, self.param_b)
        line_width = lerp(0.1, 8.0, self.param_c)
        conv = lerp(1.0, 8.0, self.param_d)

        # set wanderer starting positions
        grid = Grid(0, 0, 1, 1, 12, 12, padding=padding)
        starts = grid.centers()

        # wander points through field
        speed = 0.0005
        paths = []
        for start in starts:
            path = empty([steps, 2])
            path[0] = start
            for i in range(1, steps):
                # last position
                x, y = path[i - 1]
                vec = self.vector_at((x, y), mult=conv)
                # new position
                nx = x + vec[0] * speed
                ny = y + vec[1] * speed
                path[i] = [nx, ny]
            paths.append(path)

        # DEBUG: display flow field (interpolated points)
        if self.option_d:
            self.set_color(self.color_d)
            rad = (self.max_x - self.min_x) / x_density / 3
            for y in linspace(self.min_y, self.max_y, x_density):
                for x in linspace(self.min_x, self.max_x, y_density):
                    vec = self.vector_at((x, y))
                    a = array((x, y))
                    b = a + vec * 0.1
                    self.set_color(self.sample_layer_in((x, y)))
                    self.circle(a, rad, fill=True)

            self.set_line_width(60 / x_density)
            self.set_color([1, 1, 1, 1])
            for y in linspace(self.min_y, self.max_y, x_density):
                for x in linspace(self.min_x, self.max_x, y_density):
                    vec = self.vector_at((x, y))
                    a = array((x, y))
                    b = a + vec * 0.1
                    self.line(a, b)

        # draw wandering paths
        self.set_color(self.color_a)
        self.ctx.set_line_cap(LINE_CAP_ROUND)
        self.set_line_width(line_width)
        for path in paths:
            self.path(path)
Пример #2
0
def render():
    # size = 120
    size = 8
    grid = Grid(-1, -1, 2, 2, rows=size, cols=size)

    ctx.clear([0, 0, 0, 1])
    ctx.set_range(-1, 1)

    for xy in grid.centers():
        x, y = xy

        print(x, y)
        color = ctx.sample_point(x, y)
        ctx.set_color(color)

        ctx.circle(x, y, 0.1, fill=True)
Пример #3
0
# triangle to wedge
# from geom.circle import Circle
# circ = Circle()
# tri = circ.as_polygon(n=3)
# tri = tri.rotate(pi / 2)
# tri.draw(ctx)
# x, y = tri.center()
# ctx.circle(x, y, 0.02)

# ptsA = tri.points
# ptsB = roll(ptsA, 1, axis=0)

# arcs = []
# for a, b in zip(ptsA, ptsB):
    # arc = Arc.arcFrom2Points(b, a, 1.8)
    # arc.draw(ctx)

from geom.grid import Grid
grid = Grid(-0.25, -0.25, count, count, count, count)
for pt in grid.centers():
    x, y = pt
    ctx.circle(x, y, 0.01)

grid = Grid(0.25, 0.25, count, count, count, count)
ctx.set_color([1, 1, 1, 1])
for pt in grid.centers():
    x, y = pt
    ctx.circle(x, y, 0.01)

ctx._ctx
Пример #4
0
#%%
from geom.grid import Grid

grid_size = 64
cells = Grid(1, 1, grid_size, grid_size, padding=0.05)
centers = cells.centers()
centers

from modules.perlin import generate_perlin_noise_2d
pnoise = generate_perlin_noise_2d((512, 512), (8, 8))
pnoise

from geom.circle import Circle
from numpy import linspace
from numpy import interp
from math import sin, cos, pi
from numpy.random import rand

large_rad = (1.0 / grid_size / 2.0) * 0.9
small_rad = large_rad * 0.333
circle_count = 9
rads = linspace(large_rad, small_rad, circle_count)
def circle_stack(pos):
    noise = pnoise[int(pos[0] * 255), int(pos[1] * 255)]
    theta = interp(noise, [-1.0, 1.0], [0, 2 * pi])
    scale = rand() * large_rad * 0.666
    
    x_off = linspace(0, sin(theta) * scale, circle_count)
    y_off = linspace(0, cos(theta) * scale, circle_count)
    
    stack = []