Trigonometry & Random March 2, 2010.

Slides:



Advertisements
Similar presentations
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 13 Fall 2010.
Advertisements

Code Elements and Processing Coordinate System. Code elements: pages Comments: are documentation notes that are ignored by the computer but are.
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.
Grundaufbau import processing.core.PApplet; public class Proc_Minimal extends PApplet { public void setup(){ size(1024, 768); frameRate(60.0f);
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.
13-3: Radian Measure Radian Measure There are 360º in a circle The circumference of a circle = 2r. So if the radius of a circle were 1, then there a.
IAT 355 Lecture 4 Computer Graphics: Rocket. May 9, 2014IAT 3552 Outline  Programming concepts –Programming Computer Graphics –Transformations –Methods.
Processing can load images, display them on the screen, and change their size, position, opacity, and tint. You can load gif, png and jpg images in processing.
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
Continuous February 16, Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
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.
Variables and Arithmetic. From last class More drawing functions: strokeWeight(n); // higher the n value broader the stroke fill(k) ; // single parameter.
Transforming Geometry Groundhog Day. Drawing Quads In a 300 by 200 window, draw two quads of different colors. Don’t show the grey grid.
How to start Visual Studio 2008 or 2010 (command-line program)
Review Recursion Call Stack. Two-dimensional Arrays Visualized as a grid int[][] grays = {{0, 20, 40}, {60, 80, 100}, {120, 140, 160}, {180, 200, 220}};
Functions. Functions are named blocks of code. Functions allow complex programs to be broken down into smaller, simpler tasks. Functions allow commonly.
© Calvin College, For a number of years I have been familiar with the observation that the quality of programmers is a decreasing function of the.
B. RAMAMURTHY Lab1 Discussion. General Instructions Attend the recitation (s), office hours (s) to get help Read the Lab description Understand what is.
Review Loops – Condition – Index Functions – Definition – Call – Parameters – Return value.
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.
Review Inheritance Overloading and overriding. example1.pde.
2-D Shapes, Color, and simple animation. 7 Basic Shapes Ellipse :: ellipse() Arc :: arc() Line :: line() Point :: point() Rectangle :: rect() Triangle.
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
Objects. The Heart of the Matter - The "Black Box" Object-oriented software is all about objects. An object is a "black box" which receives and sends.
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.
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.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
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 Objects – data fields – constructors – Methods Classes.
B. RAMAMURTHY Lab1 Discussion. General Instructions Attend the recitation (s), office hours (s) to get help Read the Lab description Understand what is.
Loops. About the Midterm Exam.. Exam on March 12 Monday (tentatively) Review on March 5.
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:
Some of Chap 17.
Computer Graphics: Rocket, Java: Class
Angles and Their Measure
Computer Science I Variables. Methods.
Chapter 14, Translate & Rotate
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.
Midterm Exam Would the following students please come to the board and share your methods of solving with solutions:
Radian Measure of a Central Angle
Chapter 6 Loops (iteration).
Chapter 7 Functions.
Code Elements and Processing Coordinate System
Programming for Artists
Chapter 5, Conditionals Brief Notes
Code Elements and Processing Coordinate System
A Few Notes Starting August 29, 2018
A Few Notes August 30, 2017.
How do we convert angle measures between degrees and radians?
IAT 265 Lecture 2: Java Loops, Arrays Processing setup, draw, mouse Shapes Transformations, Push/Pop.
Just a question for Mac users:
Translate, Rotate, Matrix
Lab1 Discussion B. Ramamurthy.
Loops & Nested Loops CSE 120 Winter 2019
Chapter 10 Algorithms.
Chapter 4, Variables Brief Notes
How About Some PI? Trigonometry Feb 18,2009.
Unit 4: Circles and Volume
Continuous & Random September 21, 2009.
Chapter 13, Math A few Examples.
Presentation transcript:

Trigonometry & Random March 2, 2010

Trigonometry

Angles and Waves Angles can be measured in degrees or radians Pi is the ratio of the circumference of a circle to its diameter Angles can be converted from degrees to radians with radians() Angles can be converted from radians to degrees with degrees()

Sine

Sine Wave in Processing Angles are specified in radians in sin() and cos() functions size(700, 100); noStroke(); fill(0); float angle = 0.0; for (int x = 0; x <= width; x += 5) { float y = map(sin(angle), -1, 1, 2*height/3, height/3); rect(x, y, 2, 4); angle += PI/20.0; }

Following the sine void setup() { size(700, 100); ellipseMode(CENTER); fill(0); } float angle = 0.0; float time = 0; float yPos = 0; void draw() { background(255); yPos = map(sin(angle), -1, 1, 0.8*height, 0.2*height); ellipse(time, yPos, 20, 20); if (time>width) { time=0; time += 5; angle += PI/20.0;

In a spiral void setup() { size(200,200); noStroke(); smooth(); } float radius = 1.0; int deg = 0; float increment=random(20); void draw() { float angle = radians(deg); float x = width/2 + (cos(angle) * radius); float y = height/2 + (sin(angle) * radius); ellipse(x, y, 6, 6); deg += 11; if(radius>width/2+1) { radius=0; increment=random(20); radius = radius + 0.34;

Earth and Moon sort of void setup() { size(400,400); noStroke(); smooth(); ellipseMode(CENTER); } void drawBody(float angleRot, int radiusOrbit, int radiusDot) { float x = map(sin(angleRot), -1, 1, width/2-radiusOrbit, width/2+radiusOrbit) ; float y = map(cos(angleRot), -1, 1, width/2-radiusOrbit, width/2+radiusOrbit) ; ellipse(x, y, radiusDot, radiusDot) ; float angle = 0 ; void draw() { background(0) ; fill(0,255,0) ; drawBody(angle, width/10, width/10) ; fill(255,255,0) ; drawBody(angle+PI, 4*width/10, width/30) ; angle += 0.01 ;

Rotating Rectangles void drawBody(float angleRot, int radiusOrbit, int radiusDot) { int lowEnd = width/2-radiusOrbit ; int highEnd = width/2+radiusOrbit ; float x = map(sin(angleRot), -1, 1, lowEnd, highEnd) ; float y = map(cos(angleRot), -1, 1, lowEnd, highEnd) ; pushMatrix() ; translate(x, y) ; rotate(-angleRot) ; rect(0, 0, 2*radiusDot, radiusDot) ; popMatrix() ; } Be sure to add rectMode(CENTER) to setup()

Lab Exercise Fill the canvas with a regular, repeating pattern that uses the sine function.

Random Numbers Assume float f; To generate a pseudo random number between 0 and high and assign it to f f = random(high); To generate a pseudo random number between low and high f = random(low, high);

Printing Random Numbers for (int i=0; i<10; i++) { print(i + ". "); println(random(100)); } How do the print statements print and println differ? What’s the + inside of a print

Sample Code float f = random(5.2); // Assign f a float value from 0 to 5.2 int i = random(5.2); // ERROR! Can't assign a float to an int int j = (int)random(5.2); // Assign j an int value from 0 to 5

Perlin Noise A smoother noise void setup() { size(800,200); noStroke(); noiseSeed(0) ; fill(0) ; for (int x=0; x<width; x++) { float yN = noise(x*0.1) * 100 ; ellipse(x,yN, 5, 5) ; float yR = random(1.0) * 100 ; ellipse(x,yR+100, 5, 5) ; }

Noisy Mountains void setup() { size(800,200); background(0,0,200) ; noiseSeed(0) ; stroke(0, 150,0) ; for (int x=0; x<width; x++) { float yN = noise(x*0.01) * 150 ; line(x, yN, x, height) ; }

In-class Lab Modify the groundhog to be a bit more random or noisy Or modify anything else