Permalink
Browse files

Merge pull request #249 from kingofools/PDFexamples

Ported remaining PDF library examples
  • Loading branch information...
2 parents 89737e2 + ed628cf commit 48987069c2e5d458523581f27e128c4eb94d379e @jdf committed on GitHub Mar 25, 2017
@@ -0,0 +1,23 @@
+"""
+Large Page.
+
+Saves one frame as a PDF with a size larger
+than the screen. When PDF is used as the renderer
+(the third parameter of size) the display window
+does not open. The file is saved to the sketch folder.
+You can open it by "Sketch->Show Sketch Folder."
+"""
+
+add_library('pdf')
+
+
+def setup():
+ size(2000, 2000, PDF, "Line.pdf")
+
+
+def draw():
+ background(255)
+ stroke(0, 20)
+ strokeWeight(20.0)
+ line(200, 0, width / 2, height)
+ exit()
@@ -0,0 +1,39 @@
+"""
+Many PDFs.
+
+Saves one PDF file each each frame while the mouse is pressed.
+When the mouse is released, the PDF creation stops.
+"""
+
+
+add_library('pdf')
+
+savePDF = False
+
+
+def setup():
+ size(600, 600)
+ frameRate(24)
+
+
+def draw():
+ if savePDF:
+ beginRecord(PDF, "lines%d.pdf" % (frameCount))
+
+ background(255)
+ stroke(0, 20)
+ strokeWeight(20.0)
+ line(mouseX, 0, width - mouseY, height)
+
+ if savePDF:
+ endRecord()
+
+
+def mousePressed():
+ global savePDF
+ savePDF = True
+
+
+def mouseReleased():
+ global savePDF
+ savePDF = False
@@ -0,0 +1,29 @@
+"""
+Many Pages.
+
+Saves a new page into a PDF file each loop through draw().
+Pressing the mouse finishes writing the file and exits the program.
+"""
+
+
+add_library('pdf')
+
+
+def setup():
+ global pdf
+ size(600, 600)
+ frameRate(4)
+ pdf = beginRecord(PDF, "Lines.pdf")
+
+
+def draw():
+ background(255)
+ stroke(0, 20)
+ strokeWeight(20.0)
+ line(mouseX, 0, width - mouseY, height)
+ pdf.nextPage()
+
+
+def mousePressed():
+ endRecord()
+ exit()
@@ -0,0 +1,36 @@
+"""
+Mouse Press.
+
+Saves one PDF of the contents of the display window
+each time the mouse is pressed.
+"""
+
+
+add_library('pdf')
+
+saveOneFrame = False
+
+
+def setup():
+ size(600, 600)
+ frameRate(24)
+
+
+def draw():
+ global saveOneFrame
+ if saveOneFrame:
+ beginRecord(PDF, "Line.pdf")
+
+ background(255)
+ stroke(0, 20)
+ strokeWeight(20.0)
+ line(mouseX, 0, width - mouseY, height)
+
+ if saveOneFrame:
+ endRecord()
+ saveOneFrame = False
+
+
+def mousePressed():
+ global saveOneFrame
+ saveOneFrame = True

0 comments on commit 4898706

Please sign in to comment.