JS Guide-Shapes and Coloring

To start, let's make shapes and color them...
To make a shape, well, such as a rectangle, we do this: rect(200,200,200,200);
You must place the semicolon at the end or the code will glitch. Same with the parentheses and the rect. The semicolon and parentheses apply to all code lines in JS. The first 200 stands for the "X" position. The "X" position is how far the object goes from left to right. The number parameters for the "X" position goes from 1-400. The next 200 is the "Y" position. The "Y" position is the distance for up and down. The number parameters for the "Y" position also go from 1-400. The third 200 is the width of the rectangle. The parameters go 1-400. The lower the number, the less wide it is. The higher the number, the wider it is. The final 200 is the height. The height is the same as the width, except it makes the rectangle taller or shorter, not wider or less wide. Now, this basic set of numbers applies to all shapes, except some may have more numbers, such as: tri(200,200,200,200,200,200); This would mean it has more or less "X" and "Y" positions, or more and width and height positions. Other shape keywords in JS are: ellipse(200,200,200,200);-Note: ellipse is the JS's version of a circle. Continuing: tri(200,200,200,200,200,200); rect(200,200,200,200); All the values are basically the same with width and height, or "X" and "Y". Now, there are much more shapes I could name, but those are the basics you need. Go to: khanacademy.org to learn more. Next, let's learn how to color those shapes. Oh, and one more, not so famous but underestimated shape: point(200,200); Yes, no width and height. It has those sizes set. You only set the "X" and "Y". Continuing, to set color, follow these steps: place this code in a line before the shape you want to color: fill(255,255,255); Now, you can change those numbers to get different colors. The first 255 is how much red their is. The second 255 is how much green their is. The third 255 is how much blue their is. Change the properties to get the color you want. Remember, place the code in FRONT of the object you want to color. If I did this: rect(200,200,200,200); fill(255,255,255); It wouldn't work. You need this: fill(255,255,255); point(200,200); Though I used a point, point do not change colors. They always stay black. Say you put this: fill(255,0,0); rect(200,200,200,200); ellipse(200,200,200,200); Both object would be colored red. If you want separate colors, put this: fill(255,0,0); rect(200,200,200,200); fill(0,0,255); ellipse(200,200,200,200); Reminder, none of these numbers are the ones you need to place. These are simply examples. Remember, put separate fill commands for separate objects if you want separate colors. Well, that wraps it up for coding basic shapes and colors. Oh, wait, don't leave. To color the background of a program put this: background(0,0,0); The numbers are examples. That code sets the background for the whole program unless you use some type of scenes. Their, that wraps it up. Check khanacademy.org to start coding and to view others programs updated daily. Also to learn more. Next subject on JS!

Comment