GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing happycoding.io — Simple Processing Reference Simple ReferenceSimple ReferenceNow that you’ve learned about calling functions, the best thing you can do is practice by writing your own sketch that uses Processing’s functions to draw a few different scenes. The Processing reference contains all of the functions you can call in Processing, but it also contains a bunch of more advanced stuff that can be confusing if you’re just starting out. This page is a simplified reference that contains all of the functions you need to practice calling functions to draw a scene. This process of coming up with a goal (drawing a scene), breaking that goal down into smaller pieces (draw one small part of the scene at a time), and looking stuff up in the reference (this page) is honestly 95% of a “real” programmer’s job. So if you’re here, you’re a real programmer! Windowsize(width, height)Sets the size of the window. If you call this function, it must be the first function you call.
background(red, green, blue)Sets the background color of the window. The
Shapesellipse(x, y, width, height)Draws an ellipse (oval). The
rect(x, y, width, height)Draws a rectangle. The
triangle(xOne, yOne, xTwo, yTwo, xThree, yThree)Draws a triangle using the three
quad(xOne, yOne, xTwo, yTwo, xThree, yThree, xFour, yFour)Draws a quadrilateral from the four
line(startX, startY, endX, endY)Draws a line between the two
Colorsstroke(red, green, blue)Sets the color of the line drawn around the shapes.
You can also call strokeWeight(weight)Sets the width of the line drawn around the shapes.
fill(red, green, blue)Sets the inner color of the shapes.
Calling Multiple FunctionsNote that most sketches will contain many function calls. You can call multiple functions to achieve different effects. For example: To understand what this code does, read through it line by line. This sketch creates a 200x200 window, then sets the stroke weight to 10, and the stroke color to orange. It then sets the fill color to green, and finally it draws an ellipse. Because of the functions we called, the ellipse has a thick orange outline and a green inside.
Similarly, we can draw multiple shapes on top of each other: This code sets the window size, then draws an ellipse, then draws a rectangle.
Notice that the rectangle is drawn on top of the ellipse. Think of this as painting an ellipse to a canvas and then painting a rectangle over top of it. MathIn the examples above, we’ve passed numbers directly into the functions. But remember that a computer is basically just a big calculator, so you can also use math (more specifically, arithmetic operators) on those numbers to come up with a result number before passing it into a function. That sounds complicated, but it just means that this line: Could be rewritten like this: This can be especially useful for things like calculating the center of the window: This code sets the width of the window to
CommentsYour code can also contain comments, which are statements the computer will ignore but can help you remember what your code is doing. Here’s an example: The comments (and the spacing) make this code easier to read and understand.
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |