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.

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.
Introduction to Programming
Game with US Beginner Tutorial. Welcome!! Who I am What is Processing? Basic Coding Input Methods Images Classes Arrays.
A Quick Introduction to Processing
Emerging Platform#5: Processing 2 B. Ramamurthy 6/13/2014B. Ramamurthy, CS6511.
© Calvin College, Being abstract is something profoundly different from being vague... The purpose of abstraction is not to be vague, but to create.
 Variables  What are they?  Declaring and initializing variables  Common uses for variables  Variables you get “for free” in Processing ▪ Aka: Built-in.
Variables Conditionals Loops The concept of Iteration Two types of loops: While For When do we use them? Iteration in the context of computer graphics.
Data: Programming Design and Modularization IS 101Y/CMSC 101 Computational Thinking and Design Thursday, September 26, 2013 Marie desJardins University.
IAT 334 Lab 2 Computer Graphics: Rocket, PImage. June 4, 2010IAT 3342 Outline  Programming concepts –Programming Computer Graphics –Transformations –Methods.
IAT 334 Java using Processing ______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY.
FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2011.
IAT 800 Foundations of Computational Art and Design Lecture 2.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
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.
PROCESSING Animation. Objectives Be able to create Processing animations Be able to create interactive Processing programs.
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.
Programming Games Computer science big ideas. Computer Science jargon. Show virtual dog Homework: [Catch up: dice game, credit card or other form.] Plan.
Review Blocks of code {.. A bunch of ‘statements’; } Structured programming Learning Processing: Slides by Don Smith 1.
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
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
Review of ArT3 Programming Course David Meredith Aalborg University
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Session 16 Pinball Game Construction Kit:. Pinball Version 1 Replaced the fire button with a mouse event. Multiple balls can be in the air at once. –Uses.
B. RAMAMURTHY Simulating Motion and Implementing Animation.
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
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
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.
Lesson 3: Arrays and Loops. Arrays Arrays are like collections of variables Picture mailboxes all lined up in a row, or storage holes in a shelf – You.
LCC 6310 Computation as an Expressive Medium Lecture 2.
Variables and Functions Alice. Naming is Important If you get a new pet one of the first things you do is name it Gives you a way to refer to the new.
Repetition 8/9/2009. Learning to Program -- Suggestions Spend a lot of time fiddling around with code –Programming is something you have to learn by doing.
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
Computer Science I Recap: variables & functions. Images. Pseudo-random processing.
Computer Science I Looping. User input. Classwork/Homework: Incorporate looping & user input into a sketch.
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.
Data: Programming Design and Modularization IS 101Y/CMSC 101 Computational Thinking and Design Thursday, September 25, 2014 Carolyn Seaman Susan Martin.
Review Expressions and operators Iteration – while-loop – for-loop.
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?
Programming for Art: Arrays – 2D ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 16 Fall 2010.
Review Random numbers mouseX, mouseY setup() & draw() frameRate(), loop(), noLoop() Mouse and Keyboard interaction Arcs, curves, bézier curves, custom.
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.
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:
LCC 6310 Computation as an Expressive Medium
Computation as an Expressive Medium
Chapter 10 Algorithms.
Mouse Inputs in Processing
Chapter 10 Algorithms.
More programming with "Processing"
IAT 265 Lecture 2: Java Loops, Arrays Processing setup, draw, mouse Shapes Transformations, Push/Pop.
Variables & Datatypes CSE 120 Winter 2019
LCC 6310 Computation as an Expressive Medium
Chapter 10 Algorithms.
IAT 800 Foundations of Computational Art and Design
Continuous & Random September 21, 2009.
LCC 6310 Computation as an Expressive Medium
LCC 6310 Computation as an Expressive Medium
Presentation transcript:

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 you have to learn by trying it  Get help from other people –I expect those who already know some programming to help others –Figure things out in groups  Ask me questions in class

Sept 15, Fall 2006IAT 8003 Outline  Programming concepts –Built-in Processing methods you fill in –Loops –Reading the time –Arrays –Questions about assignment 1

Sept 15, Fall 2006IAT 8004 setup()  setup() is a predefined Processing method that you define –setup() is called once when a sketch first starts executing  Place any startup code in setup(), eg. –Setting the size –Setting the background color –Initializing variables…

