Example #1
0
    def __init__(self, environment):
        """
        Controls the UI, in this case Pygame window.
        :param environment: Environment object.
        """

        # Colors
        self.background_color = THECOLORS['black']
        self.curr_color_name = random.choice(THECOLORS.keys())
        self.step_color = THECOLORS[self.curr_color_name]

        # Creates a composition of session, environment, game window and air track.
        self.session = Session()
        self.env = environment
        self.air_track = AirTrack(self)

        # Initializing Pygame.
        pygame.init()

        # Fonts
        self.hud_font = pygame.font.SysFont("monospace", 30)

        # Gets screen dimensions in pixels from the environment object and sets the surface attribute.
        self.dimensions_px = self.width_px, self.height_px = self.env.dimensions_px
        self.surface = pygame.display.set_mode(self.dimensions_px)
        self.erase_and_update()  # Updates the screen for the first time.

        # Limits the frame rate and assigns a clock to control it.
        self.frame_rate_limit = 100
        self.clock = pygame.time.Clock()

        self.is_scrolling = False  # Will be set true when the player is high enough so the screen can begin scrolling.
        self.scrolling_rate_mps = 5  # Controls the scrolling rate of the screen.

        self.done = False  # Will exit the loop when the player loses or decides to quit.
Example #2
0
def random_color(search=None):
    """get a single random Color(), with Optional search filter.
        search='green' will return 'seagreen', 'bluegreen', etc...
        
    default to choice() of full list"""
    if search: c = choice(search_color(search))
    else: c = choice(THECOLORS.values())

    #debug: print type(c), c # returns Color()
    return c
Example #3
0
def random_color(search=None):
    """get a single random Color(), with Optional search filter.
        search='green' will return 'seagreen', 'bluegreen', etc...
        
    default to choice() of full list"""    
    if search: c = choice(search_color(search))
    else: c = choice(THECOLORS.values())
    
    #debug: print type(c), c # returns Color()
    return c 
    def __init__(self):
        for i in range(16):
            setattr(self, "knob%i" % (i + 1), random.random())

        self.midi_input = False

        self.audio_in = [random.randint(-32768, 32767) for i in range(100)]
        self.bg_color = (0, 0, 0)
        self.audio_trig = False
        self.random_color = THECOLORS[random.choice(list(THECOLORS.keys()))]
        self.midi_note_new = False
Example #5
0
    def __init__(self):
        self.knob1 = random.random()
        self.knob2 = random.random()
        self.knob3 = random.random()
        self.knob4 = random.random()

        self.audio_in = [random.randint(-32768, 32767) for i in range(100)]
        self.bg_color = (0, 0, 0)
        self.audio_trig = False
        self.random_color = THECOLORS[random.choice(list(THECOLORS.keys()))]
        self.midi_note_new = False
Example #6
0
def randomGraph():
    screen.fill((0, 0, 0))
    for i in range(100):
        width = random.randint(0, 250)
        height = random.randint(0, 100)
        top = random.randint(0, 400)
        left = random.randint(0, 500)
        color_name = random.choice(THECOLORS.keys())
        color = THECOLORS[color_name]
        line_width = random.randint(1, 3)
        pygame.draw.rect(screen, color, [left, top, width, height], line_width)
    pygame.display.flip()
Example #7
0
def create_rects(screen):
    for i in range(100):
        mycolor_index = random.choice(list(THECOLORS.keys()))
        mycolor = THECOLORS[mycolor_index]

        axis_x = random.randint(1, 580)
        axis_y = random.randint(1, 580)
        rect_width = random.randint(3, 480)
        rect_height = random.randint(3, 500)
        myrect = pygame.Rect([axis_x, axis_y, rect_width, rect_height])

        line_width = random.randint(2, 5)

        pygame.draw.rect(screen, mycolor, myrect, line_width)
Example #8
0
 for event in pygame.event.get():
     if event.type == pygame.QUIT:
         sys.exit()
     elif event.type == MOUSEBUTTONDOWN:
         (pos_x, pos_y) = pygame.mouse.get_pos()
         object = unit(pos_x, pos_y, [0, 102, 255], 50, 2, 0.05)
         unit_list.append(object)
     elif event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
         position_x = random.randint(0, 600)
         position_y = random.randint(0, 600)
         position_m = (position_x + position_y) / 2
         width = random.randint(1, 5)
         radius = random.randint(5, position_m)
         speed = random.randint(1, 99) / 100.0
         object = radar(position_x, position_y,
                        THECOLORS[random.choice(THECOLORS.keys())], radius,
                        width, speed)
         radar_list.append(object)
     elif event.type == pygame.KEYDOWN and event.key == pygame.K_DELETE:
         unit_list = []
         radar_list = []
 green_radar.run()
 for unit_object in unit_list:
     #print ((unit_object.position[0]-green_radar.position[0])**2 + (unit_object.position[1]-green_radar.position[1])**2) - (int(green_radar.radius)**2)
     if abs(((unit_object.position[0] - green_radar.position[0])**2 +
             (unit_object.position[1] - green_radar.position[1])**2) -
            (int(green_radar.radius)**2)) <= green_radar.radius:
         #if unit_object.rect.colliderect(green_radar.image):
         unit_object.run()
         unit_object.enable = True
         if unit_object not in radar_list:
Example #9
0
# Listing_16-6_modern_art_with_color.py
# Copyright Warren & Carter Sande, 2009-2019
# Released under MIT license   https://opensource.org/licenses/mit-license.php
# ------------

import pygame, sys, random
from pygame.color import THECOLORS
pygame.init()
screen = pygame.display.set_mode([640, 480])
screen.fill([255, 255, 255])
for i in range(100):
    width = random.randint(0, 250)
    height = random.randint(0, 100)
    top = random.randint(0, 400)
    left = random.randint(0, 500)
    color_name = random.choice(list(
        THECOLORS.keys()))  # Don’t worry about how this line works for now
    color = THECOLORS[color_name]
    line_width = random.randint(1, 3)
    pygame.draw.rect(screen, color, [left, top, width, height], line_width)
pygame.display.flip()
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
pygame.quit()
Example #10
0
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from pygame.draw import rect
from pygame.color import THECOLORS as colours
from pygame.rect import Rect

from random import randint

from gridparts import row, column

nicecolours = [c for k, c in colours.items() if not ('grey' in k or 'gray' in k or 'black' in k)]
darkcolours = [x for x in nicecolours if x[0]+x[1]+x[2] < 400]

def pickColour():
    return darkcolours[randint(0, len(darkcolours)-1)]

class guiShard(object):
    def __init__(self, floating, parent, row, cols):
        
        self.floating = floating
        self.grid = floating.container().grid
        self.shardGen = floating.shardGen
        
        self.colour = pickColour()
        
        self.row = row
Example #11
0
# "Sztuka nowoczesna" w kolorze

import pygame, sys, random
from pygame.color import THECOLORS  # skorzystamy z kolorów nazwanych
pygame.init()
ekran = pygame.display.set_mode([640, 480])
ekran.fill([255, 255, 255])
for i in range(100):
    # wybieramy losowe wartości dla szerokości i wysokości prostokąta
    szerokosc = random.randint(0, 250)
    wysokosc = random.randint(0, 100)
    gora = random.randint(0, 400)
    lewa = random.randint(0, 500)

    # wybieramy losowy kolor
    nazwa_koloru = random.choice(THECOLORS.keys())
    kolor = THECOLORS[nazwa_koloru]

    # wybieramy losową szerkość linii z zakresu od 1 do 3
    szerokosc_linii = random.randint(1, 3)

    # rysujemy prostokąt
    pygame.draw.rect(ekran, kolor, [lewa, gora, szerokosc, wysokosc],
                     szerokosc_linii)

