Advertisement
Guest User

Grow graph and DNA mixer

a guest
Dec 9th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.81 KB | None | 0 0
  1. #! ruby -Ks
  2. require_relative 'dxruby'
  3.  
  4. ###遺伝子成長曲線:父母遺伝再現プログラム
  5. ###作者 みれいゆー
  6.  
  7. #定義
  8. time = 0
  9. totalgrow = 0.0
  10. onetimedo = 0
  11. upordown = 0
  12. font = Font.new( 20,'HGP行書体')
  13.  
  14. #記憶保存するべきものは$最初は二人
  15. $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     ]]
  16. age = 0
  17. chara = 0
  18. xpos = 0
  19. ypos = 0
  20. twice = 0
  21. background = Image.load('background.png') #画像はなんでもいい
  22. buttonchip = Image.new(40,40,[255,255,255,255])
  23.  
  24. #ループ開始
  25. Window.loop do
  26.  
  27. ##常時
  28.  xpos = Input.mousePosX
  29.  ypos = Input.mousePosY
  30.  
  31.  Window.draw(0,0,background)
  32.  
  33.  Window.draw(10,10,buttonchip)
  34.  Window.draw(60,10,buttonchip)
  35.  Window.draw(110,10,buttonchip)
  36.  Window.draw(160,10,buttonchip)
  37.  Window.draw(10,60,buttonchip)
  38.  Window.draw(60,60,buttonchip)
  39.  Window.draw(110,60,buttonchip)
  40.  Window.draw(160,60,buttonchip)
  41.  
  42.  Window.draw_font(10,10, "自↑",font,hash={color: [0,0,0]})
  43.  Window.draw_font(60,10, "頂↑",font,hash={color: [0,0,0]})
  44.  Window.draw_font(110,10, "幅↑",font,hash={color: [0,0,0]})
  45.  Window.draw_font(160,10,"寿↑",font,hash={color: [0,0,0]})
  46.  Window.draw_font(10,60, "自↓",font,hash={color: [0,0,0]})
  47.  Window.draw_font(60,60, "頂↓",font,hash={color: [0,0,0]})
  48.  Window.draw_font(110,60, "幅↓",font,hash={color: [0,0,0]})
  49.  Window.draw_font(160,60,"寿↓",font,hash={color: [0,0,0]})
  50.  
  51. ##成長曲線数値変更部
  52.  if Input.mousePush?(M_LBUTTON)
  53.   case ypos
  54.    when 10..50
  55.    case  xpos
  56.     when 10..50   then $human[chara][0] += 5
  57.     when 60..100   then $human[chara][2] += 5
  58.     when 110..150   then $human[chara][3] += 5
  59.     when 160..200 then $human[chara][4] += 5
  60.    end
  61.    when 60..100
  62.    case  xpos
  63.     when 10..50   then $human[chara][0] -= 5
  64.     when 60..100  then $human[chara][2] -= 5
  65.     when 110..150 then $human[chara][3] -= 5
  66.     when 160..200 then $human[chara][4] -= 5
  67.    end
  68.   end
  69.  end
  70. #コントローラー
  71.  if Input.keyPush?( K_UP ) and age < 60
  72.   age += 1
  73.   elsif Input.keyPush?( K_DOWN ) and age > 0
  74.   age -= 1
  75.   elsif  Input.keyPush?( K_RIGHT ) and chara < $human.length - 1
  76.   chara += 1
  77.   elsif  Input.keyPush?( K_LEFT ) and chara > 0
  78.   chara -= 1
  79.  end
  80.  
  81. #数値修正
  82.  $human[chara][0] = 275 if $human[chara][0] > 275
  83.  $human[chara][2] = 40 if $human[chara][2] > 40
  84.  $human[chara][3] = 40 if $human[chara][3] > 40
  85.  $human[chara][4] = 60 if $human[chara][4] > 60
  86.  
  87.  $human[chara][0] = 25 if $human[chara][0] < 25
  88.  $human[chara][2] = 5 if $human[chara][2] < 5
  89.  $human[chara][3] = 5 if $human[chara][3] < 5
  90.  $human[chara][4] = 20 if $human[chara][4] < 20
  91.  $human[chara][1] , $human[chara][5]  = 300 - $human[chara][0], $human[chara][4] + 5
  92. ###成長曲線再現部
  93. #全グラフ描写か、一人描写か
  94. unless Input.keyDown?( K_SPACE )
  95. ##成長曲線生成(個別)
  96.  
  97. #値の定義
  98.  totalgrow = 0.0
  99.  activeage = $human[chara][4].to_f
  100.  peakage = $human[chara][2].to_f
  101.  peakrange = $human[chara][3].to_f
  102.  naturalpower = $human[chara][0].to_f
  103.  trainpower = $human[chara][1].to_f
  104.  onetimedo = 0
  105.  
  106. #自然FOR文
  107.  totalpower = naturalpower
  108.  for time in 0..60
  109.   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
  110.   peakgrow = ((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * peakage))
  111.   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
  112.   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
  113.   grow = 0.0 if grow <= 0.0
  114.   totalgrow += grow
  115.   Window.draw_font(10 + time * 10 , (-1 * grow* 100) + 440 , "●" , font,hash={color: [255,66,66]})
  116.  end
  117.  
  118. #訓練FOR文
  119.  totalpower = trainpower
  120.  for time in 0..60
  121.   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
  122.   peakgrow = ((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * peakage))
  123.   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
  124.   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
  125.   grow = 0.0 if grow <= 0.0
  126.   totalgrow += grow
  127.   Window.draw_font(10 + time * 10 , (-1 * grow* 100) + 440 , "●" , font,hash={color: [66,255,255]})
  128.  end
  129.  
  130. #総合FOR文
  131.  totalpower = naturalpower + trainpower
  132.  for time in 0..60
  133.   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
  134.   peakgrow = ((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * peakage))
  135.   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
  136.   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
  137.   grow = 0.0 if grow <= 0.0
  138.   totalgrow += grow
  139.   Window.draw_font(10 + time * 10 , (-1 * grow* 100) + 440 , "●" , font,hash={color: [255,255,66]})
  140.   Window.draw_font(10 + time * 10 , (-1 * grow* 100) + 420 , "↓" , font) if time == age
  141.   if age == time and onetimedo == 0
  142.    Window.draw_font(260,0 ,age.to_s + "歳時" + grow.to_s,font)
  143.    onetimedo = 1
  144.   end
  145.  end
  146.  Window.draw_font(260, 20 , "currenthuman_total:" + totalgrow.to_s , font)
  147.  Window.draw_font(0, 110 , $human[chara].to_s , font)
  148.  else
  149.  
  150. ##成長曲線生成(全員)
  151.  
  152. #マーク定義
  153.  num, ip = 0, 0
  154.  for ip in 0..$human.length - 1
  155.   num , collor= "●"  , {color: [255,255,66]} if ip == 0
  156.   num , collor= "■"  , {color: [255,66,66]} if ip == 1
  157.   num , collor= "▲"  , {color: [66,255,66]} if ip == 2
  158.   num , collor= "★"  , {color: [66,255,255]} if ip == 3
  159.   num , collor= "◆"  , {color: [66,66,255]} if ip == 4
  160.   num , collor= "▼"  , {color: [255,66,255]} if ip == 5
  161.   num , collor= "♪"  , {color: [255,255,255]} if ip == 6
  162.   num , collor= "♯"  , {color: [255,255,255]} if ip == 7
  163.   num , collor= "♭"  , {color: [255,255,255]} if ip == 8
  164.   num , collor= "〆"  , {color: [255,255,255]} if ip == 9
  165.   num , collor= ip.to_s  , {color: [255,255,255]} if ip > 9
  166.  
  167. #値の定義
  168.   totalgrow = 0.0
  169.   activeage = $human[ip][4].to_f
  170.   peakage = $human[ip][2].to_f
  171.   peakrange = $human[ip][3].to_f
  172.   naturalpower = $human[ip][0].to_f
  173.   trainpower = $human[ip][1].to_f
  174.   totalpower = naturalpower
  175.  
  176. #一括して総合FOR文
  177.   totalpower = naturalpower + trainpower
  178.   for time in 0..60
  179.    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
  180.    peakgrow = ((totalpower / peakage ) / peakrange) / (1.0 + peakage * Math.exp(-1.0 * (Math.sin(peakrange * Math::PI/ 180.0)) * peakage))
  181.    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
  182.    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
  183.    grow = 0.0 if grow <= 0.0
  184.    totalgrow += grow
  185.    Window.draw_font(10 + time * 10 , (-1 * grow* 100) + 440 , num , font,hash=collor)
  186.   end
  187.   Window.draw_font(260, ip * 20 , ip.to_s + "番:" + num , font)
  188.  end
  189.  num ,ip = 0,0
  190. end
  191. #FOR終結
  192.  totalgrow = 0
  193.  
  194. ##父母遺伝部
  195.  Window.draw_font(260, 60 , "子が生まれた。", font) if twice == 2
  196.  Window.draw_font(260, 40 , "母が決定された。父を指定せよ。", font) if twice == 1
  197.  if Input.keyPush?( K_E )
  198.   if twice == 2 then twice = 0
  199.    elsif twice == 1
  200.     twice,$father = 2,$human[chara]
  201. #比率決定
  202.     titih = rand(0.2..0.8)
  203.     hahah = 1.0 - titih
  204.     baby = 0
  205. #子をpush
  206.     $human.push([0,       0,       0,       0,         0 ,    0     ])
  207.     baby = $human.length - 1
  208. #子を定義
  209.     $human[baby][0]   = (($father[0] * titih + $mother[0] * hahah)* rand(0.8..1.2)).round
  210.     $human[baby][2]   = (($father[2] * titih + $mother[2] * hahah)* rand(0.8..1.2)).round
  211.     $human[baby][3]   = (($father[3] * titih + $mother[3] * hahah)* rand(0.8..1.2)).round
  212.     $human[baby][4]   = (($father[4] * titih + $mother[4] * hahah)* rand(0.8..1.2)).round
  213. #規制(制限)
  214.     $human[baby][0] = 275 if $human[baby][0] > 275
  215.     $human[baby][2] = 40 if $human[baby][2] > 40
  216.     $human[baby][3] = 40 if $human[baby][3] > 40
  217.     $human[baby][4] = 60 if $human[baby][4] > 60
  218.     $human[baby][0] = 25 if $human[baby][0] < 25
  219.     $human[baby][2] = 5 if $human[baby][2] < 5
  220.     $human[baby][3] = 5 if $human[baby][3] < 5
  221.     $human[baby][4] = 20 if $human[baby][4] < 20
  222.     $human[baby][1] , $human[baby][5]  = 300 - $human[baby][0], $human[baby][4] + 5
  223.    elsif twice == 0 then twice,$mother = 1,$human[chara]
  224.   end
  225.  end
  226. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement