Programming in Processing Taught by Ms. Madsen Assistants: Ms. Fischer and Ms. Yen Winsor School, 2/20/08.

Slides:



Advertisements
Similar presentations
Variables Conditionals Boolean Expressions Conditional Statements How a program produces different results based on varying circumstances if, else if,
Advertisements

 Functions breakdown: Functions purpose Modularity Declaring and defining a function Calling a function Parameter passing Returning a value Reusability.
Processing the Danger Shield Everything you wanted to know about Processing but were afraid to ask By Ben Leduc-Mills.
Programming in Processing Taught by Ms. Madsen Assistants: Ms. Fischer and Ms. Yen Winsor School, 2/13/08.
Code Elements and Processing Coordinate System. Code elements: pages Comments: are documentation notes that are ignored by the computer but are.
A Quick Introduction to Processing
Variables and Operators
Recursion October 5, Reading Read pp in the text.
SUMMARY: abstract classes and interfaces 1 Make a class abstract so instances of it cannot be created. Make a method abstract so it must be overridden.
 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.
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.
IAT 800 Foundations of Computational Art and Design Lecture 2.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
Introduction to Primitives. Overview Today we will discuss: –The eight primitive types, especially int and double –Declaring the types of variables –Operations.
Slides prepared by Rose Williams, Binghamton University Chapter 19 Swing II.
, Fall 2006IAT 800 Lab 2: Polygons, Transformations, and Arrays.
Methods: a first introduction Two ways to make tea: 1: boil water; put teabag into cup;... etc : tell your younger brother: makeTea(1 milk, 0 sugar);
PROCESSING Animation. Objectives Be able to create Processing animations Be able to create interactive Processing programs.
IAT 355 Lecture 4 Computer Graphics: Rocket. May 9, 2014IAT 3552 Outline  Programming concepts –Programming Computer Graphics –Transformations –Methods.
Review Blocks of code {.. A bunch of ‘statements’; } Structured programming Learning Processing: Slides by Don Smith 1.
Classes / Objects An introduction to object-oriented programming.
Scientific Notation.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap.
Week 2 Book Chapter 1 RGB Color codes. 2 2.Additive Color Mixing RGB The mixing of “ light ” Primary: Red, Green, Blue The complementary color “ White.
Continuous February 16, Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
Programming in Processing Taught by Ms. Madsen Assistants: Ms. Fischer and Ms. Yen Winsor School, 2/6/08.
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
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.
Creating Art With Simple Shapes By carefully implementing simple shapes to an HTML canvas we can create useful graphics. With enough time, lines, ellipses.
Functions. Functions are named blocks of code. Functions allow complex programs to be broken down into smaller, simpler tasks. Functions allow commonly.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
VARIABLES Programmes work by manipulating data placed in memory. The data can be numbers, text, objects, pointers to other memory areas, and more besides.
Mathematical Calculations in Java Mrs. C. Furman.
Computation as an Expressive Medium Lab 2: Polygons, Transformations, and Arrays Evan.
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.
LCC 6310 Computation as an Expressive Medium Lecture 2.
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
Welcome back!. Object Oriented Programming – Encapsulation Classes encapsulate state (fields) and behavior (methods) – Polymorphism Signature Polymorphism.
Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.
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.
Computation as an Expressive Medium Lab 2: Polygons, Transformations, and Arrays (Oh My) Micah.
IAT 265 Images in Processing PImage. Jun 27, 2014IAT 2652 Outline  Programming concepts –Classes –PImage –PFont.
What is Computing? What can be Programmed? Creative Computing Processing Downloading Processing Dropbox Primitive Shapes – point – line – triangle – quad.
Math Problem -- ages Making your own variable equation to solve a math riddle.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
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.
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:
Pixels, Colors and Shapes
Chapter 14, Translate & Rotate
Polygons, Transformations, and Arrays
Chapter 9 Arrays.
Basic Graphics Drawing Shapes 1.
Computation as an Expressive Medium
Basic Input and Output CSE 120 Winter 2018
What employers and colleges expect you to have.
Arduino Part #3 Variables
Lecture 7: Introduction to Processing
IAT 265 Lecture 2: Java Loops, Arrays Processing setup, draw, mouse Shapes Transformations, Push/Pop.
Variables & Datatypes CSE 120 Winter 2019
Chapter 15, Images …a few points
IAT 800 Foundations of Computational Art and Design
Continuous & Random September 21, 2009.
LCC 6310 Computation as an Expressive Medium
Chapter 13, Math A few Examples.
Presentation transcript:

Programming in Processing Taught by Ms. Madsen Assistants: Ms. Fischer and Ms. Yen Winsor School, 2/20/08

