-
Notifications
You must be signed in to change notification settings - Fork 0
/
starField.py
45 lines (35 loc) · 1.24 KB
/
starField.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
ElementArray demo.
This demo requires a graphics card that supports OpenGL2 extensions.
It shows how to manipulate an arbitrary set of elements using numpy arrays
and avoiding for loops in your code for optimised performance.
See also the elementArrayStim demo.
"""
from __future__ import division
from psychopy import visual, event, core
from psychopy.tools.coordinatetools import pol2cart
import numpy
nDots = 500
maxSpeed = 0.02
dotSize = .0075
dotsTheta = numpy.random.rand(nDots) * 360
dotsRadius = (numpy.random.rand(nDots) ** 0.5) * 2
speed = numpy.random.rand(nDots) * maxSpeed
win = visual.Window([800, 600], color=[-1, -1, -1])
dots = visual.ElementArrayStim(win, elementTex=None, elementMask='circle',
nElements=nDots, sizes=dotSize)
while not event.getKeys():
# update radius
dotsRadius = (dotsRadius + speed)
# random radius where radius too large
outFieldDots = (dotsRadius >= 2.0)
dotsRadius[outFieldDots] = numpy.random.rand(sum(outFieldDots)) * 2.0
dotsX, dotsY = pol2cart(dotsTheta, dotsRadius)
dotsX *= 0.75 # to account for wider aspect ratio
dots.xys = numpy.array([dotsX, dotsY]).transpose()
dots.draw()
win.flip()
win.close()
core.quit()