Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 07 Fall 2010.

Slides:



Advertisements
Similar presentations
First of all – lets look at the windows you are going to use. At the top you have a toolbar, with all your various tools you can use when customising your.
Advertisements

(application of the Ambiguous Case
(Say each word as it appears on the screen.)
(Say each word as it appears on the screen.)
Transformations We want to be able to make changes to the image larger/smaller rotate move This can be efficiently achieved through mathematical operations.
ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
Mathematics Algebra 1 Trigonometry Geometry The Meaning of Numbers Choosing the Correct Equation(s) Trig and Geometry Mathematics is a language. It is.
Click here to enter. Click a menu option to view more details Starters Main Courses Desserts Click on the coffee cup to return when Navigating For Vocabulary.
Roads in MineSight.
1 Normal Probability Distributions. 2 Review relative frequency histogram 1/10 2/10 4/10 2/10 1/10 Values of a variable, say test scores In.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
1 An introduction to programming concepts with Scratch.
Quantum Theory of Hydrogen shrödinger's equation for hydrogen separation of variables “A facility for quotations covers the absence of original thought.”—
Finding Exact Values For Trigonometry Functions (Then Using those Values to Evaluate Trigonometry functions and Solve Trigonometry Equations)
What is Scratch? Scratch as Logo Dr. Ben Schafer Department of Computer Science University of Northern Iowa.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
Trigonometry-7 Trigonometry in Four Quadrants. Trigonometry The Four Quadrants Co-ordinates in the First Quadrant Trig Ratios in the First Quadrant Co-ordinates.
The Game of Algebra or The Other Side of Arithmetic The Game of Algebra or The Other Side of Arithmetic © 2007 Herbert I. Gross by Herbert I. Gross & Richard.
1 Circular Functions Just a fancy name for Trigonometry –Thinking of triangles as central angles in a circle Have done trigonometry ever since grade 9.
SPECIAL USING TRIANGLES Computing the Values of Trig Functions of Acute Angles.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Introduction to Scratch!
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 8 Fall 2010.
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
3–D Helium Molecule Tutorial Alice Project Duke University Professor Susan H. Rodger Gaetjens Lezin June 2008.
Trigonometric Equations M 140 Precalculus V. J. Motto.
Unit Circle You will use the Unit Circle for nearly every computation for the rest of Trig. Make the most of today… Memorize the angles and Radians Memorize.
Our goal in todays lesson will be to build the parts of this unit circle. You will then want to get it memorized because you will use many facts from.
Art 315 Lecture 5 Dr. J. Parker AB 606. Last time … We wrote our first program. We used a tool called GameMaker. The program we wrote causes a ball to.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
Art 315 Lecture 6 Dr. J. Parker. Variables Variables are one of a few key concepts in programming that must be understood. Many engineering/cs students.
1 Loops and Branches Ch 21 and Ch18 And how you can use them to draw cool pictures!
ACT MATH TEST You are given 60 minutes to answer 60 questions. That’s 60 seconds or less per question. You should memorize the instructions for the Math.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 11 Fall 2010.
Adding Vectors Vectors are ‘magnitudes’(ie: values) with a direction
Art 321 Lecture 7 Dr. J. Parker. Programming In order to ‘make things happen’ on a computer, you really have to program it. Programming is not hard and.
Moving Around in Scratch The Basics… -You do want to have Scratch open as you will be creating a program. -Follow the instructions and if you have questions.
2015 CSE/EGR Summer Camps 1 Computer Science Concepts 1. What is an algorithm? 2. Binary information coding 3. Programming concepts via Scratch Designed.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
GAME:IT Helicopter Objectives: Review skills in making directional sprites Create objects that shoot and destroy for points Create random enemies on the.
Loops & Graphics IP 10 Mr. Mellesmoen Recall Earlier we wrote a program listing numbers from 1 – 24 i=1 start: TextWindow.WriteLine(i) i=i+1 If.
Make a Great Map of Your Engineering Building Traverse ©Mar Dr. B. C. Paul Note – This presentation contains screen shots from the Mine Sight and.
The Unit Circle M 140 Precalculus V. J. Motto. Remembering the “special” right triangles from geometry. The first one is formed by drawing the diagonal.
Trigonometric Functions: The Unit Circle Section 4.2.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
Teaching to the Big Ideas K - 3. Getting to 20 You are on a number line. You can jump however you want as long as you always take the same size jump.
Conditional Statements.  Quiz  Hand in your jQuery exercises from last lecture  They don't have to be 100% perfect to get full credit  They do have.
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
1 Project designed and created by M. Shajith Kumar.
1.6 Trigonometric Functions: The Unit circle
Opening Questions Please solve these… A 7” 9” #1 Find the measure of ےA 30° 10” x #2 Find x.
ILLUSTRATING INTEGERS The University of Texas at Dallas.
Trigonometric Functions: The Unit Circle  Identify a unit circle and describe its relationship to real numbers.  Evaluate trigonometric functions.
The Law of Averages. What does the law of average say? We know that, from the definition of probability, in the long run the frequency of some event will.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Loops Brent M. Dingle Texas A&M University Chapter 6 – Section 6.3 Multiway Branches (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
1 Math CAMPPP 2012 Plenary 1 Why students struggle with fractions.
Debugging and Random Numbers
Right-angled triangles A right-angled triangle contains a right angle. The longest side opposite the right angle is called the hypotenuse. Teacher.
Go to =>
Introduction to TouchDevelop
THE UNIT CIRCLE.
Go to =>
Go to =>
Dr. Fowler – CCM1A Unit 1 – Lesson 9 Pythagorean Theorem
Presentation transcript:

Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 07 Fall 2010

Checking the Value We very often want to a selection of things depending on what the value of a variable is. In daily life: - if a person looks less than 25 years old then check their ID. (age < 25) -If the light is red then stop; if green then go. light=red light=green If it’s 9 AM then go to class, otherwise maybe another coffee. (time < 9)

Test Variable A common element in these questions is the use of the word ‘IF’. This is the word we use in most programming languages for the purpose of checking a value. There is very little that a program can do without and ‘IF’ testing ability. What does it look like in GameMaker? It’s a ‘test variable’ box.

Test Variable Asks for the variable name. Asks for a value to compare against Asks for the nature of the comparison: equal to, less than, greater than

Test Variable The Test Variable box is a part of the Control menu.

Let’s fix Atom Let the electrons move a bit before appearing somewhere else. Keep the electrons away from the nucleus. Perhaps the particles in the nucleus should move just a bit. Give the impression of reality.

Atom Random(100) gives a number between Test is ‘random>30’ (=1/3 times) If true, then do the next statement, which is the random jump.

Random Jump The random jump is the real problem, because we wish to make it a bit less random. We want it to jump only to places where the nucleus is not. How could we arrange for the random jumps to avoid the nucleus?

One Solution (mine) Pick a random distance from the center of the image where the electron will move. Can’t be less than, say, random (200) Pick a random angle. Know any geometry? Trig?

Trigonometry This is high school stuff, and is not essential. There are other solutions to this problem. [List some …] Still, an artist should have a fair knowledge of geometry. Trig - onometry = Triangle - measure

Trigonometry This is the most basic stuff. Below is a right triangle, meaning that it has one 90 degree angle. We can give the sides and angles names for convenient reference. Right angle angle a Hypotenuse Angle b Fun fact: The angles in any triangle add up to 180 degrees. Side y opposite angle a Side x opposite angle b Hypotenuse opposite right angle

Trigonometry There are ratios in a right triangle that are important. Keep the hypotenuse = 1 for standardization. We can always draw a right triangle within a circle like so. Remember Pythagoras: Hypotenuse 2 =x 2 + y 2 x y Hypotenuse

Trigonometry We will define some things and see how they can be useful later. Define sine (a) to be the ratio of y/hypotenuse, or the ratio of the side opposite a to the hypotenuse. In this case the hypotenuse Is always = 1, so sine(a) = y. How does sine(a) change As a changes? a y Hypotenuse

Trigonometry We will define some things and see how they can be useful later. Define sine (a) to be the ratio of y/hypotenuse, or the ratio of the side opposite a to the hypotenuse. Note: angles are in radians. Boo!

So what? As always, math is only memorable if we can do something useful with it. In this case, we can do the following: given an angle and a side of a right triangle we can figure out the rest. Right angle angle a Hypotenuse Angle b sine a = y/hypotenuse so y = (sine a)*hypotenuse a+b+90 = 180 so b = 90-a sine b = x/hypotenuse so x = (sine b)*hypotenuse x y

Back to the problem We want to avoid the nucleus, remember? My solution is to pick a radius (distance) bigger than 100 at random, and an angle at random, and put the electron at that point. a d y x

Back to the problem We have a right triangle, and sine a = y/d, or y = a*d. Given a random d and a we can get the x,y coordinates! a d y x

Coordinates The (x, y) values are coordinates, as you know, and are in fact Cartesian coordinates, named after Rene Decartes. The (d, a) values can also be thought of as coordinates, and are called polar coordinates. They are equivalent. x y

Aside: Star trek Ship direction is Star Trek is given as a pair of numbers: EG 45 mark 60 These are polar coordinates (spherical polar) in 3D. 45 angle units 60 Angle units There are 1000 angle units In a circle, rather than 360 degrees (they went metric, I guess)

Back to reality When many things are to be done we have to group the statements using the triangle thingys. ‘Begin’ – ‘End’

One Solution (mine) If this one thing is true (this is essentially a coin toss) Then do everything between the triangles Otherwise don’t do anything. Note the indenting – this is intended to show Which things are conditional (part of the IF)

And so …

A problem Why do the electrons only appear in the upper left of the room? Any ideas? The process of finding the problem in a program like this is called debugging. This kind of problem is called a ‘bug’ (why?)

A problem The problem is: We assumed that the coordinate system was centered at 0,0. It is not. We center the coordinates at the center of the screen, where the nucleus is. So the ‘jump to’ instruction needs to be changed.

A problem The center is (304, 208):

A problem fixed Fixed!

Another example Have the object’s sprite change every 120 steps (4 seconds) It means counting the steps – each step, add one to a variable. When the variable’s value reaches 30 (if value > 30) then change the sprite AND set the variable to zero again. Make sense? Change sprite is a click and drop item in the Main1 menu.

Another example So: create the variable when the object is created, call it ‘count’, set it to 0. Relative Is this right?

Another example It works. But it only changes the sprite once. Is that what we wanted? If we want to change every 4 seconds then we have to keep track of which sprite will be next. Changing to proton is only a change if the current sprite is not a proton. We can have a variable keep track of the current sprite, thus telling us about the next one.

Another example The object we’re working with is the electron. Create a variable called current_sprite and initialize it to 0. The value 0 means ‘the electron sprite’, the one it starts with. The variable and the sprite must always agree. Current_sprite=1 means proton_sprite Current_sprite=2 means neutron_sprite When the sprite changes, we add 1 to the variable and change the sprite to agree.

Another example If count is larger than 120 start of a block set variable count to 0 add 1 to current_sprite if current_sprite is greater than 2 set variable current_sprite to 0 if current_sprite is equal to 0 change sprite into spr_electron if current_sprite is equal to 1 change sprite into spr_proton if current_sprite is equal to 2 change sprite into spr_neutron end of block

Another example A problem. We keep adding 1 to current_sprite, and it gets to be 2, then 3, then 4, and so on. There are no sprites for numbers bigger than 2. Solution: When current_sprite becomes equal to 3, set it to 0 again. Then it goes 0, 1, 2, 0, 1, 2, … This is called modulo 3 counting.

Another example Here’s a first try: If count is larger than 120 start of a block set variable count to 0 add 1 to current_sprite if current_sprite is equal to 0 change sprite into spr_electron if current_sprite is equal to 1 change sprite into spr_proton if current_sprite is equal to 2 change sprite into spr_neutron end of block

It works (…naturally).

If We have seen: 1.How a variable can be tested and how code can be executed conditionally upon that test. 2.That collections of statements can be executed based on one IF. 3. That IF tests can be embedded in one another. … but there is more!

If We are driving south down a country road, and get to a ‘T’ intersection. If our destination is to the West, then we turn right. Otherwise we turn left. This can be done as 2 statements: If destination is to the West, turn right. If destination is to the East, turn left.

If We are driving south down a country road, and get to a ‘T’ intersection. It can also be done as a more obvious set of statements: If destination is to the West, turn right. else turn left.

Else I know of no case where the ELSE is necessary, but it is a more natural statement of the process, and is briefer than restating the condition. We use ‘else’ and ‘otherwise’ in conversation; it makes sense to have them in a computer language.

Else Our previous example using ELSE: If count is larger than 120 start of a block set variable count to 0 add 1 to current_sprite if current_sprite is equal to 0 change sprite into spr_electron else if current_sprite is equal to 1 change sprite into spr_proton else change sprite into spr_neutron end of block

Else Not clear this is better, but it is sometimes an advantage to have a binary (yes/no, true/false) choice. If (light is red) then stop else go If (count less than 10) do some thing else quit