That is pretty immpressive!
I just had to change TBGL_SetPrimitiveQuality to 8, because my GPU was overhelmed by the amount of geometry.
Petr
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.
TBGL - DNA.jpg
and the script for it is here:
TBGL_DNA.tbasic
code updated.
Last edited by rjp74; 19-09-2012 at 19:24. Reason: error in code
That is pretty immpressive!
I just had to change TBGL_SetPrimitiveQuality to 8, because my GPU was overhelmed by the amount of geometry.
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
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:
to these:Integer cycles = 3 Integer small = 4 Integer large = 10 Integer iRods = 12
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:Integer cycles = 2 Integer small = 4 Integer large = 8 Integer iRods = 8
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
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
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
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.
DNA - cluster.jpg
the revised code:
TBGL_DNA_2.tbasic
Hi,
you may prefer this vertically aligned DNA spiral for your sample code - should you wish to do that. It has more visual impact.
TBGL_DNA_3.tbasic
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:
DNA - NewCluster.jpg
The code was reworked using the new algorithm and the results look like this:
DNA - 5.jpg
The revised code:
TBGL_DNA_5.tbasic
Bookmarks