Computer Science I Recap: variables & functions. Images. Pseudo-random processing.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Game with US Beginner Tutorial. Welcome!! Who I am What is Processing? Basic Coding Input Methods Images Classes Arrays.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Programming Project 1 Truth Table Lecture 03, file P1 Due January.
Images. PImage class PImage is a class for loading and displaying an image in Processing. Declare a PImage type: PImage img; Make a new instance by loading.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Computer Science 1000 LOGO I. LOGO a computer programming language, typically used for education an old language (1967) the basics are simple: move a.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
Chapter 20 Thinking Big: Functions. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Anatomy of a Function Functions are packages for.
FunctionsFunctions Systems Programming. Systems Programming: Functions 2 Functions   Simple Function Example   Function Prototype and Declaration.
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.
1 Random numbers Random  completely unpredictable. No way to determine in advance what value will be chosen from a set of equally probable elements. Impossible.
PROCESSING Animation. Objectives Be able to create Processing animations Be able to create interactive Processing programs.
Programming Games Computer science big ideas. Computer Science jargon. Show virtual dog Homework: [Catch up: dice game, credit card or other form.] Plan.
Scratch the Cat. Object Oriented Programing Writing computer programs Based on Objects Instead of Actions Based on Data Instead of Logic.
Review Blocks of code {.. A bunch of ‘statements’; } Structured programming Learning Processing: Slides by Don Smith 1.
1 k Jarek Rossignac,  2008 Processing  Install Processing  Learn how to edit, run, save, export, post programs  Understand.
Programming games Reprise: coin toss on canvas. Dice game rules. Global and local variables. Homework: [Catch up. Upload projects, including index.html.]
Continuous February 16, Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
Chapter 2 - More Controls More controls – Text boxes - used for user input – Frames - containers to group items – check boxes - user select an option -
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.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Applications Development
Introduction to Processing. 2 What is processing? A simple programming environment that was created to make it easier to develop visually oriented applications.
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.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
CIS 3.5 Lecture 2.2 More programming with "Processing"
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.
Words. Characters and Strings Character –A single character inside of single quotes char letter = 'A' ; char digit = '0' ; – Strings Zero or more character.
Computer Science I Classes and objects Classwork/Homework: Examine and modify my examples. Make your own.
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 Looping. User input. Classwork/Homework: Incorporate looping & user input into a sketch.
G RAPHICS & I NTERACTIVE P ROGRAMMING Lecture 2 More Programming with Processing.
Programming games Flash concepts. Coin toss. Filezilla: upload your project(s) Homework: Enjoy Spring Break.
First Project: Dance Dance Sprite  Write a dance with your sprite (You pick or create the sprite)  Incorporate as many of the Motion Commands as you.
CHAPTER 2 The Game Loop - Variables, Types, Classes and Objects in XNA XNA Game Studio 4.0.
Computer Science I Share plans for virtual something. Text. Show my virtual dog. Classwork: Plans for your virtual something. Homework: start implementation.
Open a new Flash File Action Script 2.0. Create a button like you did last lesson and name it Click to Play.
Computer Science I Variables. Methods. Classwork/Homework: Re-do or do new drawing using variables & function(s). Zip folder and upload to Moodle dropbox.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.
Processing TYWu. Where can I download? 2.0b9 Windows 32-bit.
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,
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.
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 Looking at code: "Where did Prof. Shablinsky go" Classwork/homework: midterm projects.
Computer Science I More class examples. Paths. Jigsaw. Tolerance. Classwork/homework: Your class project. Post proposal for midterm project.
Time to upload Virtual something.
Computer Science I Libraries. Sound. Saving frames as images. Classwork/Homework: Make sketch using sound. Add saving frames.
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.
Classwork: Examine and enhance falling drop(s) or make your own.
Computer Science I Variables. Methods.
Introduction to Object-Oriented Programming
Using variables, for..loop and functions to help organize your code
For Net Art Lecture 2 J Parker
Computer Science I Fonts. Building on one jigsaw to make another.
More programming with "Processing"
CSCI N207 Data Analysis Using Spreadsheet
LCC 6310 Computation as an Expressive Medium
creating a ecosystems model in net logo
Continuous & Random September 21, 2009.
Presentation transcript:

