Variables. Something to mention… void setup(){ size(200, 200); background(255); smooth(); } void draw() { stroke(0); strokeWeight(abs(mouseX-pmouseX));

Slides:



Advertisements
Similar presentations
Creative Computing. \\ aims By the end of the session you will be able to: 1.Move objects around 2.Write simple interactive programs 3.Use the mouse position.
Advertisements

Variables Conditionals Boolean Expressions Conditional Statements How a program produces different results based on varying circumstances if, else if,
Lesson One: The Beginning Chapter 3: Interaction Learning Processing: by Daniel Shiffman Presentation by Donald W. Smith Graphics from text.
Game with US Beginner Tutorial. Welcome!! Who I am What is Processing? Basic Coding Input Methods Images Classes Arrays.
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.
Constants and Data Types Constants Data Types Reading for this class: L&L,
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Processing Processing is a simple programming environment that was created to make it easier to develop visually oriented applications with an emphasis.
IAT 334 Java using Processing ______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY.
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2011.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
Declaring Variables You must first declare a variable before you can use it! Declaring involves: – Establishing the variable’s spot in memory – Specifying.
ICM Week 2. Structure - statements and blocks of code Any single statement ends with semicolon ; When we want to bunch a few statements together we use.
Lecture 3 IAT 800. Sept 15, Fall 2006IAT 8002 Suggestions on learning to program  Spend a lot of time fiddling around with code –Programming is something.
PROCESSING Animation. Objectives Be able to create Processing animations Be able to create interactive Processing programs.
Review Blocks of code {.. A bunch of ‘statements’; } Structured programming Learning Processing: Slides by Don Smith 1.
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Continuous February 16, Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
Keyboard and Events. What about the keyboard? Keyboard inputs can be used in many ways---not just for text The boolean variable keyPressed is true if.
Processing Lecture.2 Mouse and Keyboard
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Review of ArT3 Programming Course David Meredith Aalborg University
Introduction to Processing CS 4390/5390 Fall 2014 Shirley Moore, Instructor September 3,
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
PROCESSING Numeric Types. Objectives Be able to … Explain the difference between a literal, a variable and a constant Declare numeric variables and constants.
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
CIS 3.5 Lecture 2.2 More programming with "Processing"
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Lesson Two: Everything You Need to Know
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
Mouse Inputs in Processing. Interacting with the Mouse mouseX and mouseY: pg mouseXmouseY –The position of the mouse in the canvas pmouseX and.
Lesson Two: Everything You Need to Know
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
Words. Characters and Strings Character –A single character inside of single quotes char letter = 'A' ; char digit = '0' ; – Strings Zero or more character.
Computer Science I Recap: variables & functions. Images. Pseudo-random processing.
G RAPHICS & I NTERACTIVE P ROGRAMMING Lecture 2 More Programming with Processing.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.
Primitive Data Types 1 In PowerPoint, point at the speaker icon, then click the "Play" button.
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.
Welcome to Processing Who does not have access to digital camera?
Review Random numbers mouseX, mouseY setup() & draw() frameRate(), loop(), noLoop() Mouse and Keyboard interaction Arcs, curves, bézier curves, custom.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Loops. About the Midterm Exam.. Exam on March 12 Monday (tentatively) Review on March 5.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Functions. 2 Modularity What is a function? A named block of code Sometimes called a ‘module’, ‘method’ or a ‘procedure’ Some examples that you know are:
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.
Basic Input and Output CSE 120 Spring 2017
Lesson Two: Everything You Need to Know
IDENTIFIERS CSC 111.
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.
Computers & Programming Languages
Mouse Inputs in Processing
Chapter 2: Java Fundamentals
More programming with "Processing"
Chapter 2: Java Fundamentals
2. Second Step for Learning C++ Programming • Data Type • Char • Float
LCC 6310 Computation as an Expressive Medium
Chapter 4, Variables Brief Notes
Module 2 Variables, Data Types and Arithmetic
Variables and Operators
Continuous & Random September 21, 2009.
Presentation transcript:

Variables

Something to mention… void setup(){ size(200, 200); background(255); smooth(); } void draw() { stroke(0); strokeWeight(abs(mouseX-pmouseX)); line(pmouseX, pmouseY, mouseX, mouseY); } 2

Something to mention… void setup(){ size(200, 200); background(255); } void draw() { } void mousePressed(){ line(pmouseX,pmouseY,mouseX,mouseY); } 3

Something to mention… background() inside setup() background() inside draw() 4

5 All Primitive Types Integer Types byte: A very small number (-127 to +128) short: A small number ( to ) int: A large number (-2,147,483,648 to +2,147,483,647) long: A huge number Floating Point Types float: A huge number with decimal places double: Much more precise, for heavy math Other Types boolean: true or false char: One symbol in single quotes ‘a’

6 Primitive Type Examples Integer Types byte: 123 short: 1984 int: long: Floating Point Types float: 4.0 double: Other Types boolean: true char: ‘a’

7 Declaring and Initializing Variables Can be done in two ways: After declaration: On two lines int count; // declare the variable count = 50; // initialize the value During Declaration: On one line int count = 50; // declare and initialize Can also be initialized with a calculation int max = 100; int min = 10; int count = max – min; // calculation

8 Naming Variables Rules Letters, Digits and underscore ( _ ) are OK to use Cannot start with a digit ( 0,1,…9 ) Cannot use reserved words mouseX, int, size.. Best Practices Use descriptive names boolean moreToDo ; Use ‘camelHump’ notation Start with lower case Each new word starts with Upper Case

Where to Declare Variables Remember that your code is in ‘blocks’ Variables can go inside or outside these blocks

Varying Variables: Remember that processing calls draw() in a loop If you want the variable to change every time: Declare and initialize it outside of draw() Change it inside draw() Moves as circleX increases 

11 circleX Is initialized to 0 Used first time draw() is called ellipse(circleX, circleY, 50,50); Then circleX = circleX + 1; Next time draw() is called, circleX is 1 ellipse(circleX, circleY, 50,50); Then circleX = circleX + 1; Next time draw() is called, circleX is 2 ellipse(circleX, circleY, 50,50); Then circleX = circleX + 1;.. Until circleX is over 200, and the circle just moves off the right side of the screen. Call to draw() circleX …

frameRate() Function frameRate() specifies the number of frames to be displayed every second. frameRate(30) will attempt to refresh 30 times a second. It is recommended to set the frame rate within setup(). The default rate is 60 frames per second. 12

Exercise Modify the program so that instead of the circle moving from left to right, the circle grows in size. 13

Using Many Variables Make things more interesting using more variables! Declare and initialize them outside of draw() Change them inside draw()

15 System Variables Processing provides many ‘built-in’ variables: appear in blue color font mouseX, mouseY, pmouseX and pmouseY width: Width (in pixels) of sketch window height : Height (in pixels) of sketch window frameCount : Number of frames processed frameRate : Rate (per sec.) that frames are processed screen.height, screen.width: Entire screen key : Most recent key pressed on keyboard (ASC-II) keyCode : Numeric code for which key pressed mousePressed : True or false (pressed or not?) mouseButton : Which button (left, right, center)

Using System Variables 16

Exercise The shapes must resize themselves relative to the window size. 17

18 Random() Function random() returns a float. Two arguments random(1,100): a random float between [1,100) One arguments random(100): a random float between 0 (by default) and 100

Using random() 19

Make Zoog Move! 1) Make Zoog rise from below the screen 2) Change his eye color randomly as he moves initial code provided 20

21