Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.

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,
Introduction to Programming
Game with US Beginner Tutorial. Welcome!! Who I am What is Processing? Basic Coding Input Methods Images Classes Arrays.
Variables and Operators
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.
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
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.
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
IAT 800 Foundations of Computational Art and Design Lecture 2.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
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.
Introduction to Python and programming Michael Ernst UW CSE 190p Summer 2012.
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 8 Fall 2010.
Continuous February 16, Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
Art 315 Lecture 6 Dr. J. Parker. Variables Variables are one of a few key concepts in programming that must be understood. Many engineering/cs students.
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
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 11 Fall 2010.
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 02b: Tutorial for Programming in Processing Jarek Rossignac.
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
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
LCC 6310 Computation as an Expressive Medium Lecture 2.
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.
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.
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Processing  Install Processing  Learn how to edit, run, save, export,
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.
Computer Science I Animations. Bouncing ball. The if statement. Classwork/homework: bouncing something. Compress and upload work to Moodle.
Introduction to Processing Dominique Thiebaut Dept. Computer Science Computer Science Dominique Thiebaut Thiebaut -- Computer Science.
What is Binary Code? Computers use a special code of their own to express the digital information they process. It's called the binary code because it.
Primitive Data Types. int This is the type you are familiar with and have been using Stores an integer value (whole number) between -2,147,483,648 (-2.
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.
1 float Data Type Data type that can hold numbers with decimal values – e.g. 3.14, 98.6 Floats can be used to represent many values: –Money (but see warning.
p5.js mouse, keyboard and if’s
Lesson Two: Everything You Need to Know
Computation as an Expressive Medium
For Net Art Lecture 2 J Parker
Programming for Artists
Mouse Inputs in Processing
Chapter 5, Conditionals Brief Notes
More programming with "Processing"
IAT 265 Lecture 2: Java Loops, Arrays Processing setup, draw, mouse Shapes Transformations, Push/Pop.
LCC 6310 Computation as an Expressive Medium
IAT 800 Foundations of Computational Art and Design
Variables and Operators
LCC 6310 Computation as an Expressive Medium
Presentation transcript:

Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010

Processing We now know a bit about Processing – variables, animation, random numbers, and so on. Programming is about a lot of details, not all of which have easy to show examples immediately. There are principles (generalization) involved that are important to appreciate.

Types Variables have types. The type dictates what kind of data can be stored in the variable. The type is specified in the variable’s declaration.

Types booleantrue or false charcharacter (letter, digit. ‘;’) bytesmall number, -128 to 127 shortsomewhat larger number, to int a big number longa really big number float a decimal number ( ) doublea decimal number with more digits ccc

Declarations int i;// the variable named I holds an integer int i,j,k; boolean more = true; float size, x, y; // Three real numbers. i = 4; x = 3.1; y = 2*x – i*i; int count = 0;

System Variables Declared by the system and you can use them. Hold useful values. width- width of the sketch window. height- height of the window. frameCount – Number of frames drawn framerate – frames per second key- most recent key pressed keyPressed – is a key pressed mousePressed – is the mouse pressed? mouseButton – Which button is pressed?

Random random (10)a random number between 0 and 9 random (1,10) a random number between 1 and 10, not including 10. (int) random(1, 7) an integer between 1 and 6 (a die roll) (int) random (1, 53) – deal a card

Here is an animation of a die roll A histogram of rolls: void draw () { r = random (1, 7); i = (int)r; … Collect frequency of rolls, plot them.

Random Random numbers are used to simulate intelligence. Recall from GameMaker. Reality is messy. Randomness gives a sense of the real to things. EG hand-drawn lines are never straight. Randomness can simulate the nature of real drawn lines. Does not have to be right, just look right.

The Mouse We have already used the system variables mouseX and mouseY. Remember that in Gamemaker the mouse clicks were events. The same is true here. In Gamemaker we coded an event handler that executed when the event occurred. Same here. The event handler is another function like draw and setup.

The Mouse void setup () { size (200,200); background(255); } void draw () {} void mousePressed () { stroke (0); fill(174); rectMode (CENTER); rect (mouseX,mouseY,12,12); }

The Mouse void mousePressed () { stroke (0); fill(174); rectMode (CENTER); rect (mouseX,mouseY,12,12); } Changing this to ‘keyPressed’ Does the obvious thing!

Mouse Colours Set background color depending on the mouse position. Horizontal is RED, vertical is GREEN. Height and width will be 256 (full 8 bit color) Easy – set background to (mouseX, mouseY, 128);

Mouse Colours

Conditionals Processing has an IF construct too. Let’s do a program where we draw a traffic light that changes like the real ones do. It will count frames (steps) and change color when a reasonable number are reached.

Conditionals

int c = 0, k=0; C is color red=0, yellow=1, green=2. K is a count of frames/steps. It’s a timer. Add 1 each time DRAW is called. void setup () { size (200,200); background(255); } void draw () { fill (200, 200, 200); //Grey rect (30, 30, 40, 70); Surround ellipseMode (CENTER); Now draw lights: red on top, then yellow, then green. Fill with RED if color c=red (0) if (c==0) fill (255,0,0); ellipse (50, 40, 10, 10);

Conditionals Now fill with yellow if c=1, draw the circle. if (c==1) fill (255,255,0); else fill (200, 200, 200); ellipse (50, 60, 10, 10); Finally, fill with green and draw the green light. if (c==2) fill (0,255, 0); else fill (200, 200, 200); ellipse (50, 80, 10, 10); K is the timer – increase. k += 1; If timer is large enough, change the color. if (k > 200) { c += 1; if (c>2) c = 0; k = 0; }

Final program int c = 0, k=0; void setup () { size (200,200); background(255); } void draw () { fill (200, 200, 200); rect (30, 30, 40, 70); ellipseMode (CENTER); if (c==0) fill (255,0,0); ellipse (50, 40, 10, 10); if (c==1) fill (255,255,0); else fill (200, 200, 200); ellipse (50, 60, 10, 10); if (c==2) fill (0,255, 0); else fill (200, 200, 200); ellipse (50, 80, 10, 10); k += 1; if (k > 200) { c += 1; if (c>2) c = 0; k = 0; }

Println (print line) A way to print things (text, numbers) to the message window. println (“Hi there”); Prints the message ‘Hi there’ in the message window.

Println The value in a variable can be printed. int x=0; println (x); x = x + 1; Prints the value of the variable x in the message window.

Println The value in a variable can be printed along with a message. int x=0; println (“The value of X is “ + x); x = x + 1; Prints the message in the message window.

Println The symbol ‘+’ here means something different from the usual meaning ‘add’. Println is a function and its parameter is a character string. Technically, the ‘+’ here means ‘concatenate’, or add to the end of a string. println (“The value of X is “ + x); Takes the integer variable x, turns it into a string, and adds it to the end of the first string to yield a single string that can be printed.

Println There can be more than two things: println (“The sum of “ + x “ and “ + y + “ is “ + (x+y)); This works OK, but needs the () around (x+y). Otherwise it will convert x and y into strings and concatenate them! The ( ) allows us to specify the order in which we want the operations to be done. Precedence!

Precedence You likely have not thought about it, but there is an implicit order to the evaluation of operators in expressions. Computers love rules /2 is 30 (12 + (36/2) = = 30) * 2 is 17 ( (5*2) = 7+10 = 17) -3+5 = 2 ( (-3) + 5 = 2) Parentheses are used when we wish to disrupt the natural order: (12+36)/2 does the addition first: 48/2 = 24

Precedence You likely have not thought about it, but there is an implicit order to the evaluation of operators in expressions. Computers love rules /2 is 30 (12 + (36/2) = = 30) * 2 is 17 ( (5*2) = 7+10 = 17) -3+5 = 2 ( (-3) + 5 = 2) Parentheses are used when we wish to disrupt the natural order: (12+36)/2 does the addition first: 48/2 = 24

Types Types can be converted. A real number can be converted into an integer, but there are a few ways that can work out. Computers love rules. (int)1.2 is 1 (int)1.6 is 1 (int)( ) is 1 (int) is 2 (int)-1.2 is -1 (int)( ) is -1 (int)( ) is 0

Types Floats are not precise. 0.5 is exact, because it is a power of 2 and has an exact representation is binary. 0.1 is an infinitely repeating decimal fraction in binary (like 1/3 is in decimal); Adding/subtracting 0.1 repeatedly compounds the error. What does this print?? z = y+y+y+y+y+y+y+y+y+y; println ("z = " + (z) );

Types z = So the rule is: NEVER compare a float variable for equality against another float. (Unless it does not matter) OK: if (x >= 1.0) … Not OK: if (x == 1.0) …

Types Integers have a max value. If they exceed that, they become negative. You may not be warned. short k; … k = 32766; println ( "k = " + k); k = k + 1; println ( "k = " + k); What does this print?

Types k = k = k = Why? (do you really want to know??) Has to do with how negative numbers are represented in binary.