####################################################################################
#nodebeam, node/beam engine test implementation
####################################################################################
#notes:
#       test program , goal:
#               -not to fuck around with the stable test function in nworld.py
#               -simulate real program using node/beams
#

#dependency
####################################################################################
import pyg, nworld
from nworld import *


world = nworld(0,0, pyg.width, pyg.height-10)           # create world  (start coords, end coords)

### fun toggles here:
demonodes(world)                                        # create some free nodes

demoshape(world)                                        # create some node/beam shape

demosquare(world)                                       # create a square

#pin(world.nodeLst[9])                                   # nail a node down

#demopush(world)                                         # push it all around for demo

##d=2.5                                                   # demo rope pull/push speed
##world.beamLst[25].rigidity = 0.62                       # demo rope beam rigidity
###

## main 
while pyg.main():
        pyg.line(world.box[0],world.box[3],world.box[2],world.box[3])   # draw ground line    
        pyg.line(pointA.x, pointA.y, pointB.x, pointB.y)
        pyg.line(pointC.x, pointC.y, pointD.x, pointD.y)
### fun toggles heres:
        #impulse(world.nodeLst[20], vector(0,-40))                       # helium test
        #push(world.nodeLst[10], vector(2.0,-61.8))                     # test push specfic node
        
##        if world.beamLst[25].restlenght > 690:                          # change beam lenght in realtime
##                world.beamLst[25].restlenght = 690.0                    # for rope
##                d = -d
##        if world.beamLst[25].restlenght < 10:
##                world.beamLst[25].restlenght = 10.0
##                d = -d
##        world.beamLst[25].restlenght += d
###

        update(world)                                                   # one physics tick
                    
        for i in world.nodeLst:                                         # render nodes
                direction = Vsub(i.op, i.p)                             # quick angle testing
                i.a = VtoRadian(direction)
                c = VfromRadian(6.8)
                pyg.circle(i.p.x, i.p.y)                                # draw node
                pyg.line(i.p.x, i.p.y, i.op.x, i.op.y)                  # draw velocity
        for i in world.beamLst:                                         # render beams
                colorratio = 8500
                cf = int(i.pushforce * colorratio)      # make some force color
                
                if cf > 127:
                        cf = 127
                elif cf < -127:
                        cf = -127                                       # testing force color
                color = 127-cf, 127, cf+127
                pyg.line(i.nA.p.x,i.nA.p.y, i.nB.p.x,i.nB.p.y, color)
        
        
