FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2010/2011.

Slides:



Advertisements
Similar presentations
Physical Computing INST. Kerem Odabaşı - YTU - Interactive Telecomunication Design Dept.
Advertisements

Creative Computing. Comments on Assignments Everyone did very well Report writing needs more work Jumping scale Update first then draw.
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.
Variables Conditionals Boolean Expressions Conditional Statements How a program produces different results based on varying circumstances if, else if,
Lesson One: The Beginning Chapter 3: Interaction Learning Processing: by Daniel Shiffman Presentation by Donald W. Smith Graphics from text.
Game with US Beginner Tutorial. Welcome!! Who I am What is Processing? Basic Coding Input Methods Images Classes Arrays.
A Quick Introduction to Processing
Recursion October 5, Reading Read pp in the text.
Emerging Platform#5: Processing 2 B. Ramamurthy 6/13/2014B. Ramamurthy, CS6511.
Computer Graphics Tz-Huan Huang National Taiwan University (Slides are based on Prof. Chen’s)
© Calvin College, Being abstract is something profoundly different from being vague... The purpose of abstraction is not to be vague, but to create.
Grundaufbau import processing.core.PApplet; public class Proc_Minimal extends PApplet { public void setup(){ size(1024, 768); frameRate(60.0f);
Lesson Four: More of the Same
IAT 334 Lab 2 Computer Graphics: Rocket, PImage. June 4, 2010IAT 3342 Outline  Programming concepts –Programming Computer Graphics –Transformations –Methods.
Translate, Rotate, Matrix Pages Function Function Definition Calling a function Parameters Return type and return statement.
IAT 334 Java using Processing ______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY.
FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2011.
FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2010/2011.
FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2011.
FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2011.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
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.
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
Processing Lecture.2 Mouse and Keyboard
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
Review of ArT3 Programming Course David Meredith Aalborg University
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
B. RAMAMURTHY Lab1 Discussion. General Instructions Attend the recitation (s), office hours (s) to get help Read the Lab description Understand what is.
Introduction to Image processing using processing.
NestedLoops-Mody7-part51 Two-Dimensional Arrays and Nested Loops – part 5 Rotations Barb Ericson Georgia Institute of Technology May 2007.
Review Inheritance Overloading and overriding. example1.pde.
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.
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
Mouse Inputs in Processing. Interacting with the Mouse mouseX and mouseY: pg mouseXmouseY –The position of the mouse in the canvas pmouseX and.
Lesson Two: Everything You Need to Know
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
Computer Science I Arrays. Parallel structures. Classwork/Homework: Build your own bouncing things.
Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.
B. RAMAMURTHY Processing and Programming cse
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.
Welcome to Processing Who does not have access to digital camera?
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
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.
Processing Variables. Variables Processing gives us several variables to play with These variables are always being updated and you can assume they have.
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.
IAT 800 Lecture 8 PImage and PFont. Oct 13, Fall 2009IAT 8002 Outline  Programming concepts –PImage –PFont.
Arrays. 2 Why do we care (about arrays)? What if you have a whole bunch of cars (or aliens or balls or ???) bouncing around the screen? How do we keep.
B. RAMAMURTHY Lab1 Discussion. General Instructions Attend the recitation (s), office hours (s) to get help Read the Lab description Understand what is.
Variables. Something to mention… void setup(){ size(200, 200); background(255); smooth(); } void draw() { stroke(0); strokeWeight(abs(mouseX-pmouseX));
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:
Emerging Platform#1: Processing 3
Chapter 14, Translate & Rotate
Computation as an Expressive Medium
For Net Art Lecture 2 J Parker
Exam1 Review CSE113 B.Ramamurthy 11/29/2018 B.Ramamurthy.
Mouse Inputs in Processing
Chapter 5, Conditionals Brief Notes
More programming with "Processing"
Translate, Rotate, Matrix
Animation Pages
Trigonometry & Random March 2, 2010.
How About Some PI? Trigonometry Feb 18,2009.
Chapter 13, Math A few Examples.
Presentation transcript:

FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2010/2011

Due date 26 Nov Collection via ACS Assignment 2

Requirements o Design and simulate set of objects (20%) o e.g. germs, ants, cars, o Use of "for" statements and “array” data structures (20%) o With interaction among objects (30%) o Creative object behaviors (30%) o Note that graphic is not important in this assignment

Object Following target

Example – Simple Following float a = 0; float cx = 80; float cy = 60; void setup() { smooth(); } void draw() { background(200); translate(cx,cy); rotate(a - PI/2); triangle(0, 10, -3, 0, 3, 0); float dx = mouseX - cx; float dy = mouseY - cy; a = atan2(dy, dx); cx += dx * 0.05; cy += dy * 0.05; }

Example – Simple Following 2 int n = 10; float[] angle = new float[n]; float[] x = new float[n]; float[] y = new float[n]; void setup() { smooth(); size(200, 200); for (int i=0; i<n; i++) { angle[i] = random(PI*2); x[i] = random(10, width - 10); y[i] = random(10, height - 10); } Define and initialization data (arrays)

Example – Simple Following 2 void draw() { background(200); for (int i=0; i<n; i++) { pushMatrix(); translate(x[i],y[i]); rotate(angle[i] - PI/2); triangle(0, 10, -3, 0, 3, 0); popMatrix(); } How to draw objects

Example – Simple Following 2 void follow (int i, float targetX, float targetY) { float dx = targetX - x[i]; float dy = targetY - y[i]; x[i] += dx * 0.05; y[i] += dy * 0.05; angle[i] = atan2(dy, dx); } How to move object to target location

Example – Simple Following 2 float tx, ty; if (i == 0){ tx = mouseX; ty = mouseY; } else { tx = x[i-1]; ty = y[i-1]; } follow(i, tx, ty); How to move object I (put the code in the for loop) First object follow mouse cursor Other object follow the next one

Wandering

Example – Simple Wandering int n = 20; float[] angle = new float[n]; float[] x = new float[n]; float[] y = new float[n]; float[] tx = new float[n]; float[] ty = new float[n]; void setup() { smooth(); size(200, 200); for (int i=0; i<n; i++) { angle[i] = random(PI*2); x[i] = random(10, width - 10); y[i] = random(10, height - 10); tx[i] = x[i] + random(-4, 4); ty[i] = y[i] + random(-4, 4); } Define and initialization data (arrays)

Example – Simple Wandering void draw() { background(200); stroke(0); for (int i=0; i<n; i++) { pushMatrix(); translate(x[i],y[i]); rotate(angle[i] - PI/2); triangle(0, 10, -3, 0, 3, 0); popMatrix(); } How to draw objects

Example – Simple Wandering void follow (int i, float targetX, float targetY, float ratio) { float dx = targetX - x[i]; float dy = targetY - y[i]; angle[i] = atan2(dy, dx); x[i] += dx * ratio; y[i] += dy * ratio; if (x[i] < 0) { x[i] = width; } if (x[i] > width) { x[i] = 0; } if (y[i] < 0) { y[i] = height; } if (y[i] > height) { y[i] = 0; } } How to move object to target location

Example – Simple Wandering float dx = tx[i] - x[i]; float dy = ty[i] - y[i]; float d = dist(tx[i], ty[i], x[i], y[i]); tx[i] = x[i] + (dx / d) * 20 + random(-3, 3); ty[i] = y[i] + (dy / d) * 20 + random(-3, 3); //ellipse(tx[i], ty[i], 4, 4); follow(i, tx[i], ty[i], 0.05); How to move object I (put the code in the for loop)

Avoiding

Example – Simple Avoiding stroke(150); for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { if (i != j) { float d = dist(x[i], y[i], x[j], y[j]); if (d < 30) { line(x[i], y[i], x[j], y[j]); tx[i] += constrain(10.0 / (x[i]-x[j]), -5, 5); ty[i] += constrain(10.0 / (y[i]-y[j]), -5, 5); } How to avoid other objects (put the code in the draw() function)

Flock

Example – Simple Flock stroke(150); for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { if (i != j) { float d = dist(tx[i], ty[i], tx[j], ty[j]); if (d < 20) // if close enough { line(tx[i], ty[i], tx[j], ty[j]); tx[i] += constrain(10.0 / (tx[i]-tx[j]), -5, 5); ty[i] += constrain(10.0 / (ty[i]-ty[j]), -5, 5); } How to simulate flocks (put the code in the draw() function)