Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! ruby -Ks
- require_relative 'dxruby'
- ###遺伝子成長曲線:父母遺伝再現プログラム
- ###作者 みれいゆー
- #定義
- time = 0
- totalgrow = 0.0
- onetimedo = 0
- upordown = 0
- font = Font.new( 20,'HGP行書体')
- #記憶保存するべきものは$最初は二人
- $human = [[rand(25..275), 0, rand(5..40), rand(5..40), rand(20..60) , 0 ],[rand(25..275), 0, rand(5..40), rand(5..40), rand(20..60) , 0 ]]
- age = 0
- chara = 0
- xpos = 0
- ypos = 0
- twice = 0
- background = Image.load('background.png') #画像はなんでもいい
- buttonchip = Image.new(40,40,[255,255,255,255])
- #ループ開始
- Window.loop do
- ##常時
- xpos = Input.mousePosX
- ypos = Input.mousePosY
- Window.draw(0,0,background)
- Window.draw(10,10,buttonchip)
- Window.draw(60,10,buttonchip)
- Window.draw(110,10,buttonchip)
- Window.draw(160,10,buttonchip)
- Window.draw(10,60,buttonchip)
- Window.draw(60,60,buttonchip)
- Window.draw(110,60,buttonchip)
- Window.draw(160,60,buttonchip)
- Window.draw_font(10,10, "自↑",font,hash={color: [0,0,0]})
- Window.draw_font(60,10, "頂↑",font,hash={color: [0,0,0]})
- Window.draw_font(110,10, "幅↑",font,hash={color: [0,0,0]})
- Window.draw_font(160,10,"寿↑",font,hash={color: [0,0,0]})
- Window.draw_font(10,60, "自↓",font,hash={color: [0,0,0]})
- Window.draw_font(60,60, "頂↓",font,hash={color: [0,0,0]})
- Window.draw_font(110,60, "幅↓",font,hash={color: [0,0,0]})
- Window.draw_font(160,60,"寿↓",font,hash={color: [0,0,0]})
- ##成長曲線数値変更部
- if Input.mousePush?(M_LBUTTON)
- case ypos
- when 10..50
- case xpos
- when 10..50 then $human[chara][0] += 5
- when 60..100 then $human[chara][2] += 5
- when 110..150 then $human[chara][3] += 5
- when 160..200 then $human[chara][4] += 5
- end
- when 60..100
- case xpos
- when 10..50 then $human[chara][0] -= 5
- when 60..100 then $human[chara][2] -= 5
- when 110..150 then $human[chara][3] -= 5
- when 160..200 then $human[chara][4] -= 5
- end
- end
- end
- #コントローラー
- if Input.keyPush?( K_UP ) and age < 60
- age += 1
- elsif Input.keyPush?( K_DOWN ) and age > 0
- age -= 1
- elsif Input.keyPush?( K_RIGHT ) and chara < $human.length - 1
- chara += 1
- elsif Input.keyPush?( K_LEFT ) and chara > 0
- chara -= 1
- end
- #数値修正
- $human[chara][0] = 275 if $human[chara][0] > 275
- $human[chara][2] = 40 if $human[chara][2] > 40
- $human[chara][3] = 40 if $human[chara][3] > 40
- $human[chara][4] = 60 if $human[chara][4] > 60
- $human[chara][0] = 25 if $human[chara][0] < 25
- $human[chara][2] = 5 if $human[chara][2] < 5
- $human[chara][3] = 5 if $human[chara][3] < 5
- $human[chara][4] = 20 if $human[chara][4] < 20
- $human[chara][1] , $human[chara][5] = 300 - $human[chara][0], $human[chara][4] + 5
- ###成長曲線再現部
- #全グラフ描写か、一人描写か
- unless Input.keyDown?( K_SPACE )
- ##成長曲線生成(個別)
- #値の定義
- totalgrow = 0.0
- activeage = $human[chara][4].to_f
- peakage = $human[chara][2].to_f
- peakrange = $human[chara][3].to_f
- naturalpower = $human[chara][0].to_f
- trainpower = $human[chara][1].to_f
- onetimedo = 0
- #自然FOR文
- totalpower = naturalpower
- for time in 0..60
- grow = ((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * time)) if time <= peakage and time <= activeage
- peakgrow = ((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * peakage))
- grow = peakgrow - (((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * (time - peakage )))) / 2.0 if time > peakage and time <= activeage
- grow = peakgrow - ((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * (time - peakage ))) / (2.0 * (activeage / time) ** 4.0) if time > activeage
- grow = 0.0 if grow <= 0.0
- totalgrow += grow
- Window.draw_font(10 + time * 10 , (-1 * grow* 100) + 440 , "●" , font,hash={color: [255,66,66]})
- end
- #訓練FOR文
- totalpower = trainpower
- for time in 0..60
- grow = ((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * time)) if time <= peakage and time <= activeage
- peakgrow = ((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * peakage))
- grow = peakgrow - (((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * (time - peakage )))) / 2.0 if time > peakage and time <= activeage
- grow = peakgrow - ((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * (time - peakage ))) / (2.0 * (activeage / time) ** 4.0) if time > activeage
- grow = 0.0 if grow <= 0.0
- totalgrow += grow
- Window.draw_font(10 + time * 10 , (-1 * grow* 100) + 440 , "●" , font,hash={color: [66,255,255]})
- end
- #総合FOR文
- totalpower = naturalpower + trainpower
- for time in 0..60
- grow = ((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * time)) if time <= peakage and time <= activeage
- peakgrow = ((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * peakage))
- grow = peakgrow - (((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * (time - peakage )))) / 2.0 if time > peakage and time <= activeage
- grow = peakgrow - ((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * (time - peakage ))) / (2.0 * (activeage / time) ** 4.0) if time > activeage
- grow = 0.0 if grow <= 0.0
- totalgrow += grow
- Window.draw_font(10 + time * 10 , (-1 * grow* 100) + 440 , "●" , font,hash={color: [255,255,66]})
- Window.draw_font(10 + time * 10 , (-1 * grow* 100) + 420 , "↓" , font) if time == age
- if age == time and onetimedo == 0
- Window.draw_font(260,0 ,age.to_s + "歳時" + grow.to_s,font)
- onetimedo = 1
- end
- end
- Window.draw_font(260, 20 , "currenthuman_total:" + totalgrow.to_s , font)
- Window.draw_font(0, 110 , $human[chara].to_s , font)
- else
- ##成長曲線生成(全員)
- #マーク定義
- num, ip = 0, 0
- for ip in 0..$human.length - 1
- num , collor= "●" , {color: [255,255,66]} if ip == 0
- num , collor= "■" , {color: [255,66,66]} if ip == 1
- num , collor= "▲" , {color: [66,255,66]} if ip == 2
- num , collor= "★" , {color: [66,255,255]} if ip == 3
- num , collor= "◆" , {color: [66,66,255]} if ip == 4
- num , collor= "▼" , {color: [255,66,255]} if ip == 5
- num , collor= "♪" , {color: [255,255,255]} if ip == 6
- num , collor= "♯" , {color: [255,255,255]} if ip == 7
- num , collor= "♭" , {color: [255,255,255]} if ip == 8
- num , collor= "〆" , {color: [255,255,255]} if ip == 9
- num , collor= ip.to_s , {color: [255,255,255]} if ip > 9
- #値の定義
- totalgrow = 0.0
- activeage = $human[ip][4].to_f
- peakage = $human[ip][2].to_f
- peakrange = $human[ip][3].to_f
- naturalpower = $human[ip][0].to_f
- trainpower = $human[ip][1].to_f
- totalpower = naturalpower
- #一括して総合FOR文
- totalpower = naturalpower + trainpower
- for time in 0..60
- grow = ((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * time)) if time <= peakage and time <= activeage
- peakgrow = ((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * peakage))
- grow = peakgrow - (((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * (time - peakage )))) / 2.0 if time > peakage and time <= activeage
- grow = peakgrow - ((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * (time - peakage ))) / (2.0 * (activeage / time) ** 4.0) if time > activeage
- grow = 0.0 if grow <= 0.0
- totalgrow += grow
- Window.draw_font(10 + time * 10 , (-1 * grow* 100) + 440 , num , font,hash=collor)
- end
- Window.draw_font(260, ip * 20 , ip.to_s + "番:" + num , font)
- end
- num ,ip = 0,0
- end
- #FOR終結
- totalgrow = 0
- ##父母遺伝部
- Window.draw_font(260, 60 , "子が生まれた。", font) if twice == 2
- Window.draw_font(260, 40 , "母が決定された。父を指定せよ。", font) if twice == 1
- if Input.keyPush?( K_E )
- if twice == 2 then twice = 0
- elsif twice == 1
- twice,$father = 2,$human[chara]
- #比率決定
- titih = rand(0.2..0.8)
- hahah = 1.0 - titih
- baby = 0
- #子をpush
- $human.push([0, 0, 0, 0, 0 , 0 ])
- baby = $human.length - 1
- #子を定義
- $human[baby][0] = (($father[0] * titih + $mother[0] * hahah)* rand(0.8..1.2)).round
- $human[baby][2] = (($father[2] * titih + $mother[2] * hahah)* rand(0.8..1.2)).round
- $human[baby][3] = (($father[3] * titih + $mother[3] * hahah)* rand(0.8..1.2)).round
- $human[baby][4] = (($father[4] * titih + $mother[4] * hahah)* rand(0.8..1.2)).round
- #規制(制限)
- $human[baby][0] = 275 if $human[baby][0] > 275
- $human[baby][2] = 40 if $human[baby][2] > 40
- $human[baby][3] = 40 if $human[baby][3] > 40
- $human[baby][4] = 60 if $human[baby][4] > 60
- $human[baby][0] = 25 if $human[baby][0] < 25
- $human[baby][2] = 5 if $human[baby][2] < 5
- $human[baby][3] = 5 if $human[baby][3] < 5
- $human[baby][4] = 20 if $human[baby][4] < 20
- $human[baby][1] , $human[baby][5] = 300 - $human[baby][0], $human[baby][4] + 5
- elsif twice == 0 then twice,$mother = 1,$human[chara]
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement