Пытаясь оживить растущую и сокращающуюся нить, с ответвлением - PullRequest
0 голосов
/ 30 апреля 2019

В основном, родительская нить растет и сжимается от начальной точки в пространстве. Когда он достигает пороговой длины (в приведенном мною коде он соответствует координатам = (X = 8, X = 8)). В этот момент ветка начинает расти из (8,8). Ветвь растет и сжимается аналогично родительскому элементу, разница состоит в том, что его начальная точка равна (8,8) по сравнению с (1,1) для родительского элемента (хотя я начинаю переход с (1,1), то есть просто чтобы длина списка была равна анимации)

Большая проблема в том, что в моем коде несколько таких родительских филаментов растут под разными углами, и когда каждая из них пересекает пороговую длину, ветвь возникает под случайным углом. Также, если родитель сжимается до длины, меньшей порогового значения, ветвь исчезает (или, если проще, координаты ветвления такие же, как у родителя).

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

X = [1,2,3,4,5,6,7,8,9,10,11,12,11,10,11,12,13,14,15,14,13,12,13] #parent x coord
Y = [1,2,3,4,5,6,7,8,9,10,11,12,11,10,11,12,13,14,15,14,13,12,13] #parent y coord

X1 = [1,2,3,4,5,6,7,8,7,6,5,4,4,4,5,6,7,8,7,6,5,4,3] #branch x coord
Y1 = [1,2,3,4,5,6,7,8,9,10,11,12,12,12,11,10,9,8,9,10,11,12,13] #branch y coord

fig, ax = plt.subplots(1,1)
ax.set_xlim([0, 20])
ax.set_ylim([-1.1, 20])

graph1, = ax.plot([], [], color = 'green')
graph2, = ax.plot([], [], color = 'green')
dot1, = ax.plot([], [], 'o', color='red', markersize = 5)

dot2, = ax.plot([], [], 'o', color='green', markersize = 5)
def oj(i):

    graph1.set_data([X[0],X[i]],[Y[0],Y[i]]) ## for the parent this works as I want it grow and shrink without any trace

    graph2.set_data(X1[:i+1],Y1[:i+1]) # for the branch I can't use the same code as that for graph1 as I want it to be attached at (8,8) and grow from or shrink to that poin
    dot1.set_data(X[i],Y[i]) # this shows how the tip of the parent filament animates

    dot2.set_data(X1[i],Y1[i]) #this shows the tip of the branch which I face a difficulty in animating as it traces back instead of showing a shrink 
anim = animation.FuncAnimation(fig, oj, frames=len(X), interval=1000, repeat = False)
plt.show()

1 Ответ

0 голосов
/ 30 апреля 2019

Я бы фактически использовал ту же стратегию, которую вы использовали для основной ветви, но ввел параметр, указывающий, на каком этапе должно происходить ветвление, и работал бы оттуда:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

X = [1,2,3,4,5,6,7,8,9,10,11,12,11,10,11,12,13,14,15,14,13,12,13] #parent x coord
Y = [1,2,3,4,5,6,7,8,9,10,11,12,11,10,11,12,13,14,15,14,13,12,13] #parent y coord

X1 = [7,6,5,4,4,4,5,6,7,8,7,6,5,4,3] #branch x coord
Y1 = [9,10,11,12,12,12,11,10,9,8,9,10,11,12,13] #branch y coord

fig, ax = plt.subplots(1,1)
ax.set_xlim([0, 20])
ax.set_ylim([-1.1, 20])

graph1, = ax.plot([], [], color = 'green')
graph2, = ax.plot([], [], color = 'green')
dot1, = ax.plot([], [], 'o', color='red', markersize = 5)
dot2, = ax.plot([], [], 'o', color='green', markersize = 5)
ttl = ax.set_title('')

def oj(i, branch_point):
    ttl.set_text('i={:d}'.format(i))
    graph1.set_data([X[0],X[i]],[Y[0],Y[i]]) ## for the parent this works as I want it grow and shrink without any trace
    dot1.set_data(X[i],Y[i]) # this shows how the tip of the parent filament animates
    if i>branch_point:
        graph2.set_data([X[branch_point],X1[i-branch_point-1]],[Y[branch_point],Y1[i-branch_point-1]]) # for the branch I can't use the same code as that for graph1 as I want it to be attached at (8,8) and grow from or shrink to that poin
        dot2.set_data(X1[i-branch_point-1],Y1[i-branch_point-1]) #this shows the tip of the branch which I face a difficulty in animating as it traces back instead of showing a shrink 
anim = animation.FuncAnimation(fig, oj, frames=len(X), interval=1000, repeat=False, fargs=(7,))
plt.show()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...