Computer Science I Recap: variables & functions. Images. Pseudo-random processing.

Flow of control … in Processing Statements outside of any function (should be just declarations of variables) executed in order, one time. The statements in the setup function executed in order once when sketch (program) is run. The statements in the draw function are executed in order when draw is executed. The statements in any for-loop are executed and then repeated, as long as condition is true.

What is going on when a function is called? You (your code) may define a function (aka programmer defined functions; also called user-defined function, but this is bad term). Your code may invoke/execute/call a function. Flow of control goes to code in the function and, when function completes, back to where function was invoked. Processing (and other languages) use what is termed the stack / the program stack / the execution stack. This is information containing references to accessible variables and return point.

Global and local variables Variables declared inside a function are only accessible inside the function. They go away when function completes. The loop variable declared in header of for- loop and any other variables declared inside for-loop also go away when loop completes.

Planning Goal: write a coin toss sketch Program will respond to a mouse click by drawing an picture of something when mouse was clicked. The something is one of two images. We want to just show one "coin" at a time. We will want to keep track of heads versus tails and display on the screen.

What we… Know: How to respond to release of mouse button How to display text – Will expand How to write if statement – this will be variant if-else Don't know: How to do something randomly How to display images How to erase the screen

Pseudo-random processing The built-in function random returns a number from 0 up to but not including the parameter. So… random(1) produces a float, a fraction from 0 up to 1

Start Processing // coin flip void setup() { size(600,400); frameRate(1); //slow down frames } void draw() { } void mouseReleased(){ println(random(1)); // console }

Next stage: save as coinflip1 and modify Add if-else // coin flip void setup() { size(600,400); frameRate(1); } void draw() { } void mouseReleased() { if (.5<random(1)){ println("head"); } else { println("tail"); }

Comments Nothing is being displayed on the screen. Printing to console helps in debugging (and learning). Working in stages is the way to go!

Variable declarations PImage coinh,coint; PFont font; int headc,tailc;

Save As coinflip2 and modify Add the variable declarations (not using the Pimages yet) Change setup to set up font, initialize counting variables to zero. – You can experiment with font, Change mouseReleased

void setup() { size(600,400); frameRate(1); headc = 0; tailc = 0; font = createFont("Ariel",20); textFont(font); }

Notice calls to background and fill void mouseReleased() { background(255); //change background to white if (.5<random(1)){ headc = headc+1; } else { tailc = tailc+1; } fill(0,0,250); //changes color for subsequent text text("Heads ",10,20); text(headc,10,50); text(" Tails ",80,20); text(tailc,80,50); }

Get ready to incorporate images Save As sketch as coinflipImages Find two images. – Could be head and tail of a coin In Processing / Sketch / Add file … locate file one at a time and click Open. This adds the image file to the Processing data folder for this sketch. – Can now use image(Pimage,x,y,w,h) Modify setup – Removed frameRate reset. Go back to default. – Added loading of image files into Pimage variables Modify mouseReleased – Draw images (scaled) to window.

setup with 2 new statements void setup() { size(600,400); headc = 0; tailc = 0; font = createFont("Ariel",20); textFont(font); coinh = loadImage("smirk.JPG"); coint = loadImage("threesome.JPG"); } Names for your images

mouseReleased with additions void mouseReleased() { background(255); //change background to white if (.5<random(1)){ image(coinh,mouseX,mouseY,100,100); headc = headc+1; } else { image(coint,mouseX,mouseY,100,100); tailc = tailc+1; } fill(0,0,240); //change color of text to blue text("Heads ",10,20); text(headc,10,50); text(" Tails ",80,20); text(tailc,80,50); }

Classwork / Homework Complete your sketch with images and random processing. – Can experiment with re-positioning image under the mouse location. – Can experiment with more than 2 choices – Maybe you don't want to clear the window? How to make a biased coin?