For Net Art Lecture 2 J Parker

Slides:



Advertisements
Similar presentations
Java Control Statements
Advertisements

Selection Feature of C: Decision making statements: It allow us to take decisions as to which code is to be executed next. Since these statements control.
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
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.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
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
1 Repetition structures Overview while statement for statement do while statement.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
1 Lecture 14 Chapter 6 Looping Dale/Weems/Headington.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
1 Repetition structures Overview while statement for statement do while statement.
Lecture Review (If-else Statement) if-else statement has the following syntax: if ( condition ) { statement1; } else { statement2; } The condition.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
Chapter 4: Control Structures II
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
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.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Today in CS161 Lecture #8 Learn about… Logicals: And, Or, Not Repetition: loops! Rewrite our First Program Using loops Graphics Let’s make the graphics.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Arrays. An array is a collection “The Dinner offers an array of choices.” In computer programming, an array is a collection of variables of the same data.
Mouse Inputs in Processing. Interacting with the Mouse mouseX and mouseY: pg mouseXmouseY –The position of the mouse in the canvas pmouseX and.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
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.
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
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.
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.
IAT 265 Images in Processing PImage. Jun 27, 2014IAT 2652 Outline  Programming concepts –Classes –PImage –PFont.
Review Random numbers mouseX, mouseY setup() & draw() frameRate(), loop(), noLoop() Mouse and Keyboard interaction Arcs, curves, bézier curves, custom.
Introduction to Processing Dominique Thiebaut Dept. Computer Science Computer Science Dominique Thiebaut Thiebaut -- Computer Science.
IAT 800 Lecture 8 PImage and PFont. Oct 13, Fall 2009IAT 8002 Outline  Programming concepts –PImage –PFont.
Loops. About the Midterm Exam.. Exam on March 12 Monday (tentatively) Review on March 5.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
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.
Topic : While, For, Do-While Loop Guided By : Branch : Batch :
Lecture 4b Repeating With Loops
IAT 265 PImage and PFont.
Java Programming: Guided Learning with Early Objects
Computation as an Expressive Medium
CS 177 Week 15 Recitation Slides
Chapter 10 Algorithms.
Mouse Inputs in Processing
Chapter 5, Conditionals Brief Notes
Pages Section: Control2: Repetition
Chapter 10 Algorithms.
More programming with "Processing"
Pages:51-59 Section: Control1 : decisions
Control structures Chapter 3.
Chapter 15, Images …a few points
Control structures Chapter 3.
Programming for Art: Images
Control structures Chapter 3.
CS149D Elements of Computer Science
LCC 6310 Computation as an Expressive Medium
Lab1 Discussion B. Ramamurthy.
Loops & Nested Loops CSE 120 Winter 2019
Chapter 10 Algorithms.
PROGRAM FLOWCHART Iteration Statements.
Question 1a) What is printed by the following Java program? int s;
Pages:51-59 Section: Control1 : decisions
Pages Section: Control2: Repetition
Pages Section: Control2: Repetition
Chapter 9 Arrays.
Presentation transcript:

For Net Art Lecture 2 J Parker Programming For Net Art Lecture 2 J Parker

We looked at Static Processing size (300, 300); strokeWeight (7); line (100, 90, 140, 85); line (175, 82, 225, 80); strokeWeight (4); ellipse (130, 120, 60, 50); ellipse (200, 118, 60, 50); fill (0); ellipse (148,126, 14,18); ellipse (218,123, 14,18); // Mouth line (122, 165, 118, 175); line (120,170, 170, 180); line (170, 180, 210, 160); line (210,155, 213, 165);

A Flower int positionx = 200; int positiony = 200; int ground = 350; int i=0; noStroke(); size (500, 500); stroke (0,190,20); line (positionx, positiony, positionx-20, ground); fill (200,200,23); ellipse (positionx, positiony-25, 30,30); ellipse (positionx+18, positiony-5, 30,30); ellipse (positionx+12, positiony+20, 30,30); ellipse (positionx-13, positiony+20, 30, 30); ellipse (positionx-18, positiony-7, 30,30); fill(0,0,0); ellipse (positionx, positiony, 30,30); positionx = positionx + i*12; positiony = positiony - i*3;

Flowers come in Groups We need to draw more than one. Repeat the process for different locations. We need a LOOP, such as we used in the Turtle graphics programs

WHILE { statements } Syntax is: while ( expression ) As long as (while) the expression is true, keep repeating the statements within the { … } over and over.

Expressions while ( i < 10) As long as the value of i is smaller than 10 while (x >= 0) As long as the value of x is more than 0 while (x < i) while (i*2 < 100)

Forever If a loop never ends then it is called an ‘infinite loop’, and this is a bad thing. SO: some statement inside of the loop must have the possibility of changing the expression (which is evaluated once everytime the loop executes) so that the expression COULD be false.

WHILE i = 3; i = 0; X = 0.5; while (i < 10) while (x < i) { { x = x + 0.5 } i = 0; while (i < 10) { i = i + 1; . . . }

Back to Flowers i = 0; while (i< 20) { draw a flower positionx = positionx + i*12; positiony = positiony - i*3; i = i + 1; } ‘ i = 0; while (i < 20) { draw a flower Change position }

Flowers while (i<20) { stroke (0,190,20); line (positionx, positiony, positionx-20, ground); noStroke(); fill (200,200,23); ellipse (positionx, positiony-25, 30,30); ellipse (positionx+18, positiony-5, 30,30); ellipse (positionx+12, positiony+20, 30,30); ellipse (positionx-13, positiony+20, 30, 30); ellipse (positionx-18, positiony-7, 30,30); fill(0,0,0); ellipse (positionx, positiony, 30,30); positionx = positionx + i*12; positiony = positiony - i*3; i = i + 1; }

Circles Draw a set of 10 circles across the window

Example int x=20,y=50, i; size (400,200); i = 1; // Start with circle 1 while (i<=10) // Loop 20 times { ellipse (x, y, 20, 20); // Draw a circle x = x + 30; // Increase X so next circle will be to the right i = i+ 1; }

Circles

Nested Loops int x=20,y=50, i,j; size (400,400); i = 1; j = 1; // Start with circle 1 while (j <=10) { i = 0; x = 20; while (i<=10) // Loop 20 times ellipse (x, y, 20, 20); // Draw a circle x = x + 30; // Increase X so next circle will be to the right i = i + 1; } y = y + 30; j = j + 1;

Arrays Basically, many variables with the same name accessed by number: int a[] = new int[20]; Is a collection of 20 integers. x[0] = 1; x[1] = 2; x[2] = x[1] + x[0];

Why? Now we can keep track of many individual objects, like circles. Int x[] = new int[20]; Int y[] = new int[20]; … while (i<20) { ellipse (x[i], y[i], 10, 10); }

Images Pimage is a type for an image. PImage x, y; Can read them from files. x = loadImage (“image.jpg”); And display them: image (x, 0, 0);

PImage im; // The image to be loaded String name = "image PImage im; // The image to be loaded String name = "image.jpg"; // Name of the image file void setup () { size (400,400); surface.setResizable(true); im = loadImage (name); // Load the image if (im == null) // Did the file exist? { // No. println ("File 'image.jpg' is missing."); exit(); } else surface.setSize (im.width, im.height); // Yes - set window size. } void draw() { image (im, 0, 0); // Display the image }

Mouse void setup () { size (400,400); background(200, 30, 200); } void draw () // background(200, 30, 200); ellipse (mouseX, mouseY, 30, 30);

Now let’s play.