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.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

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.
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  What are they?  Declaring and initializing variables  Common uses for variables  Variables you get “for free” in Processing ▪ Aka: Built-in.
Data: Programming Design and Modularization IS 101Y/CMSC 101 Computational Thinking and Design Thursday, September 26, 2013 Marie desJardins University.
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
IAT 334 Java using Processing ______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
Iteration This week we will learn how to use iteration in C++ Iteration is the repetition of a statement or block of statements in a program. C++ has three.
Repetition Statements repeat block of code until a condition is satisfied also called loops Java supports 3 kinds of loops: while statement – repeats a.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Loops We have been using loops since week 2, our void draw(){ } is a loop A few drawbacks of draw() –It is endless –There is only one draw() –It updates.
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.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
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.
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
Continuous February 16, Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
Control Structures – Selection Chapter 4 2 Chapter Topics  Control Structures  Relational Operators  Logical (Boolean) Operators  Logical Expressions.
1 4.8The do/while Repetition Structure The do/while repetition structure –Similar to the while structure –Condition for repetition tested after the body.
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.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
Review of ArT3 Programming Course David Meredith Aalborg University
C STRUCTURES. A FIRST C PROGRAM  #include  void main ( void )  { float height, width, area, wood_length ;  scanf ( "%f", &height ) ;  scanf ( "%f",
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
CPS120: Introduction to Computer Science Decision Making in Programs.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
CSC 107 – Programming For Science. The Week’s Goal.
Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Lesson Two: Everything You Need to Know
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
Lesson Two: Everything You Need to Know
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Test 2 Review. General Info. All tests are comprehensive. You are still responsible for the material covered prior to the first exam. You will be tested.
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
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.
Often being different. Control flow By default Java (and therefore Processing) executes lines of a program one after the other –Doesn’t matter what happened.
G RAPHICS & I NTERACTIVE P ROGRAMMING Lecture 2 More Programming with Processing.
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  A piece of memory set aside to store data  When declared, the memory is given a name  by using the name, we can access the data that sits.
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.
TOOLBAR TABS MESSAGE CONSOLE TEXT EDITOR DISPLAY WINDOW.
Review Random numbers mouseX, mouseY setup() & draw() frameRate(), loop(), noLoop() Mouse and Keyboard interaction Arcs, curves, bézier curves, custom.
C Language 1 Program Looping. C Language2 Topics Program looping Program looping Relational operators / expressions Relational operators / expressions.
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.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Control Structures – Selection
Computation as an Expressive Medium
Arrays, For loop While loop Do while loop
More programming with "Processing"
Lecture 6: Conditionals AP Computer Science Principles
ICT Gaming Lesson 3.
Chapter 2 Programming Basics.
LCC 6310 Computation as an Expressive Medium
IAT 800 Foundations of Computational Art and Design
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
Introduction to C Programming
Presentation transcript:

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 curly brackets { } and it is called a block of code. (We use this for functions, loops, conditionals ) { rect(100,10,20,20); line(0,0,30,30); }

Structure - built-in callback functions void setup() { our code …} called once in the beginning of our program void draw() { our code… } called repeatedly about 30 times per second or as fast as we ask in frameRate( FPS);

Structure - event driven callback functions void mousePressed(){ our code …} Is called and executed whenever the mouse is pressed (Executed once only) void keyPressed(){ our code …} Is called and executed whenever any key is pressed (Executed once only)

Structure - continuous event driven callback functions void mouseDragged(){ our code …} Is called and executed repeatedly as long as the mouse is pressed and moved (dragged) void mouseMoved(){ our code …} Is called and executed repeatedly as long as the mouse is moved

Variables - system variables Are not declared, or named by us and we do not control their contents, but we can use the values that they store mouseX - the X position of the mouse mouseY - the Y position of the mouse

Variables - system variables pmouseX - the previous position of mouseX pmouseY - the previous position of mouseY width - the width of the window from size() height - the height of the window from size() key - the last key that was pressed mousePressed - is the mousepressed (1,0) and more - check reference

