Skip to content

Instantly share code, notes, and snippets.

@jsbain
jsbain / mapscene.py
Last active August 18, 2020 18:56
mapscene.py
from scene import *
import sound
import random
import math
A = Action
mapsprites=['plc:Brown_Block','plc:Dirt_Block','plc:Grass_Block','plc:Plain_Block',]
def choose_random_node():
tx=random.choice(mapsprites)
sn=SpriteNode(tx)
@jsbain
jsbain / simple_recorder.py
Created June 21, 2020 09:23
simple_recorder.py
import sound,ui
from sound import Recorder
from sound import Player
sound.set_volume(1)
filename='4.m4a' #could have this come from a textfield in the ui...
play_image=ui.Image('iob:play_256')
stop_image=ui.Image('iob:stop_256')
record_image=ui.Image('iob:ios7_circle_filled_256')
@jsbain
jsbain / simple_recorder.py
Created June 21, 2020 09:07
simple_recorder.py
import sound,ui
from sound import Recorder
from sound import Player
sound.set_volume(1)
filename='4.m4a' #could have this come from a textfield in the ui...
play_image=ui.Image('iob:play_256')
stop_image=ui.Image('iob:stop_256')
record_image=ui.Image('iob:ios7_circle_filled_256')
@jsbain
jsbain / detector.py
Created June 11, 2020 08:36
detector.py
# coding: utf-8
# based on Cethric's image capture gist....
FRAME_PROC_INTERVAL=15 #num frames to skip. 1=go as fast as possible, 5=every fifth frame
import ui
from objc_util import *
import ctypes
from objc_util import autoreleasepool
AVCaptureDevice = ObjCClass('AVCaptureDevice')
AVCaptureDeviceInput = ObjCClass('AVCaptureDeviceInput')
AVCaptureVideoDataOutput = ObjCClass('AVCaptureVideoDataOutput')
@jsbain
jsbain / customMenuItem.py
Created April 4, 2020 07:09
customMenuItem.py
from objc_util import *
from objc_hacks import swizzle # github.com/jsbain/objc_hacks.git
NSNotificationCenter=ObjCClass('NSNotificationCenter')
class PYUIMenuItem(object):
'''Base class representing a uimenuitem, which can be added to the manager.
Each item must have a title string, a selector name, and an action callback.
Must define subclasses with __selector__ field, __title__ string
Action callback must be of form
@jsbain
jsbain / customMenuItem.py
Created April 3, 2020 17:05
customMenuItem.py
from objc_util import *
from objc_hacks import swizzle # github.com/jsbain/objc_hacks.git
NSNotificationCenter=ObjCClass('NSNotificationCenter')
class PYUIMenuItem(object):
'''Base class representing a uimenuitem, which can be added to the manager.
Each item must have a title string, a selector name, and an action callback.
Must define subclasses with __selector__ field, __title__ string
Action callback must be of form
@jsbain
jsbain / customMenuItem.py
Created April 3, 2020 16:55
customMenuItem.py
from objc_util import *
from objc_hacks import swizzle # github.com/jsbain/objc_hacks.git
NSNotificationCenter=ObjCClass('NSNotificationCenter')
class PYUIMenuItem(object):
'''Base class representing a uimenuitem, which can be added to the manager.
Each item must have a title string, a selector name, and an action callback.
Must define subclasses with __selector__ field, __title__ string
Action callback must be of form
@jsbain
jsbain / Untitled_20.py
Created March 26, 2019 15:54
Untitled_20.py
from scene import *
from math import floor
class SceneTimers(Scene):
def setup(self):
t1=LabelNode()
t2=LabelNode()
t3=LabelNode()
@jsbain
jsbain / plotView.py
Created March 17, 2019 20:24
plotView.py
import ui
import numpy as np
W=1024
import time
from objc_util import *
CAShapeLayer=ObjCClass('CAShapeLayer')
@jsbain
jsbain / audioengine.py
Created March 14, 2019 02:15
audioengine.py
from objc_util import *
AVAudioEngine = ObjCClass('AVAudioEngine').alloc().init()
AVAudioSession = ObjCClass('AVAudioSession')
AVAudioRecorder = ObjCClass('AVAudioRecorder')
shared_session = AVAudioSession.sharedInstance()
category_set= shared_session.setCategory_withOptions_error_(
ns('AVAudioSessionCategoryRecord'),
0x2, #duckothers
None)