Skip to content

Instantly share code, notes, and snippets.

@typemytype
typemytype / lineToCurvesConverter.py
Created May 10, 2016 14:42
convert lines to curves
from fontTools.pens.basePen import BasePen
from lib.tools.bezierTools import calculateAngle
from math import sin, cos, radians
class MyPen(BasePen):
def __init__(self, outpen, distance, insice):
BasePen.__init__(self, None)
@typemytype
typemytype / randomColorAppIcon.py
Created May 10, 2016 13:55
add random color to app icon
from AppKit import *
from lib.tools.misc import randomColor
# get the application icon image
icon = NSApp().applicationIconImage()
# get the size
w, h = icon.size()
# make a rect with the size of the image
imageRect = NSMakeRect(0, 0, w, h)
# create a new image with the same size
from mojo.tools import IntersectGlyphWithLine
# get the current glypyh
g = CurrentGlyph()
# intersect the glyph with a line
# it will return a list with all intersection points
print IntersectGlyphWithLine(g, ((0, 200), (600, 200)))
@typemytype
typemytype / marginMover.py
Created February 21, 2016 14:17
Move margins while dragging with a trigger
from mojo.events import addObserver
class MarginMover(object):
leftMarginKeyDownTrigger = "y" # change this to make it fit with your hot keys
rightMarginKeyDownTrigger = "u" # change this to make it fit with your hot keys
def __init__(self):
# subscribe to key and mouse events
addObserver(self, "keyDown", "keyDown")
@typemytype
typemytype / fractals_triangle.py
Last active January 18, 2016 22:10
Fractals are cool!
# create a reusable bezierPath with a triangle
triangle = BezierPath()
triangle.moveTo((0, 0))
triangle.lineTo((width(), 0))
triangle.lineTo((width()/2, height()))
triangle.closePath()
# set the maximum recusions
maxSteps = 7
@typemytype
typemytype / blurryfyer.py
Created November 23, 2015 09:57
apply filters on any view in RoboFont (example is a space center)
"""
Apply any filter on any view.
CIFilter reference: https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/filter/ci/CIAccordionFoldTransition
"""
from mojo.UI import CurrentSpaceCenter
from AppKit import *
from mojo.events import addObserver
from AppKit import NSSound, NSURL
path = u"http://soundbible.com/grab.php?id=1995&type=mp3"
url = NSURL.URLWithString_(path)
sound = NSSound.alloc().initWithContentsOfURL_byReference_(url, False)
class SomeMotivation(object):
@typemytype
typemytype / baseGlyphJumper.py
Last active August 29, 2015 14:25
Open the selected component base glyph in a separate glyph window
from mojo.UI import OpenGlyphWindow
from mojo.events import addObserver
class BaseGlyphJumper(object):
def __init__(self):
# add observer on key down
addObserver(self, "keyDown", "keyDown")
@typemytype
typemytype / searchImage.py
Last active August 29, 2015 14:24
get image from google search and draw it
# DrawBot example
import urllib2
import json
searchTerm = 'DrawBot app is AWESOME'
## get data from google
fetcher = urllib2.build_opener()
startIndex = "0"
from drawBot import *
from drawBot.ui.drawView import DrawView
from vanilla import *
class DrawBotViewer(object):
def __init__(self):
# create a window
self.w = Window((400, 400), minSize=(200, 200))