Download
task 1 and task 2 n.
Skip this Video
Loading SlideShow in 5 Seconds..
Task 1 and Task 2 PowerPoint Presentation
Download Presentation
Task 1 and Task 2

Task 1 and Task 2

99 Vues Download Presentation
Télécharger la présentation

Task 1 and Task 2

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Task 1 and Task 2

  2. Variables in Java Programs • Variables start with lower case letter • Variables are descriptive of what they store • Variables are one word • Use camel case is two myRate; Data types - specifies the kind of data you are storing int - store whole number double - store decimals boolean - store true or false value

  3. Creating Variables Refer to the data type - what it will store Whole number, decimal number, int data type stores whole numbers Integer double data type stores decimal numbers int numX = 40; double numY = 40.5;

  4. Creating Variables int xSize = 400; int ySize = 400; size(xSize, ySize); There are two variables already created for you to use: mouseX - follows the mouseX location mouseY - follows the mouseY location Example: void draw() { ellipse(mouseX, mouseY, 40, 40); }

  5. Methods • We’ve used methods to create shapes. • Processing has two main methods setup() where you set up the size of the sketch Initial information what needs to load once draw() This method is called continually. Allows for animation. Like a game loop.

  6. Method random(int start, int end); returns a double Can produce random color Color is from 0 to 255 int r = (int)random(0,255); float r = random(0,255);

  7. Create a program with variables void setup() { size(500, 500); } void draw() { ellipse(mouseX, mouseY, 40, 40); }

  8. Processing has two main functions/methods: setup() The setup() function is called precisely once at the start of your program. void setup() { size(500, 500); } draw() - this method is called repeatedly like a game loop. an ellipse 40 pixels wide and 40 pixels high is drawn at the position of the mouse pointer, i.e. at location (mouseX, mouseY) on the screen. mouseX and mouseY are examples of variables. These particular variables are pre-defined by Processing and are automatically set to be the current coordinates of the mouse pointer on the screen. void draw() { ellipse(mouseX, mouseY, 40, 40); }