View Full Version : Simple DNA Model
Hi,
I wanted to get started with TBGL and had always wanted to create a nice DNA like picture so what better way to combine the two.
This is how it looks.
7945
and the script for it is here:
7947
code updated.
Petr Schreiber
19-09-2012, 17:15
That is pretty immpressive! :shock:
I just had to change TBGL_SetPrimitiveQuality to 8, because my GPU was overhelmed by the amount of geometry.
Petr
originally, I was running with TBGL_SetPrimitiveQuality set to 100 because I copied the value from an example. Eventually I reduced it to 16 because at 100 my machine did take about 5 seconds longer to compute the original geometry and I didn't want to wait. with value 16 I still need to wait about 2 seconds. I didn't take it lower as the spheres started to get distorted. On my machine the geometry as given takes 71,600KB memory which is not excessive.
For people who have low powered machines I suggest that you reduce these values:
Integer cycles = 3
Integer small = 4
Integer large = 10
Integer iRods = 12
to these:
Integer cycles = 2
Integer small = 4
Integer large = 8
Integer iRods = 8
which will reduce the overall dimensions of the DNA chain. And if the geometry is still too much find the two lines of code in the drawDNA() routine that look like this:
makeSphere(Offsetx,Sin(a1),Cos(a1), mOrange, 0.12, 36, 0.04, 0.08, 1)
and change the 6th parameter (here 36) to a smaller number such as 12. This is the number of smaller spheres that surround the parent sphere.
Also look for the same function in Sub makeRod() and reduce the number from 9 to 5.
This will substantially reduce the number of entities generated.
Reducing the numbers even lower will start to effect the overall look of the DNA spiral adversely.
I had a lot of technical troubles en-route which I was not able to identify. Weird things like adding a comment would cause the program to crash. Sin() and cos() stopped functioning at one point. All very weird. I started to wonder if I had non-printing characters in the script. However, it seems to be working now. I still have troubles with the random number generation which has a tendency to put spheres in the same spots in the clouds - zoom in to see this. I dumped a load of random numbers into ms excel and drew a probablity distribution graph to see what was going on. The curve has a couple of big spikes in it. I have no idea why this is incorrect. Either I need a better random number generator or I need to rewrite the cloud process in a very different way to better distribute the spheres around the parent sphere. For now I have cheated. This explains this code in the drnd() routine:
Dim r As Double
Integer j = Rnd(3,9)
For i = 0 To j ' spin them a Bit To break patterns - it needs it!!! Really!!
r = Rnd
Next i
ErosOlmi
20-09-2012, 00:22
wow, what a nice example.
Thanks for sharing with us.
Regarding randomization, please add a Randomize command somewhere at the beginning of the script.
Also check if RNDF function can help.
Ciao
Eros
Hi
I attach a slightly modified DNA code with smaller geometry and window size of 800x600.
You would be welcome to add it to your examples you ship with TB.
Thanks for the heads up about RNDF. I looked at RND and saw various examples but nothing about doubles and didn't search further, so rolled my own. I have now incorporated the RNDF function, and also added the Randomise function. the attached code is using it. However, I get the same issue. You will see what I mean by looking at the overlapping spheres and their positions in this picture. The spheres tend to congregate in approx the same sets of places. Much more structured than I would expect by random chance. I would like them to have a better distribution around the parent sphere without one being on top of another.
7948
the revised code:
7950
Hi,
you may prefer this vertically aligned DNA spiral for your sample code - should you wish to do that. It has more visual impact.
7951
Very nice demo, thanks for sharing. Beautiful to look at for sure!
Hi
I worked out how to distribute the cloud spheres using the random number generator without them overlapping. The cloud of spheres now looks like this:
7953
The code was reworked using the new algorithm and the results look like this:
7954
The revised code:
7955