Making my way through the Offscreen drawing recipe from the Processing 2 Creative programming cookbook source code on GitHub. In this recipe I learned how to:
- declare a PGraphics object and then initialise it with the createGraphics function inside the setup function.
- use the createGraphics function to create a new transparent image to be drawn on and the beginDraw and endDraw functions to start and stop drawing on the image. For this Sketch, strokes and lines are drawn on the PGraphics object. To do this, they needed to be prefixed with a variable (pg).
The display window is cleared every time the mouse is pressed. The if test inside the mousePressed function specifies there’s a 50 percent chance the new background will be black or white.
Making my way through the Manipulating SVG files recipe from the Processing 2 Creative programming cookbook source code on GitHub. In this recipe I learned:
- more about using the shape function to draw shapes in the display window
- how to declare the PShape object and create custom variables (snowFlake, small1 to small6 and big1) and the disableStyle, enableStyle, fill and stroke functions to manipulate discrete parts of the SVG loaded into the Sketch.
- how to use getChild to get text (small1 to small6) from the id attribute of each shape in the SVG file.
Making my way through the Drawing custom shapes recipe from the Processing 2 Creative programming cookbook source code on GitHub. In this recipe I learned about some of Processing’s funky functions that can be used to draw custom shapes such as a star and a flower. I also learned about the vertex, beginShape and endShape functions.
Making my way through the Calculating points on a curve recipe from the Processing 2 Creative programming cookbook source code on GitHub.
In this recipe I learned how to use the bezierPoint and curvePoint functions to calculate points on curves and splines. bezierPoint uses five parameters. The first four are coordinates for the anchor and control points (40, 120, 300, 600) of the bezier curve and the fifth is parameter is a number between 0 and 1. This Sketch uses noise to generate the number. curvePoint works in a similar way to bezierPoint, except it’s for Catmull-Rom splines. I also learned how to use:
- the first four parameters and the last four parameters of the bezier curve’s anchor points as the parameters for the red lines used to simulate the curve’s ‘handle’
- noise to animate the point as it’s moved along the curve
- rectMode to change the location from which the rectangle is drawn. For this example, CENTER is used to specify the first two parameters of each rect (120, 40 and 300, 240) as the shape’s centre point.
Making my way through the Drawing curves recipe from the Processing 2 Creative programming cookbook source code on GitHub.
In this recipe I learned how to use the bezier and curve functions to draw Bezier curves and Catmull-rom splines in the display window. For the Bezier curves in this example, 0 and 20 are the coordinates for the first anchor point. 50 and 10 are the coordinates for the first control point. 80 and 100 are the coordinates for the second control point, and the 30 and 200 are the coordinates for the second anchor point. The bezierDetail and curveDetail functions are used to change the detail of the curves and the curveTightness function is used to set the tightness of the curve. Use a value of 0.0 to connect the points of the curve with straight lines and values between -5.0 and 5.0 to create curves with varying tightness.
In this recipe I also learned how to use the translate function with a for loop to create multiple curves and then translate (position) them from left to right (x parameter) at a specified distance apart (20) in the display window. The pushMatrix and the popMatrix functions are also somehow involved in the translation of the curves, but I’m not quite sure how just yet. The Processing 2.0+ reference for these two functions functions provides a description and an example, but I’m not sure when to pop and when to push and why. I guess I’ll play around with them both and figure it out!
Worth noting, since this recipe was created the OpenGL library has been included as part of Processing 2.0. That means you no longer have to import the library. Nice!
Oh yeah, gradually increasing the tightness of the curve by moving the mouse from left to right (current horizontal coordinate of the mouse) is also pretty cool!
Making my way through the Drawing text recipe from the Processing 2 Creative programming cookbook source code on GitHub.
In this recipe I learned how to declare PFont objects for the fonts to be used in the Sketch and set the second parameter of the textFont function to determine the size of the text. For example, textFont (junction, 18). I also learned how to use:
- loadFont function to load the fonts into the PFont object
- draw function to draw lines of text
- text function to draw text to screen
- textAlign function to align the text to the coordinates used in the text function. For example, LEFT, CENTER or RIGHT.
- textWidth to return the width of a text block in pixels. In this Sketch, the width was the string of text “Nulla blandit ut magna”.
- textLeading to set the leading of three different text blocks.
Another thing I learned from this recipe was how to use Create font tool that’s part of Processing to convert each font from its original format to a bitmap format used by Processing.
Making my way through the Working with images recipe from the Processing 2 Creative programming cookbook source code on GitHub. In this recipe I learned how to:
- use the loadImage function to load an image from my data folder into my Sketch
- declare a boolean (pixelMode) for the if test
- use the image function to display the new images (dimensions specified in copWidth and copyHeight and areas specified by the pixel-swapping if test) in the window.
I also learned about the get and set methods and how they can be used to define a region and change the colour of the loaded image. Rad!
Making my way through the Working with colours recipe from the Processing 2 Creative programming cookbook source code on GitHub. In this recipe I learned how to use the color function to create a variable of the type colour (c = colour variable), the stroke function to set the colour of the stroke, the fill function to set the fill colour of the shape. I also added an additional +130 to the height of displayHeight. I wanted the size and position of all the shapes to be relative to the window size (displayWidth, displayHeight), but I haven’t figured out how to do that yet.
Making my way through the Drawing basic shapes recipe from the Processing 2 Creative programming cookbook source code on GitHub. In this recipe I learned how to use the rect, ellipse, quad and triangle functions to draw basic geometric shapes. I also found it interesting how two for loops are used to create the grid background pattern. I’m curious to find out if this coding style is better or more efficient than a single for loop I used to create my grid background pattern. I guess I’ll find that out as I continue to work through each recipe.
I understand this recipe is about drawing basic shapes and not about size and positioning, but there’s something rather inflexible about the way each shape is drawn. I’d prefer to scale and position each shape relative to the size of the window.
- Extension task 1: As an extension to this recipe, I think I’ll explore relative scale and positioning in an attempt to make my Sketch that little bit more flexible.
- Extension task 2: I wonder if it’s possible to detect or determine the display size of the environment/user agent. If so, objects may be able to be drawn and positioned relative to the display size. My task is to find out and then create a few example sketches.
The Silhouette Story started from a response to a blog post. Then came Chapter 1 – My hand. Now, the second chapter The sun and the street light has been written for The Silhouette Story.