本文整理汇总了Python中scene.Scene.add方法的典型用法代码示例。如果您正苦于以下问题:Python Scene.add方法的具体用法?Python Scene.add怎么用?Python Scene.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scene.Scene
的用法示例。
在下文中一共展示了Scene.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: different_points
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import add [as 别名]
def different_points(radians1, radians2):
sc = Scene()
circle = Circle(density = CIRCLE_DENSITY).scale(RADIUS)
sc.add(circle)
points1, points2 = (
[
(RADIUS * np.cos(angle), RADIUS * np.sin(angle), 0)
for angle in radians
]
for radians in (radians1, radians2)
)
dots1, dots2 = (
Mobject(*[Dot(point) for point in points])
for points in (points1, points2)
)
lines1, lines2 = (
[
Line(point1, point2)
for point1, point2 in it.combinations(points, 2)
]
for points in (points1, points2)
)
sc.add(dots1, *lines1)
sc.animate(
Transform(dots1, dots2, run_time = 3),
*[
Transform(line1, line2, run_time = 3)
for line1, line2 in zip(lines1, lines2)
]
)
sc.dither()
return sc
示例2: summarize_pattern
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import add [as 别名]
def summarize_pattern(*radians):
sc = Scene()
circle = Circle(density = CIRCLE_DENSITY).scale(RADIUS)
sc.add(circle)
points = [
(RADIUS * np.cos(angle), RADIUS * np.sin(angle), 0)
for angle in radians
]
dots = [Dot(point) for point in points]
last_num = None
for x in xrange(len(points)):
new_lines = Mobject(*[
Line(points[x], points[y]) for y in xrange(x)
])
num = TexMobject(str(moser_function(x + 1))).center()
sc.animate(
Transform(last_num, num) if last_num else ShowCreation(num),
FadeIn(new_lines),
FadeIn(dots[x]),
run_time = 0.5,
)
sc.remove(last_num)
last_num = num
sc.add(num, dots[x], new_lines)
sc.dither()
return sc
示例3: interesting_problems
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import add [as 别名]
def interesting_problems():
sc = Scene()
locales = [(6, 2, 0), (6, -2, 0), (-5, -2, 0)]
fermat = Mobject(*TexMobjects(["x^n","+","y^n","=","z^n"]))
fermat.scale(0.5).shift((-2.5, 0.7, 0))
face = SimpleFace()
tb = ThoughtBubble().shift((-1.5, 1, 0))
sb = SpeechBubble().shift((-2.4, 1.3, 0))
fermat_copies, face_copies, tb_copies, sb_copies = (
Mobject(*[
deepcopy(mob).scale(0.5).shift(locale)
for locale in locales
])
for mob in [fermat, face, tb, sb]
)
sc.add(face, tb)
sc.animate(ShowCreation(fermat, run_time = 1))
sc.add(fermat)
sc.dither()
sc.animate(
Transform(
deepcopy(fermat).repeat(len(locales)),
fermat_copies
),
FadeIn(face_copies, run_time = 1.0)
)
sc.animate(FadeIn(tb_copies))
sc.dither()
sc.animate(
Transform(tb, sb),
Transform(tb_copies, sb_copies)
)
return sc
示例4: PyAgar
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import add [as 别名]
class PyAgar(object):
title = "PyAgar"
def __init__(self, args):
self.args = args
pyglet.resource.path.append(os.path.join(dname,'resources'))
pyglet.resource.reindex()
pyglet.font.add_file('resources/DejaVuSans.ttf')
pyglet.font.add_file('resources/unifont.ttf')
director.set_show_FPS(False)
w = director.init(fullscreen=True, caption=self.title, visible=True, resizable=True)
# width = director.window.width
# height = director.window.height
# wnew, hnew = int(width * .75), int(height * .75)
# director.window.set_fullscreen(False)
# director.window.set_size(wnew, hnew)
# w.set_location((width-wnew)/2, (height-hnew)/2)
director.window.pop_handlers()
director.window.push_handlers(Handler())
self.gameScene = Scene()
self.gameLayer = AgarLayer()
self.gameScene.add(self.gameLayer)
director.replace(self.gameScene)
director.window.set_visible(True)
示例5: logo_to_circle
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import add [as 别名]
def logo_to_circle():
from generate_logo import DARK_BROWN, LOGO_RADIUS
sc = Scene()
small_circle = Circle(
density = CIRCLE_DENSITY,
color = 'skyblue'
).scale(LOGO_RADIUS).highlight(
DARK_BROWN, lambda (x, y, z) : x < 0 and y > 0
)
big_circle = Circle(density = CIRCLE_DENSITY).scale(RADIUS)
sc.add(small_circle)
sc.dither()`
sc.animate(Transform(small_circle, big_circle))
return sc
示例6: count_sections
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import add [as 别名]
def count_sections(*radians):
sc = Scene()
circle = Circle(density = CIRCLE_DENSITY).scale(RADIUS)
sc.add(circle)
points = [
(RADIUS * np.cos(angle), RADIUS * np.sin(angle), 0)
for angle in radians
]
dots = [Dot(point) for point in points]
interior = Region(lambda x, y : x**2 + y**2 < RADIUS**2)
for x in xrange(1, len(points)):
if x == 1:
sc.animate(ShowCreation(dots[0]), ShowCreation(dots[1]))
sc.add(dots[0], dots[1])
else:
sc.animate(ShowCreation(dots[x]))
sc.add(dots[x])
new_lines = Mobject(*[
Line(points[x], points[y]) for y in xrange(x)
])
sc.animate(Transform(deepcopy(dots[x]), new_lines, run_time = 2.0))
sc.add(new_lines)
sc.dither()
regions = plane_partition_from_points(*points[:x+1])
for reg in regions:
reg.intersect(interior)
regions = filter(lambda reg : reg.bool_grid.any(), regions)
last_num = None
for reg, count in zip(regions, it.count(1)):
number = TexMobject(str(count)).shift((RADIUS, 3, 0))
sc.highlight_region(reg)
rt = 1.0 / (x**0.8)
sc.add(number)
sc.remove(last_num)
last_num = number
sc.dither(rt)
sc.reset_background()
sc.remove(last_num)
sc.animate(Transform(last_num, deepcopy(last_num).center()))
sc.dither()
sc.remove(last_num)
return sc
示例7: response_invitation
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import add [as 别名]
def response_invitation():
sc = Scene()
video_icon = VideoIcon()
mini_videos = Mobject(*[
deepcopy(video_icon).scale(0.5).shift((3, y, 0))
for y in [-2, 0, 2]
])
comments = Mobject(*[
Line((-1.2, y, 0), (1.2, y, 0), color = 'white')
for y in [-1.5, -1.75, -2]
])
sc.add(video_icon)
sc.dither()
sc.animate(Transform(deepcopy(video_icon).repeat(3), mini_videos))
sc.add(mini_videos)
sc.dither()
sc.animate(ShowCreation(comments, run_time = 1.0))
return sc
示例8: next_few_videos
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import add [as 别名]
def next_few_videos(*radians):
sc = Scene()
circle = Circle(density = CIRCLE_DENSITY).scale(RADIUS)
points = [
(RADIUS * np.cos(angle), RADIUS * np.sin(angle), 0)
for angle in radians
]
dots = Mobject(*[
Dot(point) for point in points
])
lines = Mobject(*[
Line(point1, point2)
for point1, point2 in it.combinations(points, 2)
])
thumbnail = Mobject(circle, dots, lines)
frame = VideoIcon().highlight(
"black",
lambda point : np.linalg.norm(point) < 0.5
)
big_frame = deepcopy(frame).scale(SPACE_WIDTH)
frame.shift((-5, 0, 0))
sc.add(thumbnail)
sc.dither()
sc.animate(
Transform(big_frame, frame),
Transform(
thumbnail,
deepcopy(thumbnail).scale(0.15).shift((-5, 0, 0))
)
)
sc.add(frame, thumbnail)
sc.dither()
last = frame
for x in [-2, 1, 4]:
vi = VideoIcon().shift((x, 0, 0))
sc.animate(
Transform(deepcopy(last), vi),
Animation(thumbnail)#Keeps it from getting burried
)
sc.add(vi)
last = vi
return sc
示例9: connect_points
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import add [as 别名]
def connect_points(*radians):
sc = Scene()
circle = Circle(density = CIRCLE_DENSITY).scale(RADIUS)
sc.add(circle)
points = [
(RADIUS * np.cos(angle), RADIUS * np.sin(angle), 0)
for angle in radians
]
dots = [Dot(point) for point in points]
sc.add(*dots)
anims = []
all_lines = []
for x in xrange(len(points)):
lines = [Line(points[x], points[y]) for y in range(len(points))]
lines = Mobject(*lines)
anims.append(Transform(deepcopy(dots[x]), lines, run_time = 3.0))
all_lines.append(lines)
sc.animate(*anims)
sc.add(*all_lines)
sc.dither()
return sc
示例10: WhackAMole
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import add [as 别名]
class WhackAMole(object):
title = "Whack A Mole"
def __init__(self):
if not os.path.exists("data"): os.mkdir("data")
pyglet.resource.path.append('resources')
pyglet.resource.reindex()
pyglet.resource.add_font('cutouts.ttf')
pyglet.resource.add_font('scoreboard.ttf')
director.init(width=int(1024*1.0), height=int(768*1.1),
caption=self.title, visible=False, resizable=True)
director.window.set_size(int(1024*1.0), int(768*1.1))
director.window.pop_handlers()
director.window.push_handlers(DefaultHandler())
director.settings = {'overlay': False,
'eyetracker': True,
'eyetracker_ip': '127.0.0.1',
'eyetracker_out_port': '4444',
'eyetracker_in_port': '5555',
'calibration_speed': 1,
'calibration_wait': 1,
'calibration_random': 1,
'calibration_level': 3,
'calibration_auto': 1,
'calibration_points': 2,
'calibration_eye': 0
}
self.client = None
self.client = iViewXClient(director.settings['eyetracker_ip'], int(director.settings['eyetracker_out_port']))
self.listener = reactor.listenUDP(int(director.settings['eyetracker_in_port']), self.client)
director.set_show_FPS(False)
director.window.set_fullscreen(False)
if director.settings['eyetracker']:
director.window.set_mouse_visible(False)
else:
director.window.set_mouse_visible(True)
# Intro scene and its layers
self.introScene = Scene()
self.mainMenu = MainMenu()
self.optionsMenu = OptionsMenu()
self.eyetrackerScrim = EyetrackerScrim()
self.mplxLayer = MultiplexLayer(self.mainMenu, self.optionsMenu)
self.introScene.add(self.mplxLayer, 1)
self.introScene.register_event_type('start_task')
self.introScene.register_event_type('eyetracker_info_changed')
self.introScene.push_handlers(self)
# Task scene and its layers
self.taskScene = Scene()
self.taskLayer = Task(self.client)
self.calibrationLayer = CalibrationLayer(self.client)
self.calibrationLayer.register_event_type('show_headposition')
self.calibrationLayer.register_event_type('hide_headposition')
self.calibrationLayer.push_handlers(self)
self.taskLayer.register_event_type('new_trial')
self.taskLayer.register_event_type('start_calibration')
self.taskLayer.register_event_type('stop_calibration')
self.taskLayer.push_handlers(self)
self.taskScene.add(self.taskLayer, 1)
self.taskScene.register_event_type('show_intro_scene')
self.taskScene.push_handlers(self)
director.window.set_visible(True)
def start_calibration(self, on_success, on_failure):
self.calibrationLayer.on_success = on_success
self.calibrationLayer.on_failure = on_failure
self.calibrationLayer.points = director.settings['calibration_points']
self.calibrationLayer.eye = director.settings['calibration_eye']
self.calibrationLayer.level = director.settings['calibration_level']
self.calibrationLayer.speed = director.settings['calibration_speed']
self.calibrationLayer.auto = director.settings['calibration_auto']
self.calibrationLayer.wait = director.settings['calibration_wait']
self.calibrationLayer.random = director.settings['calibration_random']
self.taskScene.add(self.calibrationLayer, 2)
def stop_calibration(self):
self.taskScene.remove(self.calibrationLayer)
def eyetracker_listen(self, _):
self.listener = reactor.listenUDP(int(director.settings['eyetracker_in_port']), self.client)
self.introScene.remove(self.eyetrackerScrim)
self.introScene.enable_handlers(True)
#.........这里部分代码省略.........
示例11: WilliamsEnvironment
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import add [as 别名]
class WilliamsEnvironment(object):
title = "The Williams' Search Task"
def __init__(self):
if not os.path.exists("data"): os.mkdir("data")
pyglet.resource.path.append('resources')
pyglet.resource.reindex()
pyglet.resource.add_font('Pipe_Dream.ttf')
pyglet.resource.add_font('cutouts.ttf')
director.set_show_FPS(False)
director.init(fullscreen=True, caption=self.title, visible=True, resizable=True)
width = director.window.width
height = director.window.height
director.window.set_fullscreen(False)
director.window.set_size(int(width * .75), int(height * .75))
director.window.pop_handlers()
director.window.push_handlers(Handler())
director.settings = {'seed':'1',
'eyetracker': True,
'eyetracker_ip': '127.0.0.1',
'eyetracker_out_port': '4444',
'eyetracker_in_port': '5555',
'player': 'Human',
'players': ['Human'],
'mode': 'Insane',
'modes': ['Easy', 'Moderate', 'Hard', 'Insane', 'Experiment']}
self.client = None
self.client_actr = None
if ACTR6:
director.settings['players'].append("ACT-R")
#director.settings['player'] = "ACT-R"
director.settings['eyetracker'] = False
self.client_actr = JNI_Server(self)
self.listener_actr = reactor.listenTCP(6666, self.client_actr)
elif eyetracking:
self.client = iViewXClient(director.settings['eyetracker_ip'], int(director.settings['eyetracker_out_port']))
self.listener = reactor.listenUDP(int(director.settings['eyetracker_in_port']), self.client)
if platform.system() != 'Windows':
director.window.set_icon(pyglet.resource.image('logo.png'))
cursor = director.window.get_system_mouse_cursor(director.window.CURSOR_HAND)
director.window.set_mouse_cursor(cursor)
# Intro scene and its layers
self.introScene = Scene()
self.mainMenu = MainMenu()
self.optionsMenu = OptionsMenu()
self.participantMenu = ParticipantMenu()
self.introBackground = BackgroundLayer()
self.eyetrackerScrim = EyetrackerScrim()
self.introScene.add(self.introBackground)
self.mplxLayer = MultiplexLayer(self.mainMenu, self.optionsMenu, self.participantMenu)
self.introScene.add(self.mplxLayer, 1)
self.introScene.register_event_type('start_task')
self.introScene.register_event_type('eyetracker_info_changed')
self.introScene.push_handlers(self)
# Task scene and its layers
self.taskScene = Scene()
self.taskBackgroundLayer = TaskBackground()
self.taskLayer = Task(self.client, self.client_actr)
self.actrScrim = ACTRScrim()
if self.client:
self.calibrationLayer = CalibrationLayer(self.client)
self.calibrationLayer.register_event_type('show_headposition')
self.calibrationLayer.register_event_type('hide_headposition')
self.calibrationLayer.push_handlers(self)
self.headpositionLayer = HeadPositionLayer(self.client)
self.taskLayer.register_event_type('new_trial')
self.taskLayer.push_handlers(self.taskBackgroundLayer)
self.taskLayer.register_event_type('start_calibration')
self.taskLayer.register_event_type('stop_calibration')
self.taskLayer.register_event_type('show_headposition')
self.taskLayer.register_event_type('hide_headposition')
self.taskLayer.register_event_type('actr_wait_connection')
self.taskLayer.register_event_type('actr_wait_model')
self.taskLayer.register_event_type('actr_running')
self.taskLayer.push_handlers(self)
self.taskScene.add(self.taskBackgroundLayer)
self.taskScene.add(self.taskLayer, 1)
self.actrScrim.visible = False
self.taskScene.add(self.actrScrim, 3)
#.........这里部分代码省略.........
示例12: Scene
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import add [as 别名]
from scene import Scene
from player import Player
from ia import Ia
from ball import Ball
WIDTH = 800
HEIGHT = 600
BG = (255, 67, 0)
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
scene = Scene(screen, BG)
scene.add(Player("player", 5, (WIDTH / 2) - 50, 10, 50))
scene.add(Ia("ia", WIDTH - 5 - 10, (HEIGHT / 2) - 50, 10, 50))
scene.add(Ball("ball", (WIDTH / 2) - (10 / 2), (HEIGHT / 2) - (10 / 2), 10, 10))
scene.draw()
clock = pygame.time.Clock()
totalTime = pygame.time.get_ticks()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
timeChange = pygame.time.get_ticks() - totalTime
totalTime = pygame.time.get_ticks()
示例13: add
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import add [as 别名]
def add(self, *mobjects):
Scene.add(self, *list(mobjects)+self.foreground_mobjects)
示例14: add_foreground_mobjects
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import add [as 别名]
def add_foreground_mobjects(self, *mobjects):
self.foreground_mobjects += list(mobjects)
Scene.add(self, *mobjects)
示例15: Renderer
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import add [as 别名]
class Renderer(object):
def __init__(self):
self.scene = Scene()
self.scene.add(Snowman())
sn2 = Snowman()
sn3 = Snowman()
sn2.x = 3
sn3.z = 2
self.scene.add(sn2)
self.scene.add(sn3)
self.scene.camera.translate(0, -.5, -4)
def setup(self):
"""Set up the OpenGL environment."""
# Initialize the drawing environment (create main windows, etc)
glutInit(sys.argv)
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT)
glutCreateWindow(name)
glShadeModel(GL_SMOOTH)
glClearDepth(1.0)
glDepthFunc(GL_LESS) # The Type Of Depth Test To Do
glEnable(GL_DEPTH_TEST) # Enables Depth Testing
glShadeModel(GL_SMOOTH) # Enables Smooth Color Shading
glMatrixMode(GL_PROJECTION)
glLoadIdentity() # Reset The Projection Matrix
# Calculate The Aspect Ratio Of The Window
gluPerspective(45.0, float(WINDOW_WIDTH)/float(WINDOW_HEIGHT), 0.1, 100.0)
glMatrixMode(GL_MODELVIEW)
# Set up keyboard listeners.
glutKeyboardFunc(self.on_key)
def start(self):
"""Begin the render."""
glutDisplayFunc(self.render)
glutMainLoop()
def render(self):
"""Render the scene."""
self.scene.render()
def on_key(self, key, x, y):
"""Handle a keypress."""
print "Received", key
if key == "a":
self.scene.camera.translate(x=0.05)
elif key == "d":
self.scene.camera.translate(x=-0.05)
elif key == "s":
self.scene.camera.translate(y=0.05)
elif key == "w":
self.scene.camera.translate(y=-0.05)
elif key == "e":
self.scene.camera.translate(z=0.05)
elif key == "q":
self.scene.camera.translate(z=-0.05)
elif key == "j":
self.scene.camera.rotate(y=-5)
elif key == "l":
self.scene.camera.rotate(y=5)
elif key == "k":
self.scene.camera.rotate(x=5)
elif key == "i":
self.scene.camera.rotate(x=-5)
elif key == "u":
self.scene.camera.rotate(z=5)
elif key == "o":
self.scene.camera.rotate(z=-5)
self.render()