Skip to content

Instantly share code, notes, and snippets.

@typemytype
Created November 6, 2014 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typemytype/7ac526fedffa2fc3ceb0 to your computer and use it in GitHub Desktop.
Save typemytype/7ac526fedffa2fc3ceb0 to your computer and use it in GitHub Desktop.
drawBot in RoboFont
from drawBot import *
from drawBot.ui.drawView import DrawView
from vanilla import *
class Previewer(object):
def __init__(self):
# setup the window
self.w = Window((400, 400), "Previewer", minSize=(200, 200))
# add a slider
self.w.slider = Slider((10, 10, -10, 22), callback=self.sliderCallback, value=.5, minValue=0, maxValue=1)
# add a pdf viewer
self.w.result = DrawView((0, 40, -0, -0))
# call the callback so it will draw just before opening the window
self.sliderCallback(self.w.slider)
# open the window
self.w.open()
def sliderCallback(self, sender):
# get the value from the slider
value = sender.get()
# initiate a new drawing
newDrawing()
# set a size
size(200, 200)
fill(value, 1-value, 0)
# draw a rectangle, the width and height is related to the slider
rect(10, 10, (width() - 20) * value, (height() - 20) * value)
# get the pdf document
pdfDocument = pdfImage()
# set the pdf document into the pdf viewer
self.w.result.setPDFDocument(pdfDocument)
Previewer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment