Chapter 4, Variables Brief Notes

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Variables Conditionals Boolean Expressions Conditional Statements How a program produces different results based on varying circumstances if, else if,
08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
Variables and Operators
 Variables  What are they?  Declaring and initializing variables  Common uses for variables  Variables you get “for free” in Processing ▪ Aka: Built-in.
Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
Review Blocks of code {.. A bunch of ‘statements’; } Structured programming Learning Processing: Slides by Don Smith 1.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
FUNCTIONS. Function call: >>> type(32) The name of the function is type. The expression in parentheses is called the argument of the function. Built-in.
Continuous February 16, Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
CIS 3.5 Lecture 2.2 More programming with "Processing"
CHAPTER # 2 Part 2 PROGRAMS AND DATA 1 st semster King Saud University College of Applied studies and Community Service CSC1101 By: Asma Alosaimi.
Lesson Two: Everything You Need to Know
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
Arrays. An array is a collection “The Dinner offers an array of choices.” In computer programming, an array is a collection of variables of the same data.
Lesson Two: Everything You Need to Know
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Variables 1. What is a variable? Something whose value can change over time This value can change more than once over the time period (no limit!) Example:
Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Test Review. General Info. All tests will be comprehensive. You will be tested more on your understanding of code as opposed to your ability to write.
Programming for Art: Arrays – 2D ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 16 Fall 2010.
Variables. Something to mention… void setup(){ size(200, 200); background(255); smooth(); } void draw() { stroke(0); strokeWeight(abs(mouseX-pmouseX));
Loops. About the Midterm Exam.. Exam on March 12 Monday (tentatively) Review on March 5.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
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.
Chapter # 2 Part 2 Programs And data
Chapter VII: Arrays.
Some of Chap 17.
Topics Designing a Program Input, Processing, and Output
Chapter 14, Translate & Rotate
Lesson Two: Everything You Need to Know
Java Programming: Guided Learning with Early Objects
Engineering Innovation Center
Chapter 7 Functions.
Time Manager Class Activity Material Manager Writer leader Communicator Programmer Start a journey from the capital AbuDhabi to Alasmaa School using your.
Chapter 7 Functions.
Microsoft Visual Basic 2005 BASICS
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Introduction to C++ Programming
Variables ICS2O.
Variables in C Topics Naming Variables Declaring Variables
Chapter 10 Algorithms.
Chapter 5, Conditionals Brief Notes
Chapter 10 Algorithms.
Chapter 2: Java Fundamentals
Variables in C Topics Naming Variables Declaring Variables
More programming with "Processing"
Pages:51-59 Section: Control1 : decisions
Chapter # 2 Part 2 Programs And data
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Exam1 Review CSE113 B.Ramamurthy 4/17/2019 B.Ramamurthy.
Variables Here we go.
Chapter 10 Algorithms.
Chap 2. Identifiers, Keywords, and Types
Pages:51-59 Section: Control1 : decisions
Variables and Operators
Continuous & Random September 21, 2009.
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
DATA TYPES There are four basic data types associated with variables:
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Variables and Constants
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

Chapter 4, Variables Brief Notes Purpose of Chapter: Continue to program more efficiently by using variables. Allowing for information to vary creates more flexibility.

Definition Variable: A value that can change, depending on conditions or on information passed into the program. What are other synonyms or ways to describe variable? What are some variables that you might need for a game of pong? http://www.ponggame.org

Types of Variables These are the common types int: Whole numbers – positive and negative; i.e. a large number -2,147,483,648 to + 2,147,483,647) float: A number with decimal places, such as 3.14159 char: A character such as “a” or “b” boolean: True or False See page 52 for others

Rules for naming variables Best Practices One word, no spaces Cannot start with number No punctuation or special character except “_” Must be unique Names should be meaningful. Avoid words that appear elsewhere in processing, such as width, height, key, mouseX, etc. camelCase is a good idea

Declare and initialize variables You can declare a variable by stating the type and the name: int starter; Or you can declare and initialize at the same time: int starter = 1; Variables can be initialized by another variable or by a mathematical expression. float counter = x+10 Question: In general, when should you use a variable?

In this exercise, two variables are used for the X & Y positions In this exercise, two variables are used for the X & Y positions. Then each time the circle is drawn onto the screen, the X position increases by one. Declare and initialize two integer variables at top of code. int circleX = 0; int circleY = 100;   void setup() { size(200,200); } void draw() { background(255); stroke(0); fill(175); ellipse(circleX,circleY, 50,50); circleX = circleX + 1; Use the variables to specify the location of an ellipse

This is what is happening in the program:

Random Random is a math function that returns an unexpected value within a specified range. Syntax: random(high) random(low, high) Random returns floating point numbers. To convert to an integer, enclose it in the int() function: int w = int(random(low, high));

Translate The translate() function specifies a horizontal and vertical offset for shapes. However, we will cover it in Chapter 14 where more meaningful examples can be applied.

In-Class Exercise (ICE) Pair up with a classmate. Create an object that moves off the screen. Not too complex because you will vary the horizontal and/or vertical variable so that it moves. Examples: car, balloon, motorbike, airplane, boat, or even two different vehicles. As you start coding, add both names by using comments. Be sure to create a background or platform to improve visual interest (grass, pavement, etc.) Complete your design Grading will be Pass/Fail, and will be worth 1% of final grade On Monday, one team member will upload to openprocessing.org For now, each student will start a free account at www.openprocessing.org and browse some pages.