Skip to content

Instantly share code, notes, and snippets.

@nataliefreed
Created September 9, 2014 04:46
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 nataliefreed/b93b42987a5c0ec48eeb to your computer and use it in GitHub Desktop.
Save nataliefreed/b93b42987a5c0ec48eeb to your computer and use it in GitHub Desktop.
This Processing example saves out two images of a star, a PDF (vector) and a PNG (bitmap/raster).
//Art and Science of Computing Fall 14
//This example saves out two images of a star, a PDF (vector) and a PNG (bitmap/raster).
//More PDF export options at: http://processing.org/reference/libraries/pdf/
import processing.pdf.*;
//using two arrays is one improvement on individually naming each point!
int[] xPositions = { 90, 251, 51, 213, 151, 90 };
int[] yPositions = { 230, 112, 112, 229, 39, 230 };
size(300, 300);
//begin creating the PDF
beginRecord(PDF, "vector.pdf");
strokeWeight(6);
//begin drawing the star shape by placing vertices
beginShape();
//This is a for loop. This one begins by setting the variable i to 0,
//and increasing it by 1 after each repetition ("iteration") of the loop.
//It runs the code inside the { } repeatedly, until the statement i<xPositions.length
//("i is less than the length of the xPositions array") no longer holds true.
for(int i=0;i<xPositions.length;i++)
{
vertex(xPositions[i], yPositions[i]);
}
//the star shape is completed
endShape();
//record and save the bitmap image
saveFrame("bitmap.png");
//record and save the PDF (a vector image)
endRecord();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment