Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

import time
import pygame
WHITE = 255, 255, 255
BLACK = 0, 0, 0
whole_note_image = pygame.Surface((20, 20))
whole_note_rect = whole_note_image.get_rect()
whole_note_image.fill(WHITE)
@pathunstrom
pathunstrom / game.py
Created April 30, 2018 18:38
Ways to count player lives.
class Game:
def __init__(self):
self.player = Player()
self.extra_lives = 3
self.running = False
def run(self):
self.running = True
while self.running
@pathunstrom
pathunstrom / pygame_ants.py
Created April 18, 2018 23:36
A sample pygame application
import pprint
import pygame
pygame.init()
BACKGROUND_COLOR = 184, 122, 0
display = pygame.display.set_mode((600, 400))
display.fill(BACKGROUND_COLOR)
@pathunstrom
pathunstrom / main.py
Created March 8, 2018 01:18
simple example how to handle json in Flask
from flask import Flask, render_template_string, jsonify, request
app = Flask("jsontest")
@app.route("/post", methods=["POST"])
def post():
return jsonify(request.json)
@pathunstrom
pathunstrom / self_repr.py
Last active February 8, 2018 20:46
A very simple auto repr
from inspect import signature
class Example:
def __repr__(self):
val = lambda x: f"{x}={getattr(self, x)!r}"
parameters = ", ".join(val(param) for param in signature(type(self)).parameters)
return f"{type(self).__name__}({parameters})"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<header><h1>Look at me, I'm a header!</h1></header>
<div class="board">
<div class="box"></div>
@pathunstrom
pathunstrom / index.html
Created January 11, 2018 01:02
Dual Movement
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.box {
height: 100px;
width: 100px;
top: 100px;
@pathunstrom
pathunstrom / main
Created December 30, 2017 02:20
Ballistic bullets
import pygame, sys
import math
from ppb_vector import Vector2 as Vector
#Colours
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (217, 231, 249)
GOLD = (255, 255, 0)
PURPLE = (202, 90, 155)
@pathunstrom
pathunstrom / sound.py
Created December 19, 2017 01:16
Pygame sine waves
import pygame
from itertools import cycle
import math
RESOLUTION = (800, 800)
BITS = 16
MAX_SAMPLE = 2**(BITS - 1) - 1
LEFT_FREQUENCY = 0
RIGHT_FREQUENCY = 262
@pathunstrom
pathunstrom / sounds.py
Created November 30, 2017 06:00
Pygame Sounds manually building buffers.
import pygame
from itertools import cycle
import math
RESOLUTION = (800, 800)
BITS = 16
MAX_SAMPLE = 2**(BITS - 1) - 1
LEFT_FREQUENCY = 0
RIGHT_FREQUENCY = 450