Results 1 to 8 of 8

Thread: Simple DNA Model

  1. #1

    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.
    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

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    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

  3. #3
    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
    

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    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

  5. #5

    DNA code with smaller geometry and window size

    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

  6. #6

    Vertically Aligned

    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

  7. #7
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404
    Very nice demo, thanks for sharing. Beautiful to look at for sure!

  8. #8

    Clustering problem solved

    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

Similar Threads

  1. Model repository
    By Michael Hartlef in forum Media
    Replies: 3
    Last Post: 13-10-2008, 16:18
  2. Lionheart008: model example
    By Lionheart008 in forum thinStudio
    Replies: 30
    Last Post: 06-10-2008, 15:20
  3. model viewer k9
    By kryton9 in forum TBGL Scripts and Projects
    Replies: 50
    Last Post: 18-05-2007, 20:48
  4. Preistoric model viewer
    By ErosOlmi in forum YouTube
    Replies: 2
    Last Post: 05-02-2007, 12:29

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •