예제 #1
0
def main():
	win = ps.Window('Boring Objects')
	count = 0
	data = []
	h = hpy()
	for i in range(5):
		r = ps.Rect(count/10, count/10, 40, 40, (1,1,1,.5))
		win.add(r)
		print h.heap()
		count += 1;
		win.refresh()
		print h.heap()
		#data.append(win.s_since_refresh())

	return data
예제 #2
0
# Create a window with the title "Color Grid"
w = ps.Window(title="Color Change Demo")

all_rects = list()

# Creates two color objects
colorA = ps.Color(1, 0, 0, .5)
colorB = ps.Color(0, 1, 1, .5)

#creates a 10 by 10 grid of squares, choosing from the list of colors
side_length = 50
for x in range(10):
    for y in range(10):
        if (y + x) % 2 == 0:
            r = ps.Rect(x * (side_length + 1), y * (side_length + 1),
                        side_length, side_length, colorA)
        else:
            r = ps.Rect(x * (side_length + 1), y * (side_length + 1),
                        side_length, side_length, colorB)
        w.add(r)  # Add the rectangles to the window...
        all_rects.append(r)  # and keep track of them with a list

#changes which color each square is based on the time.  This means swapping out colors, not creating new colors.
oldt = 0
while w.is_open():
    t = w.s_since_open()
    if t > oldt + 1:
        colorB.g = 1 / t
        #colorB.g = 1/t
        oldt = t
예제 #3
0
# Import the python module
import pyshiva as ps
import math, random

# Create a window with the title "Rose Curves"
w = ps.Window(title="Rose Curves")

all_rects = list()

# Create 1000 squares with different colors
for i in range(1):
    #print "Initialized"
    c = random.random()
    a = abs(math.cos(i)) * 0.5
    side_length = 1 * 50
    r = ps.Rect(0, 0, side_length, side_length, (c, abs(math.sin(i)), 1, 1))
    w.add(r)  # Add the rectangles to the window...
    all_rects.append(r)  # and keep track of them with a list

k = 0.25
while w.is_open():
    t = w.s_since_open()
    for (i, r) in enumerate(all_rects):
        if (int(t) % 2):
            r.x = w.width / 2
            r.y = w.height / 2
            r.width = float(100.0)
            r.height = float(100.0)
            #print "Width: " +str(r.width)
            #print "Height: " +str(r.height)
        else:
예제 #4
0
import pyshiva as ps
from random import random

w = ps.Window()

r = ps.Rect(x=100, y=100, width=100, height=100)

w.add(r)

while w.is_open():
    r.width = random() * 500
    r.color = (random(), random(), random())
    w.refresh()
예제 #5
0
import pyshiva as ps
import random

w = ps.Window()

count = 30

data = [random.random() for i in range(count)]

for x in range(count):
	rect_width = w.width/float(count)
	w.add(ps.Rect((rect_width+1)*x,0,rect_width,10, (0,1,0,0.6)))

t_since_last = 0
while w.is_open():
	t = w.s_since_refresh()
	t_since_last += t
	for i,r in enumerate(w):
		n = data[i]
		r.height = n*w.height
	if t_since_last > 0.2:
		del data[0]
		data.append(random.random())
		t_since_last = 0
	w.refresh()
예제 #6
0
# Create a window with the title "Color Grid"
w = ps.Window(title = "Color Grid", width=500, height=500)

all_rects = list()
all_colors = list()
# Creats a list of 10 colors, ranging from blue to red
for i in range(10):
    testColor = ps.Color(1-.1*i,0,.1*i,1)
    all_colors.append(testColor)

#creates a 10 by 10 grid of squares, choosing from the list of colors
for x in range(10):
    for y in range(10):
        side_length = 50
        r = ps.Rect(x*(side_length+1),y*(side_length+1),side_length,side_length,all_colors[abs(x-y)])
        w.add(r) # Add the rectangles to the window...
        all_rects.append(r) # and keep track of them with a list

#changes which color each square is based on the time.  This means swapping out colors, not creating new colors.
oldt = 0
while w.is_open():
    t = w.s_since_open()*10
    for x in range(10):
        for y in range(10):
            r = all_rects[y*10+x]
            index = (x-y+int(t))%10
            r.color = all_colors[index]
    oldt = t

    # Update the screen
예제 #7
0
import pyshiva as ps

w = ps.Window(b"Groups, Yo!")

g = ps.Group(10, 10)

g2 = ps.Group(10, 10)

r1 = ps.Rect(0, 0, 100, 100, (1, 0, 0))
r2 = ps.Rect(25, 25, 50, 50, (0, 0, 1))

g.add(r1)
g.add(r2)

r3 = ps.Rect(30, 30, 10, 10, (0, 1, 0))
r4 = ps.Rect(50, 50, 10, 10, (0, 1, 0))

g2.add(r3)
g2.add(r4)

g.add(g2)

w.add(g)

while w.is_open():
    x, y = ps.get_mouse_pos()
    g.x = x
    g.y = y
    w.refresh()
예제 #8
0
# Rose Curves Demo
#

# Import the python module
import pyshiva as ps
import math, random

# Create a window with the title "Rose Curves"
w = ps.Window(title = "Rose Curves")

# Create 500 squares with different colors
for i in range(500):
    r = random.random()
    a = abs(math.cos(i))*0.5
    side_length = abs(math.sin(i))*50
    r = ps.Rect(0,0,side_length,side_length,(r,abs(math.sin(i)),1,0.1))
    w.add(r) # Add the rectangles to the window.

k = 0.25
while w.is_open():
    x,y = ps.get_mouse_pos()
    t = w.s_since_open()*2 # Use a scaled time since program start as the parametric time value
    radius = abs(math.sin(w.s_since_open()))
    if radius < 0.01: # Every time the curve collapses...
        k = random.random() # Randomize the k value to change the type of the curve
    #k = float(x)/w.width
    #print k
    #k = 0.760935
    # Place every rectangle along a rose curve, offset by its index
    for (i,r) in enumerate(w):
        ran = random.random()