Chapter 13, Math A few Examples.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

A Quick Introduction to Processing
Variables and Operators
Chapter 4: Circular Functions Lesson 7: Scale-Change Images to Trig Functions Mrs. Parziale.
FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2011.
FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2010/2011.
Chapter 6 Color Image Processing Chapter 6 Color Image Processing.
Microsoft® Small Basic The Math Object Estimated time to complete this lesson: 1 hour.
Math – Getting Information from the Graph of a Function 1.
Review Blocks of code {.. A bunch of ‘statements’; } Structured programming Learning Processing: Slides by Don Smith 1.
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Week 2 Book Chapter 1 RGB Color codes. 2 2.Additive Color Mixing RGB The mixing of “ light ” Primary: Red, Green, Blue The complementary color “ White.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
Variables and Arithmetic. From last class More drawing functions: strokeWeight(n); // higher the n value broader the stroke fill(k) ; // single parameter.
Random numbers in Alice 3. Create world, add character (“Red” in this example) Dragged walk tile to right onto Run method. Click on “??? “ part of Tile.
CIS 3.5 Lecture 2.2 More programming with "Processing"
2-D Shapes, Color, and simple animation. 7 Basic Shapes Ellipse :: ellipse() Arc :: arc() Line :: line() Point :: point() Rectangle :: rect() Triangle.
Lesson Two: Everything You Need to Know
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
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
Animation Pages Function Function Definition Calling a function Parameters Return type and return statement.
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.
Introduction to Programming Python Lab 3: Arithmetic 22 January PythonLab3 lecture slides.ppt Ping Brennan
Graphics Primitives in Processing 1/14/2010. size(x, y) ; Sets the initial size of the screen Units are in pixels –Pixel == picture element –Small dots.
Review. Problem 1 What is the output of the following piece of code void increment(int x) { x++; } int main() { int y = 10; increment(y); cout
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.
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
Processing Variables. Variables Processing gives us several variables to play with These variables are always being updated and you can assume they have.
Programming in Processing Taught by Ms. Madsen Assistants: Ms. Fischer and Ms. Yen Winsor School, 2/20/08.
Variables. Something to mention… void setup(){ size(200, 200); background(255); smooth(); } void draw() { stroke(0); strokeWeight(abs(mouseX-pmouseX));
Visual C++ Programming: Concepts and Projects
Introduction to Programming
Processing Lecture.3 Loop and animation
Some of Chap 17.
Properties of Sine and Cosine Functions
Chapter 14, Translate & Rotate
Lesson Two: Everything You Need to Know
Lesson One: The Beginning Chapter 1: Pixels Learning Processing Daniel Shiffman Presentation by Donald W. Smith Graphics from
20 minutes maximum exhibits
Chapter 7 Functions.
Chapter 9 Arrays.
Chapter 6 Loops (iteration).
Chapter 7 Functions.
Box and Whisker Plots Algebra 2.
Review # 2 Math 8.
Value returning Functions
Mouse Inputs in Processing
Coding Concepts (Sub- Programs)
Chapter 5, Conditionals Brief Notes
Chapter 10 Algorithms.
Variables and Arithmetic
More programming with "Processing"
Pages:51-59 Section: Control1 : decisions
1.3 Describing Quantitative Data with Numbers
Color Image Processing
Just a question for Mac users:
Exam1 Review CSE113 B.Ramamurthy 4/17/2019 B.Ramamurthy.
Chapter 15, Images …a few points
Processing Environment
Chapter 4, Variables Brief Notes
Pages:51-59 Section: Control1 : decisions
IAT 800 Foundations of Computational Art and Design
Variables and Operators
Grade 12 Essential Math Measurement and Statistics
Range, Width, min-max Values and Graphs
Chapter 9 Arrays.
Presentation transcript:

Chapter 13, Math A few Examples

Modulo The modulo operator calculates the remainder when one number is divided by another. e.g. 17 modulo 6 = 5 17 % 6 = 5   Modulo applies to integers and floats: int a = 5 % 4; // Sets 'a' to 1 int b = 125 % 100; // Sets 'b' to 25 float c = 285.5 % 140.0; // Sets 'c' to 5.5 float d = 30.0 % 33.0; // Sets 'd' to 30.0

Uses in Processing Some of the ways in which it can be used in programming include: -Keeping a number within a limit -Cycling through an array of images

One of our favs, the moving car… With if() condition Try modulo instead of if() int x = 0; void draw() { background(255); rect(x, 20, 10, 5); x = x + 1; if(x>width) { x = 0; } println(x+1);   x = (x+1) % width;   Note how it works: 1 % 100 = 1 2 % 100 = 2 … 98 % 100 = 98 99 % 100 = 99 100 % 100 = 0

Uses to cycle through array Examine example 13-1 Each of the 4 numbers in the array will be set to a random grayscale color. Then it starts back to the first number in the array.

Uses to make decision First use for to subtract 20 px from size of rectangle Then use conditional to change stroke based on even or odd number. int size = 200; size(200,200); background(255); noFill(); strokeWeight(3); rectMode(CENTER); for (int i = 1; i<11; i++) { rect(100,100, size, size ); size = size - 20; }

The Map Function The map() function remaps a number from one range to another. Example:   void draw() { float r = map(mouseX, 0, width, 0, 255); background(r, 0, 255); } The above code: -Creates a variable “r” which will be used in the red position. -maps mouseX -from the range of 0 to width, which is 0 to 100 in this sketch -to the range of 0 to 255 The five arguments of the map, function Value: The value you want to map. Current min: The minimum of the value range Current max: The maximum of the value range New min: The minimum of the new value range New max: The maximum of the new value’s range. You can use the map() function to take any number and scale it to a new number that is more useful what you’re doing.