- ( g940422 )
def ichimatsu()
a=make3d(50,50,3)
for y in 0..49
for x in 0..49
a[y][x]=[(x-y+1.0)%2.0,x%2.0,y%2.0]
end
end
show(a)
end
ichimatsu()
- ( g940533 )
def aaa(r,x,y)
if x< y
sqrt(x**2+y**2)/r-0.3
else
1
end
end
def img(r)
image = make2d(r,r)
for y in 0..r-1
for x in 0..r-1
image[y][x] = aaa(r,x,y)
end
end
image
end
show(img(100))
- ( g940433 )
def show_color_picture()
a=make3d(50,50,3)
for y in 0..49
for x in 0..49
a[y][x]=[x/49.0,1.0-y/49.0,1.0-(x+y)/98.0]
end
end
show(a)
end
show_color_picture()
- ( g940446 )
def dist(a,b,c,d)
sqrt((a-b)**2+(c-d)**2)
end
def show_color_picture(r)
a=make3d(r,r,3)
for y in 0..(r-1)
for x in 0..(r-1)
# 掲示板に提出されたプログラムを再現できませんでした
a[y][x]=[(cos(dist(r/2,x,r/2,y)/10)+3)/3,(cos(dist(r/2,x,r/2,y)/5)+3)/3,(sin(dist(r/2,x,r/2,y)/8)+3)/3]
end
end
show(a)
end
show_color_picture(100)
- ( g940421 )
def PCA(init, cond, time, p)
l = init.length()
field = makearray(time, l)
field[0] = init
for i in 1...time
for j in 0...l
bit = sum((-1..1).map{|n| field[i-1][(j+n)%l] << (1-n)})
field[i][j] = rand(0)< p ? (cond & 1<< bit) >> bit : 0
end
end
return field
end
def CA1dInit(length, place)
init = make1d(length)
for i in place
init[i%length] = 1
end
return init
end
def PCAFin(length, place, cond, time, p)
return PCA(CA1dInit(length, place), cond, time, p)
end
def gen1111task()
length = 900
place = [450]
cond = 90
time = 500
p = 0.9
return mergeColor(Array.new(C) {PCAFin(length, place, cond, time, p)})
end
show(gen1111task())
# C, mergeColorの定義が抜けている
- ( g940207 )
load("./make2d.rb")
def color_sphere(r,u,v,w)
image=make2d(2*r+1,2*r+1)
for x in 0..(2*r)
for y in 0..(2*r)
image[x][y]=[b(r,r-x,r-y)/u,b(r,r-x,r-y)/v,b(r,r-x,r-y)/w]
end
end
image
end
show(color_sphere(50,0.8,0.2,0.3))
- ( g940425 )
def len(x,y,a,b)
((a-x)**2+(b-y)**2)**0.5
end
def pict()
a=make3d(400,400,3)
for y in 0..399
for x in 0..399
r=len(x,y,40.0,0.0)/400.0;
g=len(x,y,400.0,200.0)/400.0;
b=len(x,y,40.0,400.0)/400.0;
rate=sin(len(x,y,200,200)*0.2)*0.3+0.7
a[x][y]=[(r**4)*rate,(g**4)*rate,(b**4)*rate]
end
end
show(a)
end
pict()
- ( g940073 )
def make_color_thunder(n)
image=make3d(n,n,3)
image[0][0.5*n]=[1,1,0]
image[0][0.3*n]=[1,0,0]
image[0][0.7*n]=[0,1,0]
for y in 1..(n-1)
for x in 0..(n-1)
if (image[y-1][x]==[1,1,0]||image[y-1][x]==[1,0,0]||image[y-1][x]==[0,1,0])
a=rand(51)
b=image[y-1][x]
if a==24
image[y][x-2]=b
image[y][x-1]=b
elsif a<=23
image[y][x-1]=b
elsif a==25
image[y][x]=b
elsif a>=27
image[y][x+1]=b
else
image[y][x+1]=b
image[y][x+2]=b
end
end
end
end
image
end
show(make_color_thunder(200))
def sun_eve(n)
image=make3d(n,n,3)
for x in 0..(n-1)
for y in 0..(n-1)
if sqrt((x-n/2)**2+(y-n/2)**2)< 0.05*n
image[y][x]=[1,0.7,0]
elsif y<0.55*n-0.1*n*sin(x*10.0/n)
image[y][x]=[sqrt(y*1.0/n)+0.15,sqrt(y/(3.0*n)),0]
end
end
end
image
end
show(sun_eve(200))
- ( g940444 )
def gradation_o(h)
image = make2d(h,h)
for y in 0..(h-1)
for x in 0..(h-1)
# 下の式の「^2」は「**2」と書きたかったのか?
image[y][x] = [sin(x^2+y^2-sin(x+y)),sin(x^2+y^2),sin(x^2+y^2)-cos(x+y)]
end
end
image
end
- ( g730386 )
def show_color_picture()
a=make3d(50,50,3)
for y in 0..49
for x in 0..49
a[y][x]=[1.0-x*(rand())/49.0,y*(rand())/49.0,1.0]
end
end
show(a)
end
show_color_picture()
- ( g940053 )
def d(x,y,r)
return sqrt((x-r)**2+(y-r)**2)
end
def b(r,x,y)
if d(x,y,r)<=r
[(r-d(x,y,r))/r,(r-d(x,y,r))/r,0]
else
[0,0,0]
end
end
def sphere(r)
image = make2d(2*r, 2*r)
for y in 0..(2*r -1)
for x in 0..(2*r -1)
image[y][x] = b(r,x,y)
end
end
image
end
show sphere(200)
- ( g940432 )
def distance(x,y,u,v)
sqrt((x-u)**2+(y-v)**2)
end
def dot2(r,x,y,t,u)
if distance(x,y,t,u)<=r
(r-distance(x,y,t,u))/r
else
0
end
end
def cross_sphere(r)
image=make2d(2*r+1,2*r+1)
for y in 0..(2*r)
for x in 0..(2*r)
image[y][x]=[dot2(r,x,y,r,r)+
dot2(r,x,y,0,0)+dot2(r,x,y,0,2*r)+
dot2(r,x,y,2*r,0)+dot2(r,x,y,2*r,2*r),
dot2(r,x,y,r,0)+dot2(r,x,y,r,2*r),
dot2(r,x,y,0,r)+dot2(r,x,y,2*r,r)]
end
end
image
end
- ( g940527 )
def gauss(x)
if 0<=x && x< 1
0
else
gauss(x-1)+1
end
end
def chouwa(n,l)
a=0
if n==0
0
else
for i in 1..n
a=a+l/i
end
a=gauss(a)
a
end
end
def card_tower(n,l)
image=make2d(n,chouwa(n,l-1)/2+l)
for y in 0..n-1
for x in (chouwa(y,l-1)/2)..(chouwa(y,l-1)/2+l-1)
image[y][x]=1
end
end
image
end
- ( g940443 )
def abs(x)
if x>=0
x
else
-x
end
end
def show_color_picture(r)
a=make3d(2*r,2*r,3)
for y in 0..2*r-1
for x in 0..2*r-1
a[y][x]=[1-sin(sin(sin(sin(sin(x**2+y**2))))),cos(cos(cos(cos(cos(x**2+y**2))))),abs(x-y)/(2*r-1)]
end
end
show(a)
end
- ( g940183 )
def show_color_picture()
a=make3d(50,50,3)
for y in 0..49
for x in 0..49
include Math
a[y][x]=[0.0,sin(PI*y/98.0),cos(PI*x/98.0)]
end
end
show(a)
end
- ( g940066 )
def show_color_picture()
a=make3d(100,100,3)
for y in 0..99
for x in 0..99
a[y][x]=[sqrt(((x-50.0)**2+(y-50.0)**2)/500.0),((x-y)%4)*(x-y)/400.0,((sin(x)+cos(y))/sqrt(2)).abs]
end
end
show(a)
end
- ( g940056 )
def show_color_picture()
a=make3d(100,100,3)
for y in 0..99
for x in 0..99
a[x][y]=[(x*y)/2500,sin(x)*cos(y),(x*y)/2500.0]
end
end
show(a)
end
- ( g940420 )
def yoshida(r)
image=make2d(r,r)
for y in 0..r/2-1
for x in 0..r/2-1
image[y][x]=[sin(2**(r-1-x)+2**(r-1-y))+cos(2**(r-1-x)+2**(r-1-y)),sin(4*(r-1-x)-4*(r-1-y))+
cos( (r-1-x)/3-(r-1-y)/3),sin(8*(r-1-x)+16*(r-1-y)) + cos( (r-1-x)/9-(r-1-y)/19)]
end
for x in r/2..r-1
image[y][x]=[sin(2**x+2**(r-1-y))+cos(2**x+2**(r-1-y)),sin(4*x-4*(r-1-y))+
cos(x/3-(r-1-y)/3),sin(8*x+16*(r-1-y))+cos(x/9-(r-1-y)/19)]
end
end
for y in r/2..r-1
for x in 0..r/2-1
image[y][x]=[sin(2**(r-1-x)+2**y+cos(2**(r-1-x)+2**y)),sin(4*(r-1-x)-4*y)+
cos( (r-1-x)/3-y/3),sin(8*(r-1-x)+16*y)+cos( (r-1-x)/9-y/19)]
end
for x in r/2..r-1
image[y][x]=[sin(2**x+2**y)+cos(2**x+2**y),sin(4*x-4*y)+
cos(x/3-y/3),sin(8*x+16*y)+cos(x/9-y/19)]
end
end
image
end
- ( g940055 )
def circle(x,y)
r=sqrt{(x**2)+(y**2)} # この行は構文ミス.正しくは
# r=sqrt((x**2)+(y**2))
r
end
def show_color_picture(r)
a=make3d(2*r,2*r,3)
for y in 0..2*r-1
for x in 0..2*r-1
# 穴を埋める.
#a[y][x]にRGB値からなる大きさ3の配列(要素は0から1までの実数)を入れる
if y-x>0
a[y][x]=[1-circle(x,y)/250,1-cos(x+y)*(2*r-1)/10,circle(x,y)]
else
a[y][x]=[circle(x,y)/250,cos(x+y)*(2*r-1)/10,circle(x,y)]
end
end
end
show(a)
end
- ( g940074 )
def ityou
a=make3d(100,100,3)
for y in 0..49
for x in 0..99
a[y][x]=[1-sqrt((x-50)**2+(y-50)**2)/127.5,(x+y)/198.0,sin(sin(sin(x+y)))]
end
end
for y in 50..99
for x in 0..49
a[y][x]=[sqrt(x**2+(y-100)**2)/71.0,(x+y)/198.0,sin(sin(sin(x+y)))]
end
end
for y in 50..99
for x in 50..99
a[y][x]=[sqrt((x-100)**2+(y-100)**2)/71.0,(x+y)/198.0,sin(sin(sin(x+y)))]
end
end
show(a)
end
- ( g940518 )
def show_color_picture()
a=make3d(100,100,3)
for y in 0..99
for x in 0..99
a[y][x]=[(x%2)*(1.0-x/100),((x-y)%4)*(x+y)/100.0,cos(y/10.0)**2]
end
end
show(a)
end
- ( g940532 )
def show_color_picture()
a=make3d(100,100,3)
for y in 0..99
for x in 0..99
if (x-50.0)**2+(y-50.0)**2<225
a[y][x]= [0,0,1.0]
else
if sqrt((x-50.0)**2)+sqrt((y-50.0)**2)*2<50.0
a[y][x]= [1.0,1.0,0.0]
else
if y <15 || y > 85
a[y][x] = [0,0,0]
else
a[y][x] = [0,1.0,0]
end
end
end
end
end
show(a)
end
- ( g940060 )
def absolute(x)
if x<=0
-x
else
x
end
end
def design(a,x,y)
b=make2d(a,a)
pi=3.14159265358979323846264338327950288
for j in 0..a-1
for i in 0..a-1
c=(absolute(sin(x*(pi)*(j+1)/a))/2+absolute(sin(y*(pi)*(i+1)/a))/2)
red=1.0*(j+1)/a
green=1-1.0*(j+1)/a
blue=1.0*(i+1)/a
b[i][j]=[c*red,c*green,c*blue]
end
end
b
end
show(design(200,10,10))
- ( g940440 )
a=make2d(100,100)
for i in 0..99
for j in 0..99
b=((i-50)**2+(j-50)**2)**0.5
a[i][j]=sin(0.1256*b*3+0.157)/2+0.5
end
end
c=make2d(100,100)
for i in 0..9
for j in 0..9
for k in 0..9
for l in 0..9
if (i+j)%2==0
c[10*i+k][10*j+l]=1
end
end
end
end
end
d=blur(blend(c,a))
for i in 0..99
for j in 0..99
d[i][j]=[d[i][j],c[i][j],a[i][j]]
end
end
#blur, blendは練習3.13で定義したものだが,定義が書かれていない
- ( g940065 )
include Math
def make(r)
a = Array.new(r)
for i in 0..(r-1)
a[i] = Array.new(r)
for j in 0..(r-1)
a[i][j] = Array.new(3)
a[i][j][0]=0
a[i][j][1]=0
a[i][j][2]=0
end
end
a
end
#背景
def maru(a,w,h,r,g,b,x,y)
if (y>0 and y<2*w and x>0 and x<2*w) then
a[y][x][0] = r
a[y][x][1] = g
a[y][x][2] = b
end
a
end
#点を打つ
def zukei2(w)
a = make(w*2)
for j in 0..3
s=-3.14/2
vs = 0.01
h=1
l= w-h+38-j*5
if j == 0 then
r=0
g=0
b=1
elsif j == 1 then
r=1
g=1
b=0
elsif j == 2 then
r=0
g=1
b=0
elsif j == 3 then
r=0
g=1
b=1
end
for i in 0..4000
x=w+l*cos(s)
y=w+l*sin(s)
s=s+vs
l=l*0.9995
s=s*1.0005
a=maru(a,w,h,r,g,b,x.to_i,y.to_i)
if i > 2000 then
l=l*0.9995
end
if i > 3000 then
l=l*0.9993
end
if i > 3500 then
l=l*0.999
end
end
end
a
end
show zukei2(100)