Still following along with the same tutorial from the last project (this one) I will show you how to do the rectangle and triangle in Python mode. Remember, since we are doing it in python mode we must have def setup (): and def draw (): instead of void setup (): and void draw ():
Rectangle
First we are going to make a program that prints out a rectangle. Our first step is to set up the screen size and background color under our def setup (): function. We will set our size to 500 by 400 pixels, I’m setting my background color to bright green but you may choose to play around with different colors.
To draw our rectangle we must use the rect(a,b,c,d) function. In the brackets next to rect we put our size and desired placement following these rules; a is where we put our x coordinate, b is where we put our y coordinate, c is where we put the length of our rectangle, and d is where we put the height. So if I wanted to have a red 60 by 80 pixel rectangle at 50 x and 70 y my code would look like this:
Feel free to play around with sizes, positions, and colors.
Triangle
Now we will make a program that prints out a triangle. Follow the same setup and draw function as we have for rectangle as we will need to use this for everything. I am going to make my background purple and m triangle yellow.
For a triangle we use the triangle(x1, y1, x2, y2, x3, y3) function. The rules for this function are x1 is the x-coordinate of the first point, y1 is the y-coordinate of the first point, x2 is the x-coordinate of the second point, y2 is the y-coordinate of the second point, x3 is the x-coordinate of the third point, and y3 is the y-coordinate of the third point. The size of our triangle will depend on how close together or how far apart we place our points.
When my code looks like this:
My program looks like this:
Again, feel free to play around with colors, sizes, and positions.