pygame.display.flip()
uruchomiony = True
while uruchomiony:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            uruchomiony = False
Example #12
0
                         Color.minmax(op(self.g, color)),
                         Color.minmax(op(self.b, color)), self.a)
        elif isinstance(color, (Color, PygameColor)):
            return Color(Color.minmax(op(self.r, color.r)),
                         Color.minmax(op(self.g, color.g)),
                         Color.minmax(op(self.b, color.b)), self.a)
        elif isinstance(color, (tuple, list)):
            return Color(Color.minmax(op(self.r, color[0])),
                         Color.minmax(op(self.g, color[1])),
                         Color.minmax(op(self.b, color[2])), self.a)

    def __add__(self, color):
        return self._math(operator.add, color)

    def __sub__(self, color):
        return self._math(operator.sub, color)

    def __mul__(self, color):
        return self._math(operator.mul, color)

    def __truediv__(self, color):
        return self._math(operator.truediv, color)


def color_item(item):
    key, value = item
    return key, Color(*value)


color = SimpleNamespace(**dict(map(color_item, THECOLORS.items())))
import pygame, random, time
from pygame.color import THECOLORS
pygame.init()
screen = pygame.display.set_mode([640, 480])
screen.fill([255, 255, 255])
for i in range(100):
    width = random.randint(0, 250)
    height = random.randint(0, 100)
    top = random.randint(0, 400)
    left = random.randint(0, 500)
    color_name = random.choice(THECOLORS.keys())
    color = THECOLORS[color_name]
    line_width = random.randint(1, 3)
    pygame.draw.rect(screen, color, [left, top, width, height], line_width)
    pygame.display.flip()
    time.sleep(0.05)

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
pygame.quit()
Example #14
0
import pygame, sys, random
from pygame.color import THECOLORS
pygame.init()
screen = pygame.display.set_mode([640, 480])
screen.fill([255, 255, 255])
for i in range(100):
    width = random.randint(0, 250)
    height = random.randint(0, 100)
    top = random.randint(0, 400)
    left = random.randint(0, 500)
    color = random.choice(list(THECOLORS.values()))
    pygame.draw.rect(screen, color, [left, top, width, height], 1)
