Computer Science I Looping. User input. Classwork/Homework: Incorporate looping & user input into a sketch.

Slides:



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

Pages and boxes Building quick user interfaces. learning objectives o Build a quick UI with pages and boxes o understand how pages and boxes work o click.
Introduction to Programming
Game with US Beginner Tutorial. Welcome!! Who I am What is Processing? Basic Coding Input Methods Images Classes Arrays.
RAPTOR Syntax and Semantics By Lt Col Schorsch
© 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.
Data: Programming Design and Modularization IS 101Y/CMSC 101 Computational Thinking and Design Thursday, September 26, 2013 Marie desJardins University.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
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.
Review Blocks of code {.. A bunch of ‘statements’; } Structured programming Learning Processing: Slides by Don Smith 1.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Locally Edited Animations We will need 3 files to help get us started at
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
Continuous February 16, Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
Loops: Handling Infinite Processes CS 21a: Introduction to Computing I First Semester,
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
Loops and Iteration for Statements, while Statements and do-while Statements.
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.
NA2204.1jcmt CSE 1320 Intermediate Programming C Program Basics Structure of a program and a function type name (parameters) { /* declarations */ statement;
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
Lesson Two: Everything You Need to Know
ITI 1120 Lab #5 Contributors: S. Boyd, R. Plesa, A. Felty, D. Inkpen, A. Williams, D. Amyot.
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.
Programming games Context of what we are doing. Drawing on canvas. Homework: [Complete coin toss examples.] Do your own drawings. Upload files to website.
Computer Science I Classes and objects Classwork/Homework: Examine and modify my examples. Make your own.
1 Project designed and created by M. Shajith Kumar.
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
Computer Science I Programming in Java (programming using Processing IN Java, using IntelliJ IDE) Classwork/Homework: copy your Processing projects over.
Computer Science I Arrays. Parallel structures. Classwork/Homework: Build your own bouncing things.
Computer Science I Recap: variables & functions. Images. Pseudo-random processing.
G RAPHICS & I NTERACTIVE P ROGRAMMING Lecture 2 More Programming with Processing.
Computer Science I Share plans for virtual something. Text. Show my virtual dog. Classwork: Plans for your virtual something. Homework: start implementation.
Computer Science I Variables. Methods. Classwork/Homework: Re-do or do new drawing using variables & function(s). Zip folder and upload to Moodle dropbox.
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.
Starter – Its the small things in life What’s wrong with this code Height = 10 Width = 10 A = Height * Width Print A Remember to check: Spelling Spacing.
Welcome to Processing Who does not have access to digital camera?
Computer Science I Text input. Transformations. Yet another jigsaw. Classwork/Homework: Create new application making use of transformations.
Computer Science I Animations. Bouncing ball. The if statement. Classwork/homework: bouncing something. Compress and upload work to Moodle.
Computer Science I Go over midterm. Reprise on curves. Table examples. The map function. Testing Strings. Fonts. Classwork/Homework: Complete midterm project.
Computer Science I More class examples. Paths. Jigsaw. Tolerance. Classwork/homework: Your class project. Post proposal for midterm project.
Time to upload Virtual something.
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.
Computer Science I Adding a timing feature. Classwork/Homework: finish final project. Prepare for review for final. Post on programming topic.
Introduction Every program takes some data as input and generate processed data as out put . It is important to know how to provide the input data and.
Classwork: Examine and enhance falling drop(s) or make your own.
Computer Science I Variables. Methods.
Chapter 14, Translate & Rotate
Basic Input and Output CSE 120 Winter 2018
Chapter 10 Algorithms.
Computer Science I Fonts. Building on one jigsaw to make another.
Chapter 10 Algorithms.
More programming with "Processing"
Lecture 7: Introduction to Processing
IAT 265 Lecture 2: Java Loops, Arrays Processing setup, draw, mouse Shapes Transformations, Push/Pop.
LCC 6310 Computation as an Expressive Medium
Chapter 10 Algorithms.
Continuous & Random September 21, 2009.
Presentation transcript:

Computer Science I Looping. User input. Classwork/Homework: Incorporate looping & user input into a sketch.

Looping …. Doing the same or similar things over and over. Processing has many statements (compound statement types) for looping. There also is looping done by the draw function.

Preview: animation Unless you (your code) changes it, the draw function is invoked over and over The rate of invocation of draw is the frameRate. The default value is 60 frames/second. It can be changed. Animation is produced by erasing the screen and then drawing (again), generally changing the positions of what is draw.

Looping: for loop The for statement has loop variable, and an initial value for the loop variable, a condition to be checked, and an increment expression. Also demonstrate console. void setup() { int sum = 0; for (int i=0; i<5; i++) {sum = sum + i; } print(sum); //prints value of sum on console }

Looping: for loop Change the name of the loop variable, the initial value, the condition and the increment expression // add up odd numbers less than 10 void setup() { int sum = 0; for (int k=1; k<10; k=k+2) {sum = sum + k; } print(sum); //prints value of sum on console }

Preparation for next example Use built-in variables width and height : refer to dimensions of screen. Use line function: line(x1,y1,x2,y2); Use trig functions Sine(a) Cosine(a) a

Polygon To draw an n-sided shape, we (our code) draws n lines (chords) between successive points on a circle. Think of the circle as a pie (no pun intended) divided up into pieces.

Plan Use a function named polygon Parameters are – x, y location indicating the center of the circle – width of the polygon – Number of sides

Start of sketch //polygon void setup() { size(800,600); } void draw() { polygon(.5*width,.5*height, 100.0, 3); }

void polygon(float x, float y, float w, int n) { float angle = TWO_PI / n; float rad = w/2; for (int i=0;i<n;i++) { float pangle1 = angle * i; float pangle2 = angle * (i+1); float xp1 = x + rad * cos(pangle1); float yp1 = y + rad * sin(pangle1); float xp2 = x + rad* cos(pangle2); float yp2 = y + rad * sin(pangle2); line(xp1,yp1,xp2,yp2); }

Check it out for different values of n What if parameter n is negative??? – Semantic problem. Should put in a check. What if n is even, say 4? Okay or not?

Pop quiz There is another way to draw shapes, namely shape Look up how to do this and change the program.

Processing Events Note: we still haven't used the fact that Processing sets up repeated calls (invocations) of draw. BUT, for the mouse and certain other events to work, we need draw to be defined and to work in the normal, default way, that is repeat.

Processing events: mouse Processing keeps track of the position of the mouse, setting the variables mouseX and mouseY. Processing also allows us (programmers) to define various functions, for example void mouseReleased() { } This function, if it is defined, is invoked when the mouse button is pressed, then released.

Planning We have a function that draws a polygon at a given location, width, number of sides. So…let's code our mouseRelease to invoke that function at the mouse location, fixed width, fixed number of sides. Next version will be fancier.

Implementation Take the polygon program and add void mouseReleased() { polygon(mouseX,mouseY,100.0,4); }

Fancier version Vary the type of polygon. Specifically, cycle through 3, 4, 5, 6, 7, 8, 9, 10, 3… Do this by definition variables int choices = 3; //minimum for a // polygon int limit = 10; Use ++ operator that returns value and THEN increments Use an if statement

Implementation void mouseReleased() { polygon(mouseX,mouseY, 100.0,choices++); if (choices > limit) { choices = 3;} }

One more thing Provide directions for user Use text, textSize, fill functions. Reset fill back to black. Do it all in setup. – Will need to move to draw, if draw erases screen each time.

Change (expand) setup void setup() { size(800,600); fill(255,0,0); textSize(18); text("Click on screen",20,20); fill(0); }

Pop quiz What does ellipseMode do? Describe uses. Record website.

Classwork / Homework Incorporate for-loop and/or mouseRelease into a sketch – You can start by building on one of mine. – Consider drawing something other than a polygon, but DO USE A FUNCTION and VARIABLES Look up how to set up response to pressing a key on the keyboard – This is termed as setting up event handler for a key event.