wave.py :  » Game-2D-3D » Visual » visual-5.32_release » examples » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Game 2D 3D » Visual 
Visual » visual 5.32_release » examples » wave.py
from visual import *

# David Scherer

dt = 0.1

g = []
for i in range(3):
  g.append(display(x = 0, y = 30 + 200*i, width=600, height=170))

g[0].title="k=6N/m mass=2.0kg"
g[1].title="k=6N/m mass=1.0kg"
g[2].title="k=6N/m mass=0.5kg"

bands = [ curve( x = arange(-50,50), display=g[0], color=color.red, k = 6., mass = 2.0),
          curve( x = arange(-50,50), display=g[1], color=color.yellow, k = 6., mass = 1.0),
          curve( x = arange(-50,50), display=g[2], color=color.green, k = 6., mass = 0.5),
        ]

for band in bands:
    band.radius = 0.5
    band.momentum = zeros((100,3),float)

    ### Uncomment exactly one of the following lines: ###

    band.momentum[:25,1] = sin(band.x[:25]*pi / 25.0)*3   # half-wave pulse
##    band.momentum[:25,1] = sin(band.x[:25]*2*pi / 25.0)*5 # full-wave pulse
##    band.momentum[:25,0] = sin(band.x[:25]*pi / 25.0)*5   # compression wave
##    band.momentum[:,1] = sin(band.x * 4 * pi / 100.0)*2   # standing wave
##    band.momentum[25,1] = 20                             # single point impulse (messy)

while True:
    rate(100)
    for band in bands:
        # Keep endpoints fixed:
        band.momentum[0] = band.momentum[-1] = vector(0,0,0)

        # Integrate velocity:
        band.pos = band.pos + (band.momentum/band.mass*dt)

        # force[n] is the force on point n from point n+1 (to the right):
        force = band.k * (band.pos[1:] - band.pos[:-1])

        # all points but the last experience forces to the right:
        band.momentum[:-1] = band.momentum[:-1] + force * dt

        # all points but the first experience forces to the left:
        band.momentum[1:] = band.momentum[1:] - force * dt
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.