1 / 8

Task 1 and Task 2

Task 1 and Task 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 i nt - store whole number

Download Presentation

Task 1 and Task 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

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); }

More Related