若干コード書き換え
クラス名変更
ProcessingのPython版「NodeBox」で色々してみたい(゚Д゚)p
乱数で作ったグラフィックを再現してみた
当たり前だけど、乱数で実行すると毎回違うグラフィックになる。
でも同じものを再現したいときもあるわけで(´・ω・`)
クラスはほとんど使ったことないけど、とりあえず書いてみた。
できあがり
説明とコード
NodeBoxで実行するとウインドウ左画面に画像が、右下に辞書(dict)が出力される。
「h_dic = {}」のままなら実行するごとに違う画像を表示。
再現するときは出力した辞書を「h_dic = {}」のところに代入すればオケイ(゚Д゚)v
size(300, 200) colormode(HSB) background(0.9, 1, 0.4) class Log_rundom_dic: def __init__(self, dic = {}): self.dic = dic self.is_dic = True if dic == {} else False def value(self, name, rand_num): if self.is_dic: self.dic[name] = rand_num return self.dic[name] else: return self.dic[name] def make_graphic(history_dic): rns = Log_rundom_dic(history_dic) for n in range(7): fill(rns.value("fill" + str(n), random(0.7, 0.9)), 0.5, 0.8) x = rns.value("x" + str(n), random(WIDTH)) y = rns.value("y" + str(n), random(HEIGHT)) diameter = rns.value("dia" + str(n), random(10, 60)) oval(x, y , diameter, diameter) print rns.dic h_dic = {} make_graphic(h_dic)
例えば、上記「h_dic = {}」の部分を以下のように変更すると、上のできあがりと同じ画像に。
h_dic = {'y1': 190, 'y0': 43, 'y3': 196, 'y2': 199, 'y5': 177, 'y4': 108, 'y6': 17, 'fill4': 0.89102628399563333, 'fill5': 0.80306664674561823, 'fill6': 0.87507521448109793, 'fill0': 0.80333457469877345, 'fill1': 0.80813673607354131, 'fill2': 0.82702255422971938, 'fill3': 0.72229231069026889, 'x2': 14, 'x3': 247, 'x0': 45, 'x1': 67, 'x6': 246, 'x4': 104, 'x5': 157, 'dia6': 11, 'dia4': 35, 'dia5': 20, 'dia2': 45, 'dia3': 25, 'dia0': 58, 'dia1': 21}
とりあえず再現できました(゚Д゚)