pygame.display.flip()
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
pygame.quit()
Example #15
0
@author: zhangwei
'''
import pygame, sys, random
from pygame.color import THECOLORS

pygame.init()
screen = pygame.display.set_mode([640, 480])
screen.fill([255, 255, 255])

for i in range(100):
    width = random.randint(0, 250)
    height = random.randint(0, 100)
    top = random.randint(0, 400)
    left = random.randint(0, 400)
    color = THECOLORS[random.choice(list(THECOLORS.keys()))]
    pygame.draw.rect(screen, color, [left, top, width, height],
                     1)  # last 2 is width of line

pygame.display.flip()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
# while running:
#     for event in pygame.event.get():
#         if event.type == pygame.QUIT:
#             running = False
# pygame.quit()


import pygame, sys, random
from pygame.color import THECOLORS

pygame.init()
screen = pygame.display.set_mode([640,480])
screen.fill([255,255,255])
for i in range(100):
    width = random.randint(0,250)
    height = random.randint(0,100)
    top = random.randint(0,400)
    left = random.randint(0,500)

    color_name = random.choice(THECOLORS.keys())    # 随机生成100个矩形,大小随机,颜色随机
    color = THECOLORS[color_name]
    line_width = random.randint(1,3)
    pygame.draw.rect(screen, color, [left, top, width, height], line_width)
    # pygame.draw.rect(screen, [0,0,0], [left, top, width, height], 1)
pygame.display.flip()
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
pygame.quit()
Example #17
0
# Make "modern art" with color

import pygame, sys, random
from pygame.color import THECOLORS  # use color names
pygame.init()
screen = pygame.display.set_mode([640, 480])
screen.fill([255, 255, 255])
for i in range(100):
    # pick random numbers for rectangle size and position
    width = random.randint(0, 250)
    height = random.randint(0, 100)
    top = random.randint(0, 400)
    left = random.randint(0, 500)

    # pick a random color by name
    color_name = random.choice(THECOLORS.keys())
    color = THECOLORS[color_name]

    # pick a random line width, 1 to 3
    line_width = random.randint(1, 3)

    # draw the rectangle
    pygame.draw.rect(screen, color, [left, top, width, height], line_width)

pygame.display.flip()
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
Example #18
0
 def random_color_name(self):
     color_name = random.choice(THECOLORS.keys())
     if color_name == self.curr_color_name or color_name == self.background_color:
         return self.random_color_name()
     return color_name
Example #19
0
import collections
import numpy as np
from multiprocessing import Pool
import tensorflow as tf
import random
import pickle, sys, time
import matplotlib.pyplot as plt
import argparse
import time
from scipy.misc import imsave
from pygame.color import THECOLORS

chosen_colors = list(THECOLORS.keys())
chunksize = 20


def get_sim(cube_infos):
    from mujoco_py import load_model_from_xml, MjSim
    # generate random lighting
    light = np.random.uniform(0, 1, (3, ))

    random_perturb = np.random.uniform(-0.1, 0.1, (4, ))
    plane_color = np.clip(np.array([.9, 0, 0, 1.0]) + random_perturb, 0, 1)
    xml = """
        <mujoco>
        <!--
        <default>
            <geom material="DEFAULT_GEOM_MAT"/>
        </default>
        -->
Example #20
0
                         piece.move([pos_x - starting_position[0], pos_y - starting_position[1]])
                         piece.set_moving(True)
                         for radar_object in radar_list:
                             if radar_object.ID == piece.ID:
                                 radar_object.set_position(radar_object.position[0] + pos_x - starting_position[0], radar_object.position[1] + pos_y - starting_position[1])
                 starting_position[0] = pos_x
                 starting_position[1] = pos_y
             run_graphics()
         for piece in piece_list:
             if piece_ID == piece.ID:
                 piece.set_moving(False)
                 to_be_removed = []
                 difference = 0
                 for i in range (0, len(radar_list)):
                     if radar_list[i-difference].ID == piece.ID:
                         #del radar_list[i-difference]
                         #difference += 1
                         radar_list[i].set_generation(1, 0)
     elif event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
         position_x = random.randint (0, 600)
         position_y = random.randint (0, 600)
         position_m = (position_x + position_y)/2
         width = random.randint(1, 5)
         radius = random.randint(5, position_m)
         speed = random.randint(1, 99) / 100.0
         object = radar(position_x, position_y, THECOLORS[random.choice(THECOLORS.keys())],  radius, width, speed)
         radar_list.append(object)
     elif event.type == pygame.KEYDOWN and event.key == pygame.K_DELETE:
         unit_list = []
         radar_list = []
 run_graphics ()
 def color_picker(self):
     self.random_color = THECOLORS[random.choice(list(THECOLORS.keys()))]
     return self.random_color
Example #22
0
import pygame
from pygame.color import THECOLORS
import random

pygame.init()
screen = pygame.display.set_mode([640, 480])
screen.fill([255, 255, 255])

for i in range(100):
    axis_x = random.randint(0, 500)
    axis_y = random.randint(0, 400)
    width = random.randint(0, 250)
    height = random.randint(0, 100)

    line_width = random.randint(1, 3)

    color_key = random.choice(list(THECOLORS.keys()))
    rand_color = THECOLORS[color_key]

    myrect = pygame.Rect(axis_x, axis_y, width, height)
    pygame.draw.rect(screen, rand_color, myrect, line_width)

pygame.display.flip()

flag = True
while flag:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            flag = False

pygame.quit()