Skip to content

Instantly share code, notes, and snippets.

@thillmann50
thillmann50 / Zen.py
Created September 19, 2014 21:00
Zen.py
# Zen
#
# Prints the Zen of Python with a color gradient.
# This demonstrates the use of the console module to set
# the output's font and color.
import console
import sys
import codecs
from colorsys import hsv_to_rgb
@thillmann50
thillmann50 / Stopwatch.py
Created September 19, 2014 21:00
Stopwatch.py
# Stopwatch
#
# A simple stopwatch that demonstrates the scene module's text
# drawing capabilities.
from scene import *
from time import time
from math import modf
from itertools import chain
import string
@thillmann50
thillmann50 / Sketch.py
Created September 19, 2014 21:00
Sketch.py
# Sketch
# A very simple drawing 'app' that demonstrates
# custom views and saving images to the camera roll.
import ui
import photos
import console
# The PathView class is responsible for tracking
# touches and drawing the current stroke.
@thillmann50
thillmann50 / Random Numbers.py
Created September 19, 2014 20:59
Random Numbers.py
# Lottery Number Generator
from random import choice
import console
#Helper function to input a number within a given range:
def input_number(prompt, min_value, max_value):
value = None
while value is None:
try:
@thillmann50
thillmann50 / Plotter.py
Created September 19, 2014 20:59
Plotter.py
# Function Plotter
import canvas
import console
from math import sin, cos, pi
def draw_grid(min_x, max_x, min_y, max_y):
w, h = canvas.get_size()
scale_x = w / (max_x - min_x)
scale_y = h / (max_y - min_y)
@thillmann50
thillmann50 / Piano.py
Created September 19, 2014 20:58
Piano.py
# Piano
#
# A simple multi-touch piano.
from scene import *
import sound
from itertools import chain
class Key (object):
def __init__(self, frame):
@thillmann50
thillmann50 / Particles.py
Created September 19, 2014 20:58
Particles.py
# Particles
#
# Create colorful bubbles by moving your fingers.
from scene import *
from random import random
from colorsys import hsv_to_rgb
class Particle (object):
def __init__(self, location):
@thillmann50
thillmann50 / MPL Plot.py
Created September 19, 2014 20:58
MPL Plot.py
# MPL Plot
# A simple demo of using matplotlib in Pythonista.
import console
console.clear()
print 'Generating plot... (this may take a little while)'
import numpy
import matplotlib.pyplot as plt
import math
@thillmann50
thillmann50 / Markdown Conversion.py
Created September 19, 2014 20:58
Markdown Conversion.py
# Markdown Conversion
#
# This script demonstrates how you can convert Markdown documents
# to HTML and view the results in the built-in browser.
import os, tempfile, codecs
import console, clipboard, webbrowser
from markdown2 import markdown
DEMO = '''
@thillmann50
thillmann50 / Image Warp.py
Created September 19, 2014 20:57
Image Warp.py
# Image Warp
#
# Demonstrates an interesting use of the image_quad function
# to distort an image based on touch.
from scene import *
from math import sqrt, sin, pi, floor
import Image
M = 16 # number of vert. and horiz. quads in the mesh (16*16=256)