Variables - What are they A variable is a container to hold information in our program, usually numbers or text characters. A variable can hold only a certain type of info, so you cannot ask for a text variable to hold numbers, or vise versa. To a certain extent, a variable in programming is similar to your high school math formula variable ie - x = 7+5

Variables - PEZ dispenser analogy What it holds Data type / container type Variable name (Name of this particular one) Interacting with it Irrelevant questions/use PEZ candy PEZ dispenser Snoopy Put 7 candies into Snoopy, How many candies in Snoopy ? How many marbles in Snoopy? Numbers int X X= 12 X = “serious”

Variables - our variables Three stages : –Declare - giving it a name –Assign value - storing a value in it –Using it - doing something with the value

Variables - declaring Declaring - the format is : data type name ; int x; Data types can be: –float - a decimal number (negative or positive) –int - a whole number (negative or positive) –char - a character for text Name can be letters and number, no

Variables - assigning value Assigning - the format is name = value ; value can be a number x=2; value can be another variable x=y; value can be a math operation x=y+2; value can include the initial value of the variable x=x+1 value can be the result of a function x=random();

Variables - using Wherever a number can be used you can use a variable. To assign a value to another variable x=y; As argument to a function strokeWeight(x); As argument with math strokeWeight(x/5);

Conditional statements - Boolean Boolean divides the world to true / false which in computers is also 1 / 0 allows us to evaluate the relationship between values > greater than (6>5) true < smaller than (6<5) false >= greater or equal (6>=6) true <= smaller or equal (6<=6) true == equals (6==5) false != not equal (6 != 6) false

Conditional statements - logical ! not. The opposite of whatever is on its right ! (6==6) false || or. At least one expression must be true (6==6 || 6==5) true && and. Both expressions must be true (6==6 && 6==5) false

Conditional statements - if if(expression) { } assesses anything in the parentheses and if true, executes block of code that follows. if (x==6){ strokeWeight(x); }

Conditional statements - if / else if(expression) { …} else { …} assesses anything in the parentheses and if true, executes the first block of code, if false executes the block that follows the else. if (x==6){ strokeWeight(x); }else{ strokeWeight(x/6); }

Conditional statements - if / else if if(expression) { …} else if (expression) { …} assesses anything in the parentheses, and if true, executes the first block of code, if false, evaluates the “else if” and if true executes the block that follows, and so forth. Placing an “else” in the end will execute if all others failed if (x==6){ strokeWeight(x); }else if(x>2){ strokeWeight(x/6); } else if(x>4){ strokeWeight(x/8); }

Random numbers float random (); is a function that can take 0,1 or 2 arguments and always returns a float x=random(); returns a number between 0-1 (0.032) x=random(5); returns a number between 0-5 (3.56) x=random(3,12); returns a number between 3-12 (8.876)

Debugging To print a message or the value of a variable use println(); to print a variable use println(x); to print a message use quotes println(“text”) You can combine with + println(“The value of x =” + x)

Loops We have been using loops since week 2, our void draw(){ } is a loop A few drawbacks of draw() –It is endless –There is only one draw() –It updates the screen every time through –It is rather slow (30-60 FPS)

Loops - while Syntax : while (condition) {} void draw(){ int i=0; while (i<5) { println(i); i=i+1; } Result - 0,1,2,3,4,0,1,2,3,4...

Loops - while As long as the condition is true, will continue looping. Once the condition is false, will jump to execute the code under the block. If the condition is always true, the program will get stuck.

Loops - for Look at the while loop, we can point out 3 elements that are usually present: void draw(){ int i=0; ->Initialization while (i Boolean test println(i); i=i+1;->Iteration expression }

Loops - for The for loop consolidates the 3 parts of the typical while loop : Initialization, Boolean test, Iteration expression. Syntax: for (Initialization ; Boolean test ; Iteration expression){} for ( int i = 0 ; i< 10 ; i = i+1) {

Loops - for –The iteration expression (i=i+1) happens in the end of each loop. –The variable declaration (int i = 0) is local to the loop (no one else knows who i is ) –Multiple loops can be nested to achieve matrix repetition for (int x=0;x<10;x++){ for (int y=0;y<10;y++){ point(x,y); } }