Skip to content

Instantly share code, notes, and snippets.

@jsbain
jsbain / Map View Demo2.py
Created May 10, 2018 07:41
Map View Demo2.py
# coding: utf-8
'''
NOTE: This requires Pythonista 3
Demo of a custom ui.View subclass that embeds a native map view using MapKit (via objc_util). Tap and hold the map to drop a pin.
The MapView class is designed to be reusable, but it doesn't implement *everything* you might need. I hope that the existing methods give you a basic idea of how to add new capabilities though. For reference, here's Apple's documentation about the underlying MKMapView class: http://developer.apple.com/library/ios/documentation/MapKit/reference/MKMapView_Class/index.html
adapted from original code by omz
@jsbain
jsbain / boggle.py
Created April 12, 2018 09:23
boggle.py
import ui
import random
from math import radians
import time
from functools import partial
class Die(ui.View):
def __init__(self,faces='ABCDEF',*args,**kwargs):
self.faces=faces
self._face_idx=0
ui.View.__init__(self,*args,**kwargs)
@jsbain
jsbain / Untitled.py
Created April 10, 2018 16:44
Untitled.py
import ui, random
from functools import partial
colors=['salmon','orange','yellow','turquoise','gray','white']
N=4 #size if grid
dicestr='AACIOT,ABILTY,ABJMOQ,ACDEMP,ACELRS,ADENVZ,AHMORS,BIFORX,DENOSW,DKNOTU,EEFHIY,EGKLUY,EGINTV,EHINPS,ELPSTU,GILRUW'.split(',')
dice=[[face if not face=='Q' else 'Qu' for face in die ] for die in dicestr]
@jsbain
jsbain / Untitled.py
Created April 10, 2018 15:37
Untitled.py
import ui, random
from functools import partial
colors=['salmon','orange','yellow','turquoise','gray','white']
N=4 #size if grid
def animate_button(button,num_rolls):
''' returns a callable, which when called will ui.animate to change title and color, with a recursive completion for a total of num_rolls'''
def ani():
i=random.randrange(6)
button.title=str(i+1)
@jsbain
jsbain / Untitled.py
Created April 10, 2018 14:41
Untitled.py
import ui, random
from functools import partial
colors=['salmon','orange','yellow','turquoise','gray','white']
N=4 #size if grid
def animate_button(button,num_rolls):
''' returns a callable, which when called will ui.animate to change title and color, with a recursive completion for a total of num_rolls'''
def ani():
i=random.randrange(6)
button.title=str(i+1)
@jsbain
jsbain / Untitled.py
Created April 10, 2018 14:36
Untitled.py
import ui, random
from functools import partial
colors=['salmon','orange','yellow','turquoise','gray','white']
def animate_button(button,num_rolls):
''' returns a callable, which when called will ui.animate to change title and color, with a recursive completion for a total of num_rolls'''
def ani():
i=random.randrange(6)
button.title=str(i+1)
button.bg_color=colors[i]
def finish():
@jsbain
jsbain / Sketch.py
Created April 10, 2018 13:24
Sketch.py
'''
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
@jsbain
jsbain / Tutorial Part 3a.py
Created April 9, 2018 02:31
Tutorial Part 3a.py
# coding: utf-8
'''
Part 3 -- Walk Cycle and Sound Effects 🏃
In the previous part, our little alien moved left and right, but it all looked a bit unnatural. It might be different for aliens, but we usually don't just slide on the ground without moving our feet, while always looking in the same direction...
We're going to add a very simple walk cycle animation in this part -- and while we're at it, some footstep sounds too.
The changes in this part are numbered. You can navigate between them using the popup menu that appears when you tap the filename.
'''
@jsbain
jsbain / Tutorial Part 3a.py
Created April 8, 2018 22:58
Tutorial Part 3a.py
# coding: utf-8
'''
Part 3 -- Walk Cycle and Sound Effects 🏃
In the previous part, our little alien moved left and right, but it all looked a bit unnatural. It might be different for aliens, but we usually don't just slide on the ground without moving our feet, while always looking in the same direction...
We're going to add a very simple walk cycle animation in this part -- and while we're at it, some footstep sounds too.
The changes in this part are numbered. You can navigate between them using the popup menu that appears when you tap the filename.
'''
@jsbain
jsbain / Untitled_192.py
Created April 1, 2018 08:53
Untitled_192.py
from scene import *
import math
class myscene(Scene):
def setup(self):
a=SpriteNode('plf:LaserPurple')
self.add_child(a)
self.a=a
a.position=(0,300)
a.vel=[180,120]