From last time…
•

Libraries, Functions, Active Mode, Interaction!

•

Check the site for a list of inspiration sources!

...
Variables

CAP
What is a variable?
•

An address in memory: 0x0000883A!

•

Variables have a type and a name!

int x;
int y;
float weight...
Memory
int x;
The Primitives
boolean!! ! true or false!
char! ! ! ! ‘a’ ‘b’ ‘c’!
byte! ! ! ! -128 to 127
short! ! ! -32,768 to 32,767!
i...
Common Primitives
boolean!! ! true or false!
int ! ! ! -2147483648 to 2147483647!
float! ! ! 3.14159
Using Variables
1. Declare the variable!

int xposition;

// type name;

2. Initialize the variable!

xposition = 10;

// ...
Using Variables
1 & 2. Declare & Initialize the variable!

int xposition = 10;
// type name = value;
Demo Variables
System Variables
mouseX, mouseY
pmouseX, pmouseY
width, height

// sketch dimensions

frameCount, frameRate
displayWidth, ...
Demo!
System Variables
random() & casting
random(j)

// from 0 to j

random(j,k)

// from j to k

float r = random(24);
int r = random(24);

// n...
For next time…
•

Monday is Martin Luther King, Jr. Day!

•

Read Shiffman, p. 59–70 (Conditionals I)!

•

Project Proposa...
Upcoming SlideShare
Loading in...5
×

5. Variables

87

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
87
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "5. Variables"

  1. 1. From last time… • Libraries, Functions, Active Mode, Interaction! • Check the site for a list of inspiration sources! • We have a Teaching Assistant:! ! Yifan Wang, yifan@cise.ufl.edu! ! Office Hours: CSE309, 2:00pm–3:00pm
  2. 2. Variables CAP
  3. 3. What is a variable? • An address in memory: 0x0000883A! • Variables have a type and a name! int x; int y; float weight; string introduction;
  4. 4. Memory int x;
  5. 5. The Primitives boolean!! ! true or false! char! ! ! ! ‘a’ ‘b’ ‘c’! byte! ! ! ! -128 to 127 short! ! ! -32,768 to 32,767! int ! ! ! -2147483648 to 2147483647! long! ! ! ! larger numbers!! float! ! ! 3.14159! double! ! ! float with more decimal places
  6. 6. Common Primitives boolean!! ! true or false! int ! ! ! -2147483648 to 2147483647! float! ! ! 3.14159
  7. 7. Using Variables 1. Declare the variable! int xposition; // type name; 2. Initialize the variable! xposition = 10; // name = value;
  8. 8. Using Variables 1 & 2. Declare & Initialize the variable! int xposition = 10; // type name = value;
  9. 9. Demo Variables
  10. 10. System Variables mouseX, mouseY pmouseX, pmouseY width, height // sketch dimensions frameCount, frameRate displayWidth, displayHeight dimensions // screen key, keyCode, keyPressed mousePressed // is it pressed? mouseButton // left/center/right
  11. 11. Demo! System Variables
  12. 12. random() & casting random(j) // from 0 to j random(j,k) // from j to k float r = random(24); int r = random(24); // needs to be cast! int r = int(random(24)); // int() method int r = (int) random(24); // Java cast
  13. 13. For next time… • Monday is Martin Luther King, Jr. Day! • Read Shiffman, p. 59–70 (Conditionals I)! • Project Proposals due on Wed, January 22 Quiz • Closed book, 25 minutes, good luck!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×