Last week I: stroke, strokeWeight, fill… rect, ellipse, triangle… Remember that green  numbers, blue  names. void setup() { size(width, height); color colorName = color(redValue, greenValue, blueValue); background(colorName); } void draw() { color colorName2 = color(redValue2, greenValue2, blueValue2); fill(colorName2); stroke(redValue3, greenValue3, blueValue3); strokeWeight(lineThickness); rect(xStart, yStart, width, height); ellipse(xStart, yStart, width, height); triangle(x1, y1, x2, y2, x3, y3); }

Last week II: beginShape/vertex/endShape! Remember that green  numbers, blue  names. void setup() { color colorName = color(redValue, greenValue, blueValue); background(colorName); size(width, height); } void draw() { beginShape(); vertex(x, y); endShape(); // try using endShape(CLOSE) instead. }

Using variables to hold information We can use variables to hold pieces of information. Variables are names (like x or boo or supercalafragalistic333) that follow our regular naming conventions and hold information about something. We’re going to learn two types of number variables, called int and float.

INT vs. FLOAT int stands for ‘integer’. That means we can use any positive or negative number that doesn’t have a decimal point -3, -2, -1, 0, 1, 2, 3…. float stands for ‘floating-point decimal.’ That means our number should have a decimal point, even if there are only 0s afterwards , ,.453, , 4.8

We declare ints and floats the same way we declared colors. int a = 5; int b = 4938; float c = 27.5; float d = ;

We can combine the declarations: int a = 5, b = 4938; float c = 27.5, d = ; You can also change the values later on – just don’t DECLARE (using ‘int’ or ‘float’) again. –If we’ve already written the code from above… we can write this stuff after. a = 7; // good b = 43392; // good c = ; // good float d = 22.8; // bad! You already declared ‘d’ using ‘float.’

Why do we care about creating variables? They let us reference a piece of information while drawing things… and the information can be changing. So, for instance, if the xStart of a circle is always at foo… … and foo is increasing each time draw() runs… then the xStart of the circle will also be increasing each time draw() runs… And the circle will move across the screen!

How do we increase a variable by 1? Three ways! The long way: a = a + 1; The very short way: a++; And the medium-length-but-more-flexible-way: a += 1;

Let’s try making a circle move right across the screen. Create a variable foo OUTSIDE of any of your methods. (It’ll be ‘global.) int foo = 0; Add a circle to your draw() method, with xStart equal to foo. ellipse(foo, yStart, width, height); Increment foo in draw() to make the circle move. foo++;

Try this: make a circle move right across the screen! color colorName = color(redValue, greenValue, blueValue); int foo = 0; // declaring the variable that will change void setup() { size(width, height); background(colorName); } void draw() { background(colorName); // add this to the beginning of draw() // here’s where your old code is ellipse(foo, yStart, width, height); foo++; // incrementing the variable }

How would you make it move the other direction? Have it start on the other side of the screen; instead of initializing foo to 0, initialize it to the width of your screen. –Replace int foo = 0; with int foo = width; Then, instead of INCREMENTING foo, you can DECREMENT it (make it get smaller, not bigger) –Replace foo++; with foo--;

Try this: make a circle move left across the screen! color colorName = color(redValue, greenValue, blueValue); int foo = width; // declaring the variable that will change void setup() { size(width, height); background(colorName); } void draw() { background(colorName); // add this to the beginning of draw() // here’s where your old code is ellipse(foo, yStart, width, height); foo--; // decrementing the variable }

How can we make the program change speed? Add frameRate() to your setup method. frameRate tells how you many times draw() will run per second. More framesPerSecond  program runs faster. Add this line to setup(): frameRate(framesPerSecond);

New topic: semi-opaque colors. OPACITY is a measure of how not-see-through a color is. A totally transparent color has an opacity of 0. You can see right through it. A totally opaque color has an opacity of 255. You can’t see anything through it. Opacities in between are partly see-through.

How can we make a color partially opaque? Give a 4 th argument to color, fill, or stroke. –(The first three are R, G, B.) If you give 0 as a 4 th argument: –the color/shape will be completely transparent. If you give 255 as a 4 th argument: –the color/shape will be completely opaque (which is the automatic setting.) Try using values in between…

Try this: make some semi-opaque shapes! (This is in your handout.) void setup() { size(width, height); background(colorName); } void draw() { // here’s where your old code is fill(255, 0, 0); // this will be totally opaque red rect(50, 50, 20, 20); fill(255, 0, 0, 255); // this will be opaque red (same as before) rect(50, 100, 20, 20); fill(255, 0, 0, 50); // this will be a semi-opaque red rect(50, 150, 20, 20); fill(255, 0, 0, 0); // this will be totally transparent rect(50, 200, 20, 20); }