Simulation and Modeling: Predator-Prey Processing Lab IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 23, 2014 Carolyn Seaman Susan.

Slides:



Advertisements
Similar presentations
Simulation and Modeling: Predator-Prey Processing Lab IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, October 1, 2013 Carolyn Seaman University.
Advertisements

Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
SCRATCH Lesson Two – Interactive Concepts Using Sensing, Operators, and Variables.
Simulation and Modeling: Predator-Prey Processing Lab IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, October 1, 2013 Marie desJardins University.
RAPTOR Syntax and Semantics By Lt Col Schorsch
INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
Data: Programming Design and Modularization IS 101Y/CMSC 101 Computational Thinking and Design Thursday, September 26, 2013 Marie desJardins University.
CS 177 Recitation Week 8 – Methods. Questions? Announcements  Project 3 milestone due next Thursday 10/22 9pm  Turn in with: turnin –c cs177=xxxx –p.
Fibonacci Problem Solving and Thinking in Engineering Programming H. James de St. Germain.
Games and Simulations O-O Programming in Java The Walker School
Relations And Functions. Objective All students will be able to determine whether a relation is a function and identify the domain and range of a function.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
Noadswood Science,  To know the basics of Python coding and decoding Monday, September 07, 2015.
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Carolyn Seaman University of Maryland, Baltimore County.
1 iSee Player Tutorial Using the Forest Biomass Accumulation Model as an Example ( Tutorial Developed by: (
Spreadsheet-Based Decision Support Systems Chapter 22:
Measure your handspan and foot length in cm to nearest mm We will record them as Bivariate data below: Now we need to plot them in what kind of graph?
Design IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, October 15, 2013 Carolyn Seaman University of Maryland, Baltimore County.
Python Programming Using Variables and input. Objectives We’re learning to make use of if statements to enable code to ask questions. Outcomes Build an.
General Programming Introduction to Computing Science and Programming I.
CS 122 Engineering Computation Lab Lab 2 Dan De Sousa and Tim Cheeseman Department of Computer Science Drexel University April 2009 ©By the author. All.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
GUI development with Matlab: GUI Front Panel Components 1 GUI front panel components In this section, we will look at -GUI front panel components -Programming.
Functions Functions. A function is a rule that relates two quantities so that each input value corresponds to exactly one output value. Define-
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 9, 2014 Carolyn Seaman Susan Martin University of Maryland, Baltimore.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
CS 320 Assignment 1 Rewriting the MISC Osystem class to support loading machine language programs at addresses other than 0 1.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
HTML Table and PHP Array
Processing Lab 3 – Header issues and trace editing Bryce Hutchinson Objectives: Fixing elevation issues Define an LMO function Pick first breaks Kill traces.
Algorithmic Problem Solving: Programming with Processing IS 101Y/CMSC 101 Computational Thinking and Design Thursday, September 11, 2014 Carolyn Seaman.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Understanding the TigerSHARC ALU pipeline Determining the speed of one stage of IIR filter – Part 2 Understanding the pipeline.
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Bell Ringer  Answer the following questions in your notebook: 1. What is your favorite ice cream flavor? a. chocolate b. strawberry c. vanilla 2. What.
IOD 202.
Intermediate 2 Computing Unit 2 - Software Development.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Data: Programming Design and Modularization IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 24, 2013 Marie desJardins University.
Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.
Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.
Aquarium Lab Series Developed by Alyce BradyAlyce Brady of Kalamazoo CollegeKalamazoo College.
Data: Programming Design and Modularization IS 101Y/CMSC 101 Computational Thinking and Design Thursday, September 25, 2014 Carolyn Seaman Susan Martin.
BIO1130 LAB 4 MICROEVOLUTION. Objectives of the lab: Understand various concepts of microevolution using simulated populations: Allelic and genotypic.
CompSci 42.1Intro to Java Anatomy of a Class & Terminology Running and Modifying a Program.
Design IS 101Y/CMSC 101 Computational Thinking and Design Thursday, October 9, 2014 Carolyn Seaman Susan Martin University of Maryland, Baltimore County.
Getting Started With Python Brendan Routledge
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Algorithms and Flowcharts
Learning to use a ‘For Loop’ and a ‘Variable’. Learning Objective To use a ‘For’ loop to build shapes within your program Use a variable to detect input.
Algorithmic Problem Solving: Programming with Processing IS 101Y/CMSC 101 Computational Thinking and Design Thursday, September 12, 2013 Carolyn Seaman.
How to Run a Java Program
This is a setup file for a Jeopardy game.
Python programming exercise
This is a setup file for a Jeopardy game.
This is a setup file for a Jeopardy game.
Introduction to Python
This is a setup file for a Jeopardy game.
Continuous & Random September 21, 2009.
CSCE 206 Lab Structured Programming in C
GCSE Computing.
Presentation transcript:

Simulation and Modeling: Predator-Prey Processing Lab IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 23, 2014 Carolyn Seaman Susan Martin University of Maryland, Baltimore County

What Does That Mean?? “It looks like you’re mixing “active” and “static” modes.” “static” mode is when your Processing program is just a list of instructions – those instructions are run once and then the program ends “active” mode is when you define the setup() and/or draw() functions and the program runs continuously looking for input If you have any functions defined, you can’t have commands outside those functions – you need to use setup() and draw() If you want anything to happen after setup() runs (e.g., when a key is pressed), you must have a draw() function (even if it’s empty)

Today’s Concepts Simulating processes Using data: Visualizing data (generating graphs) Outputting data (for use by Excel or other analysis programs) Code reading: Understanding Modifying

Simulating Processes Process model: We can represent “states” as collections of variables Semester game: Happiness, grades, wealth We can represent “actions” as choices from a list, parameter settings,... Semester game: Hours studying, hours in class... State1State2State3 Action1Action2Action3...

Data Representations for Simulations States: set of variables x, y, z,... at each time t x 1, x 2, x 3,... (values at time 1, 2, 3...) Can represent the sequence of values for state variable x as an array x[], indexed by time Multiple state variables  multiple arrays We’ll talk about arrays next time!! Alternative: if we don’t need to remember all of the values, we can just represent one or two values for each state variable: currentX currentX and prevX (if we want to measure/track change over time)

Visualizing Data How might we want to see (say) happiness, grades, and wealth over time? One way: table of numbers Another way: as a graph TimeHappinessGradesWealth 190%60%$ %70%$ %70%$ %80%$ %90%$200

Outputting Data Tables in Processing // open file for recording data PrintWriter OUTPUT = createWriter (FILENAME); Example: PrintWriter datafile= createWriter ("outfile.csv”); // print to output file OUTPUT.println (OUTPUTSTRING); Example: datafile.println (”time, happiness, grades, wealth”); Better example: datefile.println (“Your happiness level for this week is “, happiness);

Visualizing Data in Processing Graphs are just lines! Tricky part: figuring out how a particular state variable value will map to a screen location Time value has to “scale” to the width of the screen State variable value has to “scale” to the height of the screen

Graphing in Processing: Quadratic Example // Graph the function y=x^2 - 10, x= // Range of function: [-10, 390] void setup() { float x, prevX; float y, prevY; size (500, 500); // Generate the first y value and save it as prevY prevY = (-20*-20) - 10; // for each value of x, draw a line from the // previous (x, y) to the new (x,y) for ( x=-19 ; x<=20 ; x++ ) { y = x*x – 10; drawLine (x-1, prevY, x, y); prevY = y; } void drawLine (float prevX, float prevY, float x, float y) { line (screenX (prevX), screenY (prevY), screenX (x), screenY (y)); } // Scaling to the display window // Let's say y=400 will appear at screenY = 50 // y=0 will appear at screenY = 450 // y=-10 will appear at screenY=460 // So screenY = 450 – y // Let's put x=-20 at screenX = 50 // x=0 at screenX = 250 // x=20 at screenX = 450 // So screenX = (x+20)* float screenX (float x) { return ( (x+20)* ); } float screenY (float y) { return ( 450-y ); }

The Predator-Prey Cycle Lotka-Volterra equations “Actions” (fixed): birth rate (b pred, b prey ) and death rate (d pred, d prey ) of predators and prey States: population (n pred, n prey ) of predators and prey n prey = n prey + b prey *n prey - (d prey *n prey *n pred ) n pred = n pred + b pred *n pred *n prey - (d pred *n pred )

Code Reading First, just read the code, by yourself Break it up into chunks Recognize patterns from the Quadratic example Read the comments for clues Pair up – designate #1 and #2 #1 explains the code to #2, #2 corrects and asks questions Together, answer the following questions: What part of the code draws the blue line? What part of the code makes sure the graph doesn’t go up above the top of the screen? What part of the code makes sure the graph doesn’t go off the right hand edge of the screen? Where in the code calculates the numbers of predators and prey?

Modifying Code Download the.pde file from Blackboard Make the following modifications: Make the predator line green and the prey line yellow Ask the user to input the maximum number of cycles Replace the “while” loop with a “for” loop (the program should behave exactly the same way) Draw X and Y axes with meaningful labels and markings Test all your modifications by changing the values of height, width, border, max_cycles, max_pred, max_prey – it should still work, but the graph will look different