All Samples(5574) | Call(5046) | Derive(0) | Import(528)
Choose a random item from range(start, stop[, step]). This fixes the problem with randint() which includes the endpoint; in Python this is usually not what you want. Do not supply the 'int', 'default', and 'maxwidth' arguments.
src/k/a/kamaelia-HEAD/trunk/Code/Python/Kamaelia/Examples/GraphVisualisation/BasicGraphVisualisation/PhysApp1.py kamaelia(Download)
import pygame from pygame.locals import * from random import randrange import random from Axon.Component import component
def makeParticle(self, label, position, nodetype, particleRadius):
if position == "randompos":
xpos = randrange(self.border, self.screensize[0]-self.border, 1)
ypos = randrange(self.border, self.screensize[1]-self.border, 1)
else:
xpos,ypos = position
particle = VisibleParticle( (xpos, ypos), label, particleRadius)
def extra(self):
if self.physics:
if random.randrange(0,100)<5:
self.makeParticle(str(self.X), "randompos", "circle", 20)
self.X += 1
if random.randrange(0,100)<25:
start = self.physics.particleDict.keys()[random.randrange(0,len(self.physics.particleDict.keys()))]
end = start
while end == start:
end = self.physics.particleDict.keys()[random.randrange(0,len(self.physics.particleDict.keys()))]
linkDict = {}
while len(linkDict.keys()) <L:
start = random.randrange(0,len(nodes))
end = start
while end == start:
end = random.randrange(0,len(nodes))
linkDict[ nodes[start][0],nodes[end][0] ] = None
links = linkDict.keys()
app = PhysApp1( (640, 480), False, nodes, links)
X = N+1
for i in app.main():
if randrange(0,100)<5:
if randrange(0,100)<5:
app.makeParticle(str(X), "randompos", "circle", 20)
X += 1
if randrange(0,100)<25:
start = app.physics.particleDict.keys()[random.randrange(0,len(app.physics.particleDict.keys()))]
end = start
while end == start:
end = app.physics.particleDict.keys()[random.randrange(0,len(app.physics.particleDict.keys()))]
src/k/a/kamaelia-HEAD/Code/Python/Kamaelia/Examples/GraphVisualisation/BasicGraphVisualisation/PhysApp1.py kamaelia(Download)
import pygame from pygame.locals import * from random import randrange import random from Axon.Component import component
def makeParticle(self, label, position, nodetype, particleRadius):
if position == "randompos":
xpos = randrange(self.border, self.screensize[0]-self.border, 1)
ypos = randrange(self.border, self.screensize[1]-self.border, 1)
else:
xpos,ypos = position
particle = VisibleParticle( (xpos, ypos), label, particleRadius)
def extra(self):
if self.physics:
if random.randrange(0,100)<5:
self.makeParticle(str(self.X), "randompos", "circle", 20)
self.X += 1
if random.randrange(0,100)<25:
start = self.physics.particleDict.keys()[random.randrange(0,len(self.physics.particleDict.keys()))]
end = start
while end == start:
end = self.physics.particleDict.keys()[random.randrange(0,len(self.physics.particleDict.keys()))]
linkDict = {}
while len(linkDict.keys()) <L:
start = random.randrange(0,len(nodes))
end = start
while end == start:
end = random.randrange(0,len(nodes))
linkDict[ nodes[start][0],nodes[end][0] ] = None
links = linkDict.keys()
app = PhysApp1( (640, 480), False, nodes, links)
X = N+1
for i in app.main():
if randrange(0,100)<5:
if randrange(0,100)<5:
app.makeParticle(str(X), "randompos", "circle", 20)
X += 1
if randrange(0,100)<25:
start = app.physics.particleDict.keys()[random.randrange(0,len(app.physics.particleDict.keys()))]
end = start
while end == start:
end = app.physics.particleDict.keys()[random.randrange(0,len(app.physics.particleDict.keys()))]
src/k/a/kamaelia-HEAD/trunk/Code/Python/Kamaelia/Examples/GraphVisualisation/BasicGraphVisualisation/VisibleParticle.py kamaelia(Download)
import pygame from pygame.locals import * from random import randrange import random from Axon.Component import component
def makeParticle(self, label, position, nodetype, particleRadius):
if position == "randompos":
xpos = randrange(self.border, self.screensize[0]-self.border, 1)
ypos = randrange(self.border, self.screensize[1]-self.border, 1)
else:
xpos,ypos = position
particle = VisibleParticle( (xpos, ypos), label, particleRadius)
linkDict = {}
while len(linkDict.keys()) <L:
start = random.randrange(0,len(nodes))
end = start
while end == start:
end = random.randrange(0,len(nodes))
linkDict[ nodes[start][0],nodes[end][0] ] = None
links = linkDict.keys()
app = PhysApp1( (640, 480), False, nodes, links)
X = N+1
for i in app.main():
if randrange(0,100)<5:
if randrange(0,100)<5:
app.makeParticle(str(X), "randompos", "circle", 20)
X += 1
if randrange(0,100)<25:
start = app.physics.particleDict.keys()[random.randrange(0,len(app.physics.particleDict.keys()))]
end = start
while end == start:
end = app.physics.particleDict.keys()[random.randrange(0,len(app.physics.particleDict.keys()))]
src/k/a/kamaelia-HEAD/Code/Python/Kamaelia/Examples/GraphVisualisation/BasicGraphVisualisation/VisibleParticle.py kamaelia(Download)
import pygame from pygame.locals import * from random import randrange import random from Axon.Component import component
def makeParticle(self, label, position, nodetype, particleRadius):
if position == "randompos":
xpos = randrange(self.border, self.screensize[0]-self.border, 1)
ypos = randrange(self.border, self.screensize[1]-self.border, 1)
else:
xpos,ypos = position
particle = VisibleParticle( (xpos, ypos), label, particleRadius)
linkDict = {}
while len(linkDict.keys()) <L:
start = random.randrange(0,len(nodes))
end = start
while end == start:
end = random.randrange(0,len(nodes))
linkDict[ nodes[start][0],nodes[end][0] ] = None
links = linkDict.keys()
app = PhysApp1( (640, 480), False, nodes, links)
X = N+1
for i in app.main():
if randrange(0,100)<5:
if randrange(0,100)<5:
app.makeParticle(str(X), "randompos", "circle", 20)
X += 1
if randrange(0,100)<25:
start = app.physics.particleDict.keys()[random.randrange(0,len(app.physics.particleDict.keys()))]
end = start
while end == start:
end = app.physics.particleDict.keys()[random.randrange(0,len(app.physics.particleDict.keys()))]
src/k/a/kamaelia-HEAD/trunk/Sketches/MH/Layout/Example/VisibleParticle.py kamaelia(Download)
import pygame from pygame.locals import * from random import randrange import random from Axon.Component import component
def makeParticle(self, label, position, nodetype, particleRadius):
if position == "randompos":
xpos = randrange(self.border, self.screensize[0]-self.border, 1)
ypos = randrange(self.border, self.screensize[1]-self.border, 1)
else:
xpos,ypos = position
particle = VisibleParticle( (xpos, ypos), label, particleRadius)
linkDict = {}
while len(linkDict.keys()) <L:
start = random.randrange(0,len(nodes))
end = start
while end == start:
end = random.randrange(0,len(nodes))
linkDict[ nodes[start][0],nodes[end][0] ] = None
links = linkDict.keys()
app = PhysApp1( (640, 480), False, nodes, links)
X = N+1
for i in app.main():
if randrange(0,100)<5:
if randrange(0,100)<5:
app.makeParticle(str(X), "randompos", "circle", 20)
X += 1
if randrange(0,100)<25:
start = app.physics.particleDict.keys()[random.randrange(0,len(app.physics.particleDict.keys()))]
end = start
while end == start:
end = app.physics.particleDict.keys()[random.randrange(0,len(app.physics.particleDict.keys()))]
src/k/a/kamaelia-HEAD/trunk/Sketches/MH/Layout/Example/PhysApp1.py kamaelia(Download)
import pygame from pygame.locals import * from random import randrange import random from Axon.Component import component
def makeParticle(self, label, position, nodetype, particleRadius):
if position == "randompos":
xpos = randrange(self.border, self.screensize[0]-self.border, 1)
ypos = randrange(self.border, self.screensize[1]-self.border, 1)
else:
xpos,ypos = position
particle = VisibleParticle( (xpos, ypos), label, particleRadius)
linkDict = {}
while len(linkDict.keys()) <L:
start = random.randrange(0,len(nodes))
end = start
while end == start:
end = random.randrange(0,len(nodes))
linkDict[ nodes[start][0],nodes[end][0] ] = None
links = linkDict.keys()
app = PhysApp1( (640, 480), False, nodes, links)
X = N+1
for i in app.main():
if randrange(0,100)<5:
if randrange(0,100)<5:
app.makeParticle(str(X), "randompos", "circle", 20)
X += 1
if randrange(0,100)<25:
start = app.physics.particleDict.keys()[random.randrange(0,len(app.physics.particleDict.keys()))]
end = start
while end == start:
end = app.physics.particleDict.keys()[random.randrange(0,len(app.physics.particleDict.keys()))]
src/m/i/mingus-0.4.2.3/mingus_examples/improviser/improviser.py mingus(Download)
from mingus.containers import NoteContainer, Note from mingus.midi import fluidsynth import time, sys from random import random, choice, randrange SF2 = "soundfont.sf2"
# Play chord if not swing and play_chords and loop > chord_start and loop < chord_end: fluidsynth.play_NoteContainer(c, chord_channel, randrange(50,75)) if play_chords and loop > chord_start and loop < chord_end: if orchestrate_second: if loop % 2 == 0: fluidsynth.play_NoteContainer(c, chord_channel2, randrange(50,75)) else: fluidsynth.play_NoteContainer(c, chord_channel2, randrange(50,75))
if t > 0 and t < len(beats) - 1: if beats[t-1] and not beats[t+1]: n = Note(choice(c).name) fluidsynth.play_Note(n, solo_channel, randrange(80, 110)) print n # Repeat chord on half of the bar if play_chords and t != 0 and loop > chord_start and loop < chord_end: if swing and random() > 0.95: fluidsynth.play_NoteContainer(c, chord_channel3, randrange(20, 75)) elif t % (len(beats) / 2) == 0 and t != 0: fluidsynth.play_NoteContainer(c, chord_channel3, randrange(20, 75))
l = Note(choice(c).name)
l.octave_down()
l.octave_down()
fluidsynth.play_Note(l, bass_channel, randrange(50,75))
elif play_bass and t == 0:
fluidsynth.play_Note(l, bass_channel, randrange(50,75))
# Drums
if play_drums and loop > 0:
if t % (len(beats) / 2) == 0 and t != 0:
fluidsynth.play_Note(Note("E", 2), 9, randrange(50,100)) # snare
else:
if random() > 0.8 or t == 0:
fluidsynth.play_Note(Note("C", 2), 9, randrange(20,100)) # bass
fluidsynth.play_Note(Note("C", 2), 9, randrange(20,100)) # bass
if t == 0 and random() > 0.75:
fluidsynth.play_Note(Note("C#", 3), 9, randrange(60,100)) # crash
if swing:
if random() > 0.9:
fluidsynth.play_Note(Note("A#", 2), 9, randrange(50,100)) # hihat open
elif random() > 0.6:
fluidsynth.play_Note(Note("G#", 2), 9, randrange(100,120)) # hihat closed
src/k/a/kamaelia-HEAD/Sketches/MH/Layout/Example/VisibleParticle.py kamaelia(Download)
import pygame from pygame.locals import * from random import randrange import random from Axon.Component import component
def makeParticle(self, label, position, nodetype, particleRadius):
if position == "randompos":
xpos = randrange(self.border, self.screensize[0]-self.border, 1)
ypos = randrange(self.border, self.screensize[1]-self.border, 1)
else:
xpos,ypos = position
particle = VisibleParticle( (xpos, ypos), label, particleRadius)
linkDict = {}
while len(linkDict.keys()) <L:
start = random.randrange(0,len(nodes))
end = start
while end == start:
end = random.randrange(0,len(nodes))
linkDict[ nodes[start][0],nodes[end][0] ] = None
links = linkDict.keys()
app = PhysApp1( (640, 480), False, nodes, links)
X = N+1
for i in app.main():
if randrange(0,100)<5:
if randrange(0,100)<5:
app.makeParticle(str(X), "randompos", "circle", 20)
X += 1
if randrange(0,100)<25:
start = app.physics.particleDict.keys()[random.randrange(0,len(app.physics.particleDict.keys()))]
end = start
while end == start:
end = app.physics.particleDict.keys()[random.randrange(0,len(app.physics.particleDict.keys()))]
src/k/a/kamaelia-HEAD/Sketches/MH/Layout/Example/PhysApp1.py kamaelia(Download)
import pygame from pygame.locals import * from random import randrange import random from Axon.Component import component
def makeParticle(self, label, position, nodetype, particleRadius):
if position == "randompos":
xpos = randrange(self.border, self.screensize[0]-self.border, 1)
ypos = randrange(self.border, self.screensize[1]-self.border, 1)
else:
xpos,ypos = position
particle = VisibleParticle( (xpos, ypos), label, particleRadius)
linkDict = {}
while len(linkDict.keys()) <L:
start = random.randrange(0,len(nodes))
end = start
while end == start:
end = random.randrange(0,len(nodes))
linkDict[ nodes[start][0],nodes[end][0] ] = None
links = linkDict.keys()
app = PhysApp1( (640, 480), False, nodes, links)
X = N+1
for i in app.main():
if randrange(0,100)<5:
if randrange(0,100)<5:
app.makeParticle(str(X), "randompos", "circle", 20)
X += 1
if randrange(0,100)<25:
start = app.physics.particleDict.keys()[random.randrange(0,len(app.physics.particleDict.keys()))]
end = start
while end == start:
end = app.physics.particleDict.keys()[random.randrange(0,len(app.physics.particleDict.keys()))]
src/p/y/python-visual-HEAD/examples/randombox.py python-visual(Download)
from visual import *
from random import random, randrange
## this is mostly for experimenting with zooming and rotating
print("""
Right button drag to rotate "camera" to view scene.
def random_box ():
xx = randrange (-55,54)
yy = randrange (-55,54)
zz = randrange (-55,54)
x = randrange (1,11)
y = randrange (1,11)
z = randrange (1,11)
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next