/
taal_and_tukuda.py
160 lines (142 loc) · 5.15 KB
/
taal_and_tukuda.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import numpy as np
import matplotlib.pyplot as plt
def createCircle(ax):
all_thetas = np.arange(0,2*np.pi+2*np.pi/400,2*np.pi/400)
X = [np.cos(theta) for theta in all_thetas]
Y = [np.sin(theta) for theta in all_thetas]
ax.axvline(0,color='gray',alpha=0.3)
ax.axhline(0,color='gray',alpha=0.3)
ax.plot(X,Y,'gray',lw=1)
def createTaal(name, ax,taaldict,num_avartans=1):
createCircle(ax)
distance = 2*np.pi/(taaldict[name]['matra'] )
matras = np.arange(num_avartans*2*np.pi,0-distance,-distance)
m_count = 1
for m in matras:
if m_count == taaldict[name]['sam']:
ax.plot(np.cos(m),np.sin(m),marker='o',markerfacecolor='none',color='k',ms=10)
if m_count in taaldict[name]['taali']:
ax.plot(np.cos(m),np.sin(m),'ko')
if m_count in taaldict[name]['khaali']:
ax.plot(np.cos(m),np.sin(m),'kx',ms=10)#color='#67db45'
else:
ax.plot(np.cos(m),np.sin(m),'k.')
m_count +=1
def newplot():
f, ax = plt.subplots(1,1,figsize=(3,3))
ax.set_xticks([])
ax.set_yticks([])
return ax
def prettystring(total, i):
if i +1 <10:
return("0"+str(i+1))
else:
return(str(i+1))
def executeAvartan(bol, taaldict, num_avartans):
name = bol.guessTaal()
print(name)
distance = 2*np.pi/(taaldict[name]['matra'] )
matras = np.arange(num_avartans*2*np.pi,0-distance,-distance)
aksharlist = bol.Akshar
for i,(m,a) in enumerate(zip(matras, aksharlist)):
plt.close()
ax = newplot()
createTaal(name, ax, taaldict,num_avartans=num_avartans)
ax.plot([0.5*np.cos(m),np.cos(m)],[0.5*np.sin(m),np.sin(m)],'gray')
if a != 'S':
ax.plot(np.cos(m),np.sin(m),'bo',ms=10)
ax.annotate(a,xy=(0,0),xytext=(0,0))
else:
ax.annotate(a,xy=(0,0),xytext=(0,0))
ax.axis('off')
ax.set_title(name + ' (' +prettystring(len(aksharlist),i)+'/'+ str(len(aksharlist)) +')')
plt.savefig('../experiments/animation/taal/' + name.replace(' ','-') + '-' + prettystring(len(aksharlist),i) +'.png')
class bolParser:
def __init__(self, bol):
self.bol = bol
self.Avartan = list()
self.Vibhaag = list()
self.Akshar = list()
self.num_avartans = 0
self.taaldict = {'teen taal':{'matra':16,
'taali':[5,13],
'khaali':[9],
'sam':1},
'jhap taal':{'matra':10,
'taali':[6],
'khaali':[3,8],
'sam':1},
'roopak taal':{'matra':7,
'taali':[6],
'khaali':[1],
'sam':4},
'keherwa taal':{'matra':8,
'taali':[],
'khaali':[5],
'sam':1},
'ek taal':{'matra':12,
'taali':[5,8],
'khaali':[3,7],
'sam':1}}
self.__getAvartan()
self.__getVibhaag()
self.__getAkshar()
self.num_avartans = len(self.Avartan)
def __getAvartan(self):
self.Avartan = self.bol.split('||')[:-1]
def __getVibhaag(self):
self.Vibhaag = [av.split('|') for av in self.Avartan]
def __getAkshar(self):
GroupedAkshars = [[v.split(' ') for v in V] for V in self.Vibhaag]
for av in GroupedAkshars:
for v in av:
for a in v:
self.Akshar.append(a)
def guessTaal(self):
matra_per_avartan = int(float(len(self.Akshar))/float(len(self.Avartan)))
print(matra_per_avartan)
for taal in self.taaldict.keys():
if matra_per_avartan == self.taaldict[taal]['matra']:
return(taal)
bol = \
"dha S na dha|" \
"ti ta dhi ki|" \
"ta na ghe na|" \
"na ghe na dha||" \
"ti ta dhi ki|" \
"ta na ghe na|" \
"taa S na taa|" \
"ti ta ti ki||" \
"ta na ghe na|" \
"na ghe na dha|" \
"ti ta dhi ki|" \
"ta na ghe na||" \
"dha S na dha|" \
"ti ta dhi ki|" \
"ta na ghe na|" \
"na ghe na dha||" \
"ti ta dhi ki|" \
"ta na ghe na|" \
"dha S na dha|" \
"ti ta dha S||" \
"S ta ki ta|" \
"dha S S ta|" \
"ki ta dha S|" \
"S ta ki ta||"
# bol = \
# "dhi kita dhin|"\
# "ta dha dha din||"\
# "ta dhin na|"\
# "S kata dha S||"\
# "ti kita tin|"\
# "ta taa taa tin||"\
# "ta tin na|"\
# "S kata dha S||"
#bol = u"धा धीं धीं धा|धा धीं धीं धा|धा तिं तिं ता|ता धीं धीं धा||"
matras = bolParser(bol)
plt.close()
executeAvartan(matras,
matras.taaldict,
matras.num_avartans)