Added support files
parent
cfb0b074bb
commit
6aaf5755f6
|
@ -0,0 +1,16 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from colors import *
|
||||||
|
from screen import *
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
while True:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == QUIT:
|
||||||
|
pygame.quit()
|
||||||
|
sys.exit()
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
|
if __name__ == "__main__": main()
|
|
@ -0,0 +1,127 @@
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Name: Colors
|
||||||
|
# Purpose: Color library for Python/Pygame
|
||||||
|
#
|
||||||
|
# Author: Joshua Smith
|
||||||
|
#
|
||||||
|
# Created: 08/29/2012
|
||||||
|
# Modified: 08/29/2014
|
||||||
|
# Copyright: (c) Joshua Smith 2012, Steve Clement 2014
|
||||||
|
# Licence: GNU Public License
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#----------Start of colors----------#
|
||||||
|
RED1=(50,0,0)
|
||||||
|
RED2=(75,0,0)
|
||||||
|
RED3=(100,0,0)
|
||||||
|
RED4=(125,0,0)
|
||||||
|
RED5=(150,0,0)
|
||||||
|
RED6=(175,0,0)
|
||||||
|
RED7=(200,0,0)
|
||||||
|
RED8=(225,0,0)
|
||||||
|
RED=RED9=(255,0,0)
|
||||||
|
RED10=(255,150,150)
|
||||||
|
#-----------------------------------#
|
||||||
|
ORANGE=(255,127,0)
|
||||||
|
ORANGE1=(150,75,0)
|
||||||
|
ORANGE2=(175,80,0)
|
||||||
|
ORANGE3=(200,85,0)
|
||||||
|
ORANGE4=(225,90,0)
|
||||||
|
ORANGE5=(235,95,0)
|
||||||
|
ORANGE6=(245,100,0)
|
||||||
|
ORANGE7=(255,105,0)
|
||||||
|
ORANGE8=(255,125,0)
|
||||||
|
ORANGE9=(255,150,50)
|
||||||
|
ORANGE10=(255,200,100)
|
||||||
|
#-----------------------------------#
|
||||||
|
YELLOW=(255,255,0)
|
||||||
|
YELLOW1=(75,75,0)
|
||||||
|
YELLOW2=(100,100,0)
|
||||||
|
YELLOW3=(125,125,0)
|
||||||
|
YELLOW4=(150,150,0)
|
||||||
|
YELLOW5=(175,175,0)
|
||||||
|
YELLOW6=(200,200,0)
|
||||||
|
YELLOW7=(225,225,0)
|
||||||
|
YELLOW8=(250,250,0)
|
||||||
|
YELLOW9=(255,255,100)
|
||||||
|
YELLOW10=(255,255,150)
|
||||||
|
#-----------------------------------#
|
||||||
|
GREEN1=(0,50,0)
|
||||||
|
GREEN2=(0,75,0)
|
||||||
|
GREEN3=(0,100,0)
|
||||||
|
GREEN4=(0,125,0)
|
||||||
|
GREEN5=(0,150,0)
|
||||||
|
GREEN6=(0,175,0)
|
||||||
|
GREEN7=(0,200,0)
|
||||||
|
GREEN8=(0,225,0)
|
||||||
|
GREEN=GREEN9=(0,255,0)
|
||||||
|
GREEN10=(150,255,150)
|
||||||
|
#-----------------------------------#
|
||||||
|
CYAN1=(0,50,50)
|
||||||
|
CYAN2=(0,75,75)
|
||||||
|
CYAN3=(0,100,100)
|
||||||
|
CYAN4=(0,125,125)
|
||||||
|
CYAN5=(0,150,150)
|
||||||
|
CYAN6=(0,175,175)
|
||||||
|
CYAN7=(0,200,200)
|
||||||
|
CYAN8=(0,225,225)
|
||||||
|
CYAN=CYAN9=(0,255,255)
|
||||||
|
CYAN10=(150,255,255)
|
||||||
|
#-----------------------------------#
|
||||||
|
BLUE1=(0,0,50)
|
||||||
|
BLUE2=(0,0,75)
|
||||||
|
BLUE3=(0,0,100)
|
||||||
|
BLUE4=(0,0,125)
|
||||||
|
BLUE5=(0,0,150)
|
||||||
|
BLUE6=(0,0,175)
|
||||||
|
BLUE7=(0,0,200)
|
||||||
|
BLUE8=(0,0,225)
|
||||||
|
BLUE=BLUE9=(0,0,255)
|
||||||
|
BLUE10=(125,125,255)
|
||||||
|
#-----------------------------------#
|
||||||
|
PURPLE=(128,0,128)
|
||||||
|
PURPLE1=(50,0,50)
|
||||||
|
PURPLE2=(75,0,75)
|
||||||
|
PURPLE3=(100,0,100)
|
||||||
|
PURPLE4=(125,0,125)
|
||||||
|
PURPLE5=(150,0,150)
|
||||||
|
PURPLE6=(175,0,175)
|
||||||
|
PURPLE7=(200,0,200)
|
||||||
|
PURPLE8=(225,0,225)
|
||||||
|
PURPLE9=(240,0,240)
|
||||||
|
PURPLE10=(255,150,255)
|
||||||
|
#-----------------------------------#
|
||||||
|
BROWN1=(50,25,0)
|
||||||
|
BROWN2=(75,38,0)
|
||||||
|
BROWN3=(100,50,0)
|
||||||
|
BROWN4=(125,62,0)
|
||||||
|
BROWN=BROWN5=(150,75,0)
|
||||||
|
BROWN6=(175,88,0)
|
||||||
|
BROWN7=(200,101,0)
|
||||||
|
BROWN8=(225,114,0)
|
||||||
|
BROWN9=(250,127,0)
|
||||||
|
BROWN10=(255,140,25)
|
||||||
|
#-----------------------------------#
|
||||||
|
GRAY=(128,128,128)
|
||||||
|
GRAY1=(25,25,25)
|
||||||
|
GRAY2=(50,50,50)
|
||||||
|
GRAY3=(75,75,75)
|
||||||
|
GRAY4=(100,100,100)
|
||||||
|
GRAY5=(125,125,125)
|
||||||
|
GRAY6=(150,150,150)
|
||||||
|
GRAY7=(175,175,175)
|
||||||
|
GRAY8=(200,200,200)
|
||||||
|
GRAY9=(225,225,225)
|
||||||
|
GRAY10=(245,245,245)
|
||||||
|
#-----------------------------------#
|
||||||
|
PINK=(255,192,203)
|
||||||
|
#-----------------------------------#
|
||||||
|
VIOLET=(127,0,255)
|
||||||
|
#-----------------------------------#
|
||||||
|
MAGENTA=(255,0,255)
|
||||||
|
#-----------------------------------#
|
||||||
|
WHITE=(255,255,255)
|
||||||
|
BLACK=(0,0,0)
|
||||||
|
#-----------End of colors-----------#
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# by Timothy Downs, inputbox written for my map editor
|
||||||
|
|
||||||
|
# Edited to be python3 compatible by @SteveClement on Twitter
|
||||||
|
# Example version is with additional comments
|
||||||
|
|
||||||
|
# This program needs a little cleaning up
|
||||||
|
# It ignores the shift key
|
||||||
|
# And, for reasons of my own, this program converts "-" to "_"
|
||||||
|
|
||||||
|
# A program to get user input, allowing backspace etc
|
||||||
|
# shown in a box in the middle of the screen
|
||||||
|
#
|
||||||
|
# Called by:
|
||||||
|
#
|
||||||
|
# import inputboxExample
|
||||||
|
# answer = inputbox.ask(screen, "Your name")
|
||||||
|
#
|
||||||
|
# Only near the center of the screen is blitted to
|
||||||
|
#
|
||||||
|
# Obviously inputboxExample.py needs to be in the same directory you started you python from
|
||||||
|
|
||||||
|
import pygame, pygame.font, pygame.event, pygame.draw, string
|
||||||
|
from pygame.locals import *
|
||||||
|
|
||||||
|
def get_key():
|
||||||
|
while True:
|
||||||
|
event = pygame.event.poll()
|
||||||
|
if event.type == KEYDOWN:
|
||||||
|
return event.key
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def display_box(screen, message):
|
||||||
|
"Print a message in a box in the middle of the screen, no font selected, no fancy colors"
|
||||||
|
fontobject = pygame.font.Font(None,18)
|
||||||
|
# Draw a RED (r255,g0,b0) rectangle
|
||||||
|
pygame.draw.rect(screen, (255,0,0),
|
||||||
|
((screen.get_width() / 2) - 100,
|
||||||
|
(screen.get_height() / 2) - 10,
|
||||||
|
200,20), 0)
|
||||||
|
# Draw a GREEN (r0,g255,b0) rectangle
|
||||||
|
pygame.draw.rect(screen, (0,255,0),
|
||||||
|
((screen.get_width() / 2) - 102,
|
||||||
|
(screen.get_height() / 2) - 12,
|
||||||
|
204,24), 1)
|
||||||
|
if len(message) != 0:
|
||||||
|
# blit a WHITE (r255,g255,b255) fontobject with the contents of the message variable to the screen where we can enter Text
|
||||||
|
screen.blit(fontobject.render(message, 1, (255,255,255)),
|
||||||
|
((screen.get_width() / 2) - 100, (screen.get_height() / 2) - 10))
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
def ask(screen, question):
|
||||||
|
"ask(screen, question) -> answer"
|
||||||
|
# Init font engine
|
||||||
|
pygame.font.init()
|
||||||
|
current_string = []
|
||||||
|
# call display_box() function
|
||||||
|
display_box(screen, question + ": " + "".join(current_string))
|
||||||
|
# Main endless loop untill we press the Return/Enter key (K_RETURN)
|
||||||
|
while True:
|
||||||
|
# Get pressed key
|
||||||
|
inkey = get_key()
|
||||||
|
# Check what key was pressed
|
||||||
|
if inkey == K_BACKSPACE:
|
||||||
|
# remove one character from current_string
|
||||||
|
current_string = current_string[0:-1]
|
||||||
|
elif inkey == K_RETURN:
|
||||||
|
break
|
||||||
|
elif inkey == K_MINUS:
|
||||||
|
# appent an underscore if minus (-) entered
|
||||||
|
current_string.append("_")
|
||||||
|
elif inkey <= 127:
|
||||||
|
# All other characters get appended to current_string
|
||||||
|
current_string.append(chr(inkey))
|
||||||
|
# Add characters to current_string and display them on the screen
|
||||||
|
display_box(screen, question + ": " + "".join(current_string))
|
||||||
|
# Once enter pressed return the contents of current string
|
||||||
|
return "".join(current_string)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# set the screen size to 320x240
|
||||||
|
screen = pygame.display.set_mode((320,240))
|
||||||
|
# Print the return value of the function ask()
|
||||||
|
print((ask(screen, "Please type your Name") + " was entered"))
|
||||||
|
|
||||||
|
if __name__ == '__main__': main()
|
|
@ -0,0 +1,53 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# Move a single pixel around the screen without crashing against the borders.
|
||||||
|
# (and exit the program once crashed)
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from colors import *
|
||||||
|
from screen import *
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# Position of the pixel.
|
||||||
|
x = WIDTH / 2
|
||||||
|
y = HEIGHT / 2
|
||||||
|
|
||||||
|
# Direction of the pixel.
|
||||||
|
dir_x = 0
|
||||||
|
dir_y = -1
|
||||||
|
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
running = True
|
||||||
|
|
||||||
|
while running:
|
||||||
|
x += dir_x
|
||||||
|
y += dir_y
|
||||||
|
|
||||||
|
if x <= 0 or x >= WIDTH or y <= 0 or y >= HEIGHT:
|
||||||
|
print("Crash!")
|
||||||
|
running = False
|
||||||
|
|
||||||
|
screen.fill(BLACK)
|
||||||
|
screen.set_at((int(x), int(y)), WHITE)
|
||||||
|
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
running = False
|
||||||
|
elif event.type == pygame.KEYDOWN:
|
||||||
|
if event.key == pygame.K_UP:
|
||||||
|
dir_x = 0
|
||||||
|
dir_y = -1
|
||||||
|
elif event.key == pygame.K_DOWN:
|
||||||
|
dir_x = 0
|
||||||
|
dir_y = 1
|
||||||
|
elif event.key == pygame.K_LEFT:
|
||||||
|
dir_x = -1
|
||||||
|
dir_y = 0
|
||||||
|
elif event.key == pygame.K_RIGHT:
|
||||||
|
dir_x = 1
|
||||||
|
dir_y = 0
|
||||||
|
|
||||||
|
pygame.display.flip()
|
||||||
|
clock.tick(120)
|
||||||
|
|
||||||
|
if __name__ == "__main__": main()
|
|
@ -0,0 +1,17 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import pygame
|
||||||
|
from pygame.locals import *
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
|
||||||
|
displayInfo = pygame.display.Info()
|
||||||
|
zoom = 1.3
|
||||||
|
|
||||||
|
WIDTH = int(displayInfo.current_w / zoom)
|
||||||
|
HEIGHT = int(displayInfo.current_h / zoom)
|
||||||
|
|
||||||
|
# this will be the Surface you work on (in the docs referenced as Surface)
|
||||||
|
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||||
|
|
||||||
|
pygame.display.set_caption("Caption of your window")
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import pygame
|
||||||
|
from pygame.locals import *
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
|
||||||
|
displayInfo = pygame.display.Info()
|
||||||
|
zoom = 1.3
|
||||||
|
|
||||||
|
WIDTH = int(displayInfo.current_w / zoom)
|
||||||
|
HEIGHT = int(displayInfo.current_h / zoom)
|
||||||
|
|
||||||
|
# this will be the Surface you work on (in the docs referenced as Surface)
|
||||||
|
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||||
|
screenAlpha = screen.convert_alpha()
|
||||||
|
|
||||||
|
pygame.display.set_caption("Pink Unicorns are waiting but what is the HOTkey?!?!?!1111")
|
|
@ -0,0 +1,84 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import sys
|
||||||
|
from colors import *
|
||||||
|
from screen import *
|
||||||
|
|
||||||
|
global fullS
|
||||||
|
fullS = False
|
||||||
|
|
||||||
|
def toggle_fullscreen():
|
||||||
|
global fullS
|
||||||
|
fullS = True
|
||||||
|
screen = pygame.display.get_surface()
|
||||||
|
tmp = screen.convert()
|
||||||
|
caption = pygame.display.get_caption()
|
||||||
|
cursor = pygame.mouse.get_cursor() # Duoas 16-04-2007
|
||||||
|
|
||||||
|
w,h = screen.get_width(),screen.get_height()
|
||||||
|
flags = screen.get_flags()
|
||||||
|
bits = screen.get_bitsize()
|
||||||
|
|
||||||
|
pygame.display.quit()
|
||||||
|
pygame.display.init()
|
||||||
|
|
||||||
|
screen = pygame.display.set_mode((w,h),flags^FULLSCREEN,bits)
|
||||||
|
screen.blit(tmp,(0,0))
|
||||||
|
pygame.display.set_caption(*caption)
|
||||||
|
|
||||||
|
pygame.key.set_mods(0) #HACK: work-a-round for a SDL bug??
|
||||||
|
|
||||||
|
pygame.mouse.set_cursor( *cursor ) # Duoas 16-04-2007
|
||||||
|
|
||||||
|
return screen
|
||||||
|
|
||||||
|
def toggle_window():
|
||||||
|
global fullS
|
||||||
|
fullS = False
|
||||||
|
screen = pygame.display.get_surface()
|
||||||
|
tmp = screen.convert()
|
||||||
|
caption = pygame.display.get_caption()
|
||||||
|
cursor = pygame.mouse.get_cursor() # Duoas 16-04-2007
|
||||||
|
|
||||||
|
w,h = screen.get_width(),screen.get_height()
|
||||||
|
flags = screen.get_flags()
|
||||||
|
bits = screen.get_bitsize()
|
||||||
|
|
||||||
|
pygame.display.quit()
|
||||||
|
pygame.display.init()
|
||||||
|
|
||||||
|
print((int(w/1.3),int(h/1.3)))
|
||||||
|
# flags/bits overflows BUG : OverflowError: signed integer is greater than maximum
|
||||||
|
## -> FixMe screen = pygame.display.set_mode((int(w/1.3),int(h/1.3)),flags,bits)
|
||||||
|
|
||||||
|
# This works, BUT, after toggling a few times window shrinks and shrinks and shrinks, need more clever "zoom" implementation
|
||||||
|
screen = pygame.display.set_mode((int(w/1.3),int(h/1.3)))
|
||||||
|
screen.blit(tmp,(0,0))
|
||||||
|
pygame.display.set_caption(*caption)
|
||||||
|
|
||||||
|
pygame.key.set_mods(0) #HACK: work-a-round for a SDL bug??
|
||||||
|
|
||||||
|
pygame.mouse.set_cursor( *cursor ) # Duoas 16-04-2007
|
||||||
|
|
||||||
|
return screen
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
global fullS
|
||||||
|
while True:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if (event.type is KEYDOWN and event.key == K_RETURN and (event.mod&(KMOD_LALT|KMOD_RALT)) != 0):
|
||||||
|
if fullS == True:
|
||||||
|
toggle_window()
|
||||||
|
else:
|
||||||
|
toggle_fullscreen()
|
||||||
|
if (event.type == QUIT) or (event.type == KEYDOWN and event.key == K_ESCAPE):
|
||||||
|
exit()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
screen = pygame.display.get_surface()
|
||||||
|
import random
|
||||||
|
rr = random.randrange
|
||||||
|
screen.fill((rr(0,256),rr(0,256),rr(0,256)),(rr(0,WIDTH),rr(0,HEIGHT),32,32))
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
if __name__ == '__main__': main()
|
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import sys, time
|
||||||
|
from colors import *
|
||||||
|
from screen import *
|
||||||
|
|
||||||
|
def main():
|
||||||
|
ck = (127, 33, 33)
|
||||||
|
size = 25
|
||||||
|
while True:
|
||||||
|
time.sleep(0.5)
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == QUIT:
|
||||||
|
pygame.quit()
|
||||||
|
sys.exit()
|
||||||
|
if event.type == MOUSEMOTION:
|
||||||
|
s = pygame.Surface((50,50))
|
||||||
|
# first, "erase" the surface by filling it with a color and
|
||||||
|
# setting this color as colorkey, so the surface is empty
|
||||||
|
s.fill(ck)
|
||||||
|
s.set_colorkey(ck)
|
||||||
|
|
||||||
|
pygame.draw.circle(s, (RED), (size, size), size, 4)
|
||||||
|
# after drawing the circle, we can set the
|
||||||
|
# alpha value (transparency) of the surface
|
||||||
|
s.set_alpha(75)
|
||||||
|
|
||||||
|
x, y = pygame.mouse.get_pos()
|
||||||
|
screen.blit(s, (x-size, y-size))
|
||||||
|
pygame.event.poll()
|
||||||
|
pygame.display.flip()
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
|
if __name__ == "__main__": main()
|
|
@ -0,0 +1,55 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import urllib.request, sys, shutil, os
|
||||||
|
from colors import *
|
||||||
|
from screenAlpha import *
|
||||||
|
|
||||||
|
file_name = 'mlp.png'
|
||||||
|
|
||||||
|
def main():
|
||||||
|
try:
|
||||||
|
os.path.isfile(file_name)
|
||||||
|
print("Howdy you already got the file! Good.")
|
||||||
|
except:
|
||||||
|
MLP = "http://localhost.lu/MLP.png"
|
||||||
|
with urllib.request.urlopen(MLP) as response, open(file_name, 'wb') as out_file:
|
||||||
|
shutil.copyfileobj(response, out_file)
|
||||||
|
|
||||||
|
MLPcolor = (255,192,192,128)
|
||||||
|
|
||||||
|
image = pygame.image.load(file_name)
|
||||||
|
image = pygame.transform.scale(image, (200, 200))
|
||||||
|
image.set_colorkey((255,255,255))
|
||||||
|
alpha = 75
|
||||||
|
image.set_alpha(alpha)
|
||||||
|
screen.fill(MLPcolor)
|
||||||
|
screen.blit(image, (0,0))
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == QUIT:
|
||||||
|
pygame.quit()
|
||||||
|
sys.exit()
|
||||||
|
elif event.type == KEYDOWN:
|
||||||
|
if event.key == K_UP:
|
||||||
|
alpha += 1
|
||||||
|
image.set_alpha(alpha)
|
||||||
|
print("Alpha wants to be: {}".format(alpha))
|
||||||
|
elif event.key == K_DOWN:
|
||||||
|
alpha -= 1
|
||||||
|
image.set_alpha(alpha)
|
||||||
|
print("Alpha wants to be: {}".format(alpha))
|
||||||
|
elif event.key == K_LEFT:
|
||||||
|
dir_x = -1
|
||||||
|
dir_y = 0
|
||||||
|
elif event.key == K_RIGHT:
|
||||||
|
dir_x = 1
|
||||||
|
dir_y = 0
|
||||||
|
elif event.key == K_q:
|
||||||
|
pygame.quit()
|
||||||
|
sys.exit()
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
|
if __name__ == "__main__": main()
|
||||||
|
|
Loading…
Reference in New Issue