|
|
|
|
![]() ![]() |
Mar 12 2008, 07:05 PM
Post
#1
|
|
|
Newbie [Level 1] ![]() Group: Members Posts: 15 Joined: 12-March 08 Member No.: 59,224 |
Okay, I have created, looked, and generally studied simple PHP calculators. However, I can not seem to find any tutorials on how to create a genetic calculator. One that calculates genetic percentages similar to that of Punnette Squares. I have seen plenty of websites that have these types of calculators, but I have yet to see any websites offer tutorials on how to create these types of calculators. So.. does anyone know of any tutorials I can find or sites that might have the tutorial I am looking for? Maybe even a tutorial here?
Reason for asking: I am creating a website, simulation game, and one of the aspects of the game is calculating the colors of the offspring from a certain pair. Any help on the subject is greatly appreciated. Thanks in advance, TCD |
|
|
|
Mar 12 2008, 07:27 PM
Post
#2
|
|
|
Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 974 Joined: 25-September 05 From: The dungeon deep below the foundation of trap17 Member No.: 12,251 |
Well its been a long time since I've seen or used punnette squares, and I'm sure they are much more complicated than the simple 4 block ones that I learned, but I'll do a basic one for you.
So if I recall correctly you have dominant and recessive traits, such as dark hair or blond hair. And lets say dark is dominant. So we'll have this: DD+bb= 100% to be Db Db+Db= 25% to be DD 50% to be Db 25% to be bb Db+bb= 50% to be Db 50% to be bb Correct? (If I'm wrong tell me because it's been a while) Anyway I would suggest an object oriented approach if you are going to be having different plants (or animals) with different traits. So first make the class life. CODE class life{ function __construct($dom,$res){//constructors are new in php 5 so don't do this step if you are working with an older version $this->dom=$dom; $this->res=$res; } //Returns a life object when mating this object and the input object function mate($life){ switch(rand(0,3)){ case 0: return new life($this->dom,$life->dom); case 1: return new life($this->res,$life->dom); case 2: return new life($this->dom,$life->res); case 3: return new life($this->res,$life->res); } } } And that should do it. This code was not tested yet. Post back with any errors you find. This post has been edited by alex7h3pr0gr4m3r: Mar 12 2008, 07:27 PM |
|
|
|
Mar 13 2008, 04:37 AM
Post
#3
|
|
|
Newbie [Level 1] ![]() Group: Members Posts: 15 Joined: 12-March 08 Member No.: 59,224 |
Yes. Exactly on the example about Punnette Squares. =] Also, I tested the code below and it works just fine. Now I just need to add a form to it so people can choose the color or genetics to generate the outcome. Correct?
My hosting company just recently upgraded to PHP 5. So.. I am still working on understanding certain aspects of PHP 5. Since I have been mainly studying PHP 4 and testing PHP 4. Thank you again and the code was very helpful. ^^ TCD Well its been a long time since I've seen or used punnette squares, and I'm sure they are much more complicated than the simple 4 block ones that I learned, but I'll do a basic one for you. So if I recall correctly you have dominant and recessive traits, such as dark hair or blond hair. And lets say dark is dominant. So we'll have this: DD+bb= 100% to be Db Db+Db= 25% to be DD 50% to be Db 25% to be bb Db+bb= 50% to be Db 50% to be bb Correct? (If I'm wrong tell me because it's been a while) Anyway I would suggest an object oriented approach if you are going to be having different plants (or animals) with different traits. So first make the class life. CODE class life{ function __construct($dom,$res){//constructors are new in php 5 so don't do this step if you are working with an older version $this->dom=$dom; $this->res=$res; } //Returns a life object when mating this object and the input object function mate($life){ switch(rand(0,3)){ case 0: return new life($this->dom,$life->dom); case 1: return new life($this->res,$life->dom); case 2: return new life($this->dom,$life->res); case 3: return new life($this->res,$life->res); } } } And that should do it. This code was not tested yet. Post back with any errors you find. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 24th July 2008 - 12:03 PM |