Sept 15, Fall 2006IAT 8005 draw()  draw() is a predefined Processing method that you define –draw() is called continuously by the program  Put code in draw() when you need to constantly update the display (for example, animating an object)

Sept 15, Fall 2006IAT 8006 Example of setup() and draw() int x; int y; void setup() { size(400, 400); background(0); x = 0; y = height/2; } void draw() { background(0); ellipse(x, y, 20, 20); x = x + 1; if (x > width) x = 0; }

Sept 15, Fall 2006IAT 8007 setup() and draw() are examples of callbacks  A callback function is defined by the programmer –The callback gets called in response to some internal event –You usually don’t call callback functions directly with your own code. –setup() and draw() are predefined within Processing as to-be-called-if-defined

Sept 15, Fall 2006IAT 8008 Controlling draw()  framerate() can be used to set the number of times per second that draw() is called –framerate(30) says to call draw() 30 times a second (if the computer is capable of it)  delay() delays execution for a certain number of milliseconds –delay(250) delays for 250 milliseconds (1/4 of a sec.) –You can use delay() or framerate() to determine how fast you want draw() to be called – framerate() is probably easier  noloop() tells the system to stop calling draw() –If you want to, for example, turn off animation  loop() tells the system to start calling draw() again –Use noloop() and loop() together to turn drawing on and off

Sept 15, Fall 2006IAT 8009 Getting info from the mouse  mouseX and mouseY – variables that automagically contain the current mouse location –pmouseX and pmouseY hold the previous location  mousePressed – boolean variable that is true if the mouse button is down –mouseButton – value is LEFT, RIGHT or CENTER depending on which button is held down

Sept 15, Fall 2006IAT Mouse methods  There are several built-in methods you can fill in to process mouse events  mousePressed(), mouseReleased(), mouseMoved(), mouseDragged()

Sept 15, Fall 2006IAT Loops  Sometimes you want to execute code multiple times –E.g. draw() is being called in a loop  Java provides a number of looping mechanisms  They all test some boolean expression (just like an if statement does) and continue to execute code while the expression is true

Sept 15, Fall 2006IAT while loops while( ) { }  Executes code while the boolean expression is true

Sept 15, Fall 2006IAT for loops for( ; ; ) { } First executes the initialization statement  Then tests the boolean expression – if it's true, executes the code once  Then repeats the following: execute final statement, test boolean exp., execute code if true

Sept 15, Fall 2006IAT Converting for to while  Seeing how for loops can be converted to while loops helps you understand for for( ; ; ) { } // is the same as ; while( ) { ; }

Sept 15, Fall 2006IAT Reading time  int hour() – returns the hour (0 – 23)  int minute() – returns the minutes (0 – 59)  int second() – returns the seconds (0 – 59)  int day() – returns the day of the month (1 -31)  int month() – returns the month (1 – 12)  int year() – returns the four digit year (e.g. 2004)  float milliseconds() – returns number of millis since start of app

Sept 15, Fall 2006IAT draw() has nothing to do with time  The value returned by second (or milliseconds()) has nothing to do with how often draw() is called  In draw() you draw frames – you don’t know how often it will be called  Put a println in loop to see how often it gets called long lastTimeLoopWasCalled = 0; void draw() { long milliseconds = millis(); println(milliseconds - lastTimeLoopWasCalled); lastTimeLoopWasCalled = milliseconds; }

Sept 15, Fall 2006IAT Effect of creating an int variable // Single int int anInt; // Put a value in the int anInt = 3; // Type error! anInt = “hello”; CodeEffect Name: anInt, Type: int 3 “hello” Can’t shove “hello” into an int

Sept 15, Fall 2006IAT Effect of creating an array of ints // declare byte array int[] intArray; // initialize byte array intArray = new int[5]; // set first element intArray[0] = 3; // set third element intArray[2] = 5; CodeEffect Name: intArray, Type: int[] each element has type int

Sept 15, Fall 2006IAT Practice reading code  If code is a medium, then it can be both written and read  Reading code reveals –New programming constructs –Strategies and techniques (design patterns) –Style –Philosophical assumptions (deep reading)  Let’s figure out the Motion  BrownianMotion example together

Sept 15, Fall 2006IAT New constructs  Array declaration and reference  Math operations and functions  Type casting