def show_color_picture():
a=ita.array.make3d(50, 50, 3)
for y in range(0, 50):
for x in range(0, 50):
#a[y][x]にRGB値からなる大きさ3の配列(要素は0から1までの実数)を入れる
(1)
return a
ita.plot.image_show(show_color_picture())
たとえば,(1)のところに
a[y][x] = [x / 49, 1 - y / 49, 1]
と入れると,
def show_color_picture(t):
a=ita.array.make3d(50, 50, 3)
for y in range(0, 50):
for x in range(0, 50):
#a[y][x]にRGB値からなる大きさ3の配列(要素は0から1までの実数)を入れる
a[y][x] = [x / 49, 1 - y / 49, t / 10]
return a
これを使って,10枚の静止画を作成して1つの配列に入れる関数を作成して,表示させてみる.
def show_animation():
image = ita.array.make1d(10)
for t in range(0, 10):
image[t] = show_color_picture(t)
return image
ita.plot.animation_show(show_animation())
すると,以下のように時間ごとに色が変わっていくアニメーションになる.
import randomをした上で,random.randrange(0, n)で0以上n-1以下の整数が返る.
IN [1]: random.randrange(3) OUT[1]: 1 IN [2]: random.randrange(3) OUT[2]: 0小数の乱数は random.random() で0.0以上1.0以下の一様乱数が返る.
IN [1]: random.random() OUT[1]: 0.3163153252111951 IN [2]: random.random() OUT[2]: 0.9910121225838986
IN [1]: int(2.9) OUT[1]: 2 IN [2]: int(2) OUT[2]: 2 IN [3]: int(-2.9) OUT[3]: -2四捨五入ではないので,注意が必要.