22 Pages

rec4

Course: CS 177, Fall 2010
School: Purdue
Rating:
 
 
 
 
 

Word Count: 796

Document Preview

177 CS Week 4 Recitation Slides for Loop if statement and range 1 Announcements EXAM 1 Wednesday 09/29 6:30p - 7:30p EE 129 2 ANY QUESTIONS? 3 Lets remember for Loop def decreaseRed(picture): for p in getPixels(picture): value = getRed(p) setRed(p,value*0.5) 4 What is wrong here? def decreaseRed(picture): for p in getPixels(picture): value = getRed(p) setRed(p,value*0.5) Indentation is wrong! This...

Register Now

Unformatted Document Excerpt

Coursehero >> Indiana >> Purdue >> CS 177

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
177 CS Week 4 Recitation Slides for Loop if statement and range 1 Announcements EXAM 1 Wednesday 09/29 6:30p - 7:30p EE 129 2 ANY QUESTIONS? 3 Lets remember for Loop def decreaseRed(picture): for p in getPixels(picture): value = getRed(p) setRed(p,value*0.5) 4 What is wrong here? def decreaseRed(picture): for p in getPixels(picture): value = getRed(p) setRed(p,value*0.5) Indentation is wrong! This statement is not inside the for loop. Only the last pixel is changed. 5 Clearing Blue def clearBlue(picture): for p in getPixels(picture): setBlue(p,0) Again, this will work for any picture. 6 Lightening and darkening an image def lighten(picture): def darken(picture): for px in getPixels(picture): for px in getPixels(picture): color = getColor(px) color = getColor(px) color = makeLighter(color) color = makeDarker(color) setColor(px ,color) setColor(px ,color) 7 Creating a negative Lets think it through R,G,B go from 0 to 255 Lets say Red is 10. Thats very light red. 8 Whats the opposite? LOTS of Red! The negative of that would be 255 10 = 245 So, for each pixel, if we negate each color component in creating a new color, we negate the whole picture. Creating a negative def negative(picture): for px in getPixels(picture): red = getRed(px) green = getGreen(px) blue = getBlue(px) negColor=makeColor( 255-red, 255-green, 255-blue) negative of negative is setColor(px,negColor) the original picture 9 Converting to greyscale We know that if red=green=blue, we get grey 10 But what value do we set all three to? What we need is a value representing the darkness of the color, the luminance There are lots of ways of getting it, but one way that works reasonably well is really simplesimply take the average: Converting to greyscale def greyScale(picture): for p in getPixels(picture): intensity = (getRed(p)+getGreen(p)+getBlue(p))/3 setColor(p,makeColor(intensity,intensity,intensity)) 11 Building a better greyscale Well weight red, green, def greyScaleNew(picture): and blue based on how for px in getPixels(picture): light we perceive them newRed = getRed(px) * 0.299 to be, based on newGreen = getGreen(px) * 0.587 laboratory experiments. newBlue = getBlue(px) * 0.114 luminance = newRed + newGreen + newBlue setColor(px,makeColor(luminance,luminance,luminance)) 12 Comparing the two greyscales: Average on left, weighted on right 13 How to save the changes? writePictureTo(picture,filename) Windows: MacOS writePictureTo(picture,"E:/temp/output.jpg") writePictureTo(picture,"/home/users/guzdial/med iasources/output.jpg") Writes the picture out as a JPEG Be sure to end your filename as .jpg! If you dont specify a full path, will be saved in the same directory as JES. 14 if statement An statement if takes a logical expression and evaluates it. If it is true, the statements in if block are executed, otherwise, they are not executed. if a < 100: print "a is small 15 If a is 45, prints a is small If a is 153, does nothing if - else statement Similarly, the logical expression is evaluated. If it is true, the statements in if block are executed, otherwise, the statements in else block are executed. if a < 100: print "a is small" else: print "a is large" 16 If a is 45, prints a is small If a is 153, prints a is large Lets count the red pixels in a picture def countRedPixels(picture): redCount = 0 for p in getPixels(picture): color = getColor(p) if(color == red): redCount = redCount + 1 print redCount 17 Lets count the the non-red pixels too def countPixels(picture): redCount = 0 nonRedCount = 0 for p in getPixels(picture): color = getColor(p) if(color == red): redCount = redCount + 1 else: nonRedCount = nonRedCount + 1 print redCount print nonRedCount 18 function range Range is a function that returns a sequence If range has only one input parameter: (i.e range(input)) It generates the sequence of all the non-negative integers that are less than the input parameter value the generated sequence starts with 0 increment is 1 the last element of the sequence is the value of input parameter 1 >>> range(3) >>> range(1) >>> range(-1) [0,1,2] >>> range(9) [0, 1, 2, 3, 4, 5, 6, 7, 8] [0] >>> range(0) [] [] >>> range(-5) [] 19 function range If two inputs (i.e range(first_input, second_input)): It generated the sequence of all the integers that are greater than or equal to the first_input value and less than the second_input value the first element of the sequence is the value of first_input increment is 1 the last element of the sequence is the value of second_input 1 >>> range(0, 3) >>> range(4, 7) [0, 1, 2] >>> range(0, 10) [4, 5, 6] >>> range(7, 4) >>> range(-2, 2) [-2, -1, 0, 1] >>> range(-2, -5) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] [] [] 20 function range If three inputs (i.e. range(first_input, second_input, third_input)): the sequence starts with the first_input value increment is third-input If increment is positive the sequence ends with the largest value less than second_input If increment is negative the sequence ends with the smallest value greater than second_input >>> range(0, 3, 1) >>> range(1, 7, 2) >>> range(-5, 5, 3) [0, 1, 2] >>> range(0, 6, 3) [0, 3] [1, 3, 5] >>> range(-7, -1, 2) [-7, -5, -3] [-5, -2, 1, 4] >>> range(7, 1, -2) [7, 5, 3] 21 Final QUESTIONS??? 22
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Purdue - CS - 177
CS 177 Week 5 Recitation SlidesMirroring and copying images,Using for Loop, if statement, and range1AnnouncementsEXAM 1Wednesday 09/296:30p - 7:30pEE 1292ANY QUESTIONS?3Horizontal mirror recipe4mirroring means intuitively &quot;flipping around&quot; a
Purdue - CS - 177
CS 177 Week 6 Recitation SlidesScalingDrawing on imagesVector-based Vs. Bitmap graphical representation1AnnouncementsnEXAM 1Wednesday 09/296:30p - 7:30pEE 1292ScalingnScaling a picture (smaller or larger) has to do withsampling the source p
Purdue - CS - 177
CS 177 Week 7 Recitation SlidesModifying Sounds using Loops+Discussion of some Exam Questions1ANY QUESTIONS?2Q3. Consider the following function definition:def sum(a, b):c=a+breturn cprint Hello WorldWhat is the output when you execute sum(4,5
Purdue - CS - 177
CS 177 Week 8 Recitation SlidesJES Sound functionsandModifying SoundsIncreasing/Decreasing VolumeMaximizing (Normalizing)SplicingReversingMirroring1ANY QUESTIONS?2Lets remember SoundWe store sounds as array of integer values Each value is st
Purdue - CS - 177
CS 177 Week 9 Recitation SlidesSound Combination, SamplingandBuilding Bigger Programs1ANY QUESTIONS?2Media File Path is Important&gt; setMediaPath() #must be called before getMediaPath&gt; c4=makeSound(getMediaPath(&quot;bassoon-c4.wav&quot;)&gt; e4=makeSound(getM
Purdue - CS - 177
CS 177 Week 9 Recitation SlidesCreating and Modifying Text1ANY QUESTIONS?2Text and StringLike sound, text is usually processed in an arraya longline of charactersStrings are defined with quote marks:Single quotes my string Double quotes my strin
Purdue - CS - 177
CS 177 Week 11 Recitation SlidesWriting out programs, Reading from the Internetand Using Modules1ANY QUESTIONS?2Writing a program to writeprogramsFirst, a function that will automatically change the textstring that the program littlepicture draws
Purdue - CS - 177
CS 177 Week 12 Recitation SlidesAdvanced Text Techniques and Making Text for theWeb + (some examII questions)1Q21. Suppose you have the following string:str = &quot;Purdue University&quot;Which of the following statements will produce the same result ofstr.f
Purdue - CS - 177
CS 177 Week 13 Recitation SlidesHTML and Relational Database1ANY QUESTIONS?2What is HTML?Language which specifies the format of the text on theworld wide web.a.k.a. Hyper Text Markup Language.Was originally created with the intent of identifying
Purdue - CS - 177
CS 177 Week 15 Recitation SlidesSpeedBig-O notationSorting and SearchingandFunctions with Recursion1ANY QUESTIONS?2More than one way to solve aproblemTheres always more than one way to solve a problem.3You can walk to one place around the blo
Purdue - CS - 177
CS 177 Week 16 Recitation SlidesObject Oriented Programming1ANY QUESTIONS?2Procedural Abstractions3Define tasks to be performedBreak tasks into smaller and smaller pieces Until you reach an implementable sizeDefine the data to be manipulatedDes
Purdue - CS - 177
Q1. What is the name of the function that will display the names of variables in yourprogram?A)showVars()B)showNames()C)showFiles()D)showObjects()Key: AQ2. The following function will result in a JES error. Why?A)B)C)D)In line 1 the : is m
Purdue - CS - 177
The Concept of Team WorkStarting with Lab 9 you will be doing lab exercises in groups of two or three students. You willalso do projects in groups. The content of this document applies to labs and to projects. Youshould elect one student as the group l
Purdue - CS - 177
Teaming: Reflection Paper GuidelinesPart of a successful teaming experience is the ability to critically reflect on that experience andarticulate it well to others. College-level writing that has been spell-checked and proof read isexpected. This paper
Purdue - CS - 177
If you want to turnin your project from your home you can follow the followingsteps:1. Download the SSH Secure Shell Client 3.2.9. You can google it or find atftp:/ftp.tm.informatik.uni-frankfurt.de/pub/prog/SSHSecureShellClient3.2.9.exeThis program i
University of Sydney - MATH - 1011
Periodic Functions[1.2 of the Notes, Chapter 1 ofStewart is also useful]There are many examples in natureof events repeating themselves overand over again. Nature is periodic!Example 1If you plot the length of day againsttime the graph repeats its
Purdue - HIS - 306
NewFinalExam1.ComparethedifferencesbetweentheEastandWestintermsofinfluencandlandscapearchitecture.StudentResponse:EgyptianlandscapeswemadefertilebytheoverfgardenswereformalandmadelandscapebecausnonaturallandscapestoirrigationsystemswereinEgypti
Purdue - HIS - 306
History of Horticulture: Lecture 1Lecture 1Dating the Past: Geologic,Archeologic, Biologic, and HumanArcheologic,CultureDating the Past (years ago)Dating the Past (years ago)1History of Horticulture: Lecture 1Dating the Past (years ago)The Emer
Purdue - HIS - 306
History of Horticulture: Lecture 2Lecture 2Early Humans and the Prehistoric Record:HumanPlant InteractionDating the PastHuman Fossils &amp; ToolsHominid fossils and tools date to 1.8 million yearsago.There is some evidence of tools in Europe as early
Purdue - HIS - 306
History of Horticulture: Lecture 3Lecture 3Neolithic Revolution and theDiscovery of AgricultureDating the PastThe Great Technological Discoveriesof Pre-historyThe discovery of toolsThe discovery and control of fireThe invention of agricultureThe
Purdue - HIS - 306
History of Horticulture: Lecture 4Lecture 4Geography of Plant DomesticationAlphonse de Candolle (18061893)Charles Darwin (18091882)1858 Origin of SpeciesNicholas Ivanovitch Vavilov (18871943)Alphonse de Candolle (18061893)Alphonse De Candolle as a
Purdue - HIS - 306
History of Horticulture: Lecture 5Lecture 5Centers of Origin of Crop PlantsThe eight Vavilovian Centers of Origin for crop plantsOLD WORLDI. Chinese Center: The largest independent centerwhich includes the mountainous regions of centraland western
Purdue - HIS - 306
NewFinalExam1.ComparethedifferencesbetweentheEastandWestintermsofinfluencandlandscapearchitecture.StudentResponse:EgyptianlandscapeswemadefertilebytheoverfgardenswereformalandmadelandscapebecausnonaturallandscapestoirrigationsystemswereinEgypti
Purdue - HIS - 306
Title:exam1Started:Submitted:Timespent:Totalscore:February21,20088:26AMFebruary21,20088:58AM00:31:4799/100=99% Totalscoreadjustedby0.0Maximumpossiblescore:1001.ToxicsubstancestendtobeeliminatedinStudentResponseValueCorrectAnswer1 cultiva
Purdue - HIS - 306
JumptoNavigationFrameTitle:Started:Submitted:Timespent:Totalscore:exam2March5,200810:31AMMarch5,200811:08AM00:36:5298/100=98% Totalscoreadjustedby0.0Maximumpossiblescore:1001.ComparecontributionsofDioscoridesandTheophrastestohorticulturalkS
Purdue - HIS - 306
Title:Quiz1Started:January15,20088:29PMSubmitted:January15,20088:43PMTimespent:00:13:56Totalscore:10/10=100% Totalscoreadjustedby0.0 Maximumpossiblescore:101.GiveapproximatedatefortheBronzeAgeStudentResponse1. 4,000yearsagoValueCorrectAnswe
Purdue - HIS - 306
Extra Credit AssignmentTwo famous garden scenes of Shakespeare are found in Richard II and The Winter's Tale.Choose one and delineate and discuss the horticultural knowledge revealed in these excerpts.Your submission should be at least one page in leng
Purdue - HIS - 306
ARTGiuseppeArcimboldoMichelangeloCaravaggioGeorgDionysusEhretGeorgiaOKeefeVincentvanGoghLeonardodaVinciBartolomeoMayanYumKaax,Yucatan,Chultunes.AztecsTenochtitlan,Milpas,Chinampas,MexicoCity.IncasMacchuPichu,Potatoculture,.Cuzco.GreeceRhizotomoi,Hippoc
Purdue - HIS - 306
EXAM #1Question Type #1Cultivated Food Plants Toxic Substances tend to be eliminated in Seed dormancy is lost in Self pollination tends to increase in Fruit and organ size is greater in Life span for crops grown for vegetative organs is increased i
Purdue - HIS - 306
Yourlocation:AssessmentsViewAllSubmissionsViewAttemptViewAttempt1of1Title:exam1Started:Submitted:Timespent:Totalscore:January28,20098:28AMJanuary28,20098:47AM00:18:2190/100=90% Totalscoreadjustedby0.0 Maximumpossiblescore:1001.Toxicsubstance
Purdue - HIS - 306
Yourlocation:AssessmentsViewAllSubmissionsViewAttemptViewAttempt1of1Title:exam2Started: February2,20098:20AMSubmitted: February2,20098:53AMTime00:32:52spent:Total97/100=97% Totalscoreadjustedby0.0 Maximumpossiblescore:100score:1.Comparecontri
Purdue - HORT - 306
Old World Crops: Wheat, rice, Date. Apple, citrus/ New World Crops: Peanut, cacao, maize, squash, tomato Ikebana, Bonsai, and Sakai:ikebana is a Japanese flower arrangement that is based on the symbolic use of flowers. Bonsai is specimen grown on miniatu
Purdue - HORT - 306
View Attempt 1 of 1Title:Started:Submitted:Time spent:New Final ExamDecember 8, 2010 3:02 PMDecember 8, 2010 4:15 PM01:12:34Total score:170/200 = 85% Total score adjusted by 0.0Maximum possible score: 2001.Define the following design termsSy
Purdue - HORT - 306
Title:NewFinalExamStarted:Submitted:Timespent:Totalscore:February11,20098:29AMFebruary11,20099:52AM01:23:25154/200=77% Totalscoreadjustedby0.0 Maximumpossiblescore:2001.Defendthefollowingstatementandgiveexamples.&lt;br&gt;Thegreatestcontributiontoho
Purdue - HORT - 306
ViewAttempt1of1Title:Quiz3Started:Submitted:Timespent:Totalscore:January15,200911:31PMJanuary15,200911:40PM00:08:5310/10=100% Totalscoreadjustedby0.0 Maximumpossiblescore:101.WhatisevidenceforplantintroductionintoEgypt?(2points)StudentRespon
Purdue - HORT - 306
Yourlocation:AssessmentsViewAllSubmissionsViewAttemptViewAttempt1of1Title:exam1Started:Submitted:Timespent:Totalscore:January28,20098:28AMJanuary28,20098:47AM00:18:2190/100=90% Totalscoreadjustedby0.0 Maximumpossiblescore:1001.Toxicsubstance
Purdue - HORT - 306
Title:Quiz1Started:January15,20088:29PMSubmitted:January15,20088:43PMTimespent:00:13:56Totalscore:10/10=100% Totalscoreadjustedby0.0 Maximumpossiblescore:101.GiveapproximatedatefortheBronzeAgeStudentResponse1. 4,000yearsagoValueCorrectAnswe
Purdue - HORT - 306
Title:Quiz2Started:Submitted:Timespent:Totalscore:January15,20088:50PMJanuary15,20089:06PM00:16:1110/10=100% Totalscoreadjustedby0.0Maximumpossiblescore:101.WheatoriginatedinStudentResponse1. Americas2.Asia3. AfricaValueCorrectFeedbac
Purdue - HORT - 306
Title:Quiz3Started:Submitted:Timespent:Totalscore:January16,20087:06PMJanuary16,20087:15PM00:09:4310/10=100% Totalscoreadjustedby0.0Maximumpossiblescore:101.WhatisevidenceforplantintroductionintoEgypt?(2points)StudentResponse:SampleCorrectAn
Purdue - HORT - 306
Title:Quiz4Started:Submitted:Timespent:Totalscore:January16,20087:16PMJanuary16,20087:33PM00:16:4510/10=100% Totalscoreadjustedby0.0Maximumpossiblescore:101.Whatisthehorticulturalsignificanceof:HangingGardensofBabylon(2points)StudentResponse
Purdue - HORT - 306
Title:Quiz5Started:Submitted:Timespent:Totalscore:January16,20087:34PMJanuary16,20087:44PM00:09:248/10=80% Totalscoreadjustedby0.0Maximumpossiblescore:101.Definemilpa(1point)StudentResponse:SampleCorrectAnswerAztecmaizefield.Score:Aztecma
Purdue - HORT - 306
Title:Quiz6Started:Submitted:Timespent:Totalscore:January17,20083:30PMJanuary17,20083:54PM00:24:0510/10=100% Totalscoreadjustedby0.0Maximumpossiblescore:101.Identifyanddescribeinrelationtoagricultureorhorticulture.(1point)Aristotle:StudentRe
Purdue - HORT - 306
Title:Quiz7Started:Submitted:Timespent:Totalscore:January17,20083:54PMJanuary17,20084:06PM00:11:5010/10=100% Totalscoreadjustedby0.0Maximumpossiblescore:101.DefineorIdentify.(1point)RaisedBeds:StudentResponse:Bedsthatareraisedandfillewhich
Purdue - HORT - 306
Title:Quiz8Started:Submitted:Timespent:Totalscore:January17,20084:06PMJanuary17,20084:15PM00:09:0510/10=100% Totalscoreadjustedby0.0Maximumpossiblescore:101.Matchthecorrectanswer.(10points)StatementResponseConceptthatthemedicinalqualitiesof
Purdue - HORT - 306
Title:Quiz9Started:Submitted:Timespent:Totalscore:January17,20084:19PMJanuary17,20084:29PM00:10:0510/10=100% Totalscoreadjustedby0.0Maximumpossiblescore:101.MatcheachpersontohiscontributiontoBotanicalScienceorHorticulturStatementResponsePro
Purdue - HORT - 306
Title:Quiz10Started:Submitted:Timespent:Totalscore:January17,20084:30PMJanuary17,20084:45PM00:14:4210/10=100% Totalscoreadjustedby0.0Maximumpossiblescore:101.WhatwerethecontributionsofRachelCarsontohorticulture?StudentResponse:Amarinebiologi
Purdue - HORT - 306
OutlineIntroductionII. History/OriginIII. The Process of Raising MaizeIV. Development of the Maize PlantV. Uses of MaizeVI. Future of MaizeI.I. IntroductionMaize, also known as corn in Great Britain and the United States, is the most widespreadf
Purdue - HORT - 306
Term PaperA term paper (100 points) is due by 11:59 pm (midnight) on April 27th. The subject should be onan historical topic as suggested below. You are free to pick your own topic with Dr. Janicksapproval.You are not allowed recycle a term paper you
Purdue - HORT - 306
Horticulture 306Y/History 302YHistory of HorticultureSyllabusInstructorJules JanickOffice: 330, Horticulture BldgPhone: 494-1329Email: janick@purdue.eduCourse Administrator/GraderAnna WhipkeyOffice: 116A, Horticulture BldgPhone: 494-6968Email:
Purdue - HORT - 306
Title:Quiz12Started:Submitted:Timespent:Totalscore:February25,20087:15PMFebruary25,20087:30PM00:15:1110/10=100% Totalscoreadjustedby0.0Maximumpossiblescore:101.Whatisthedifferencebetweensymmetricalbalanceandasymmestricaldesign?(5points)Stude
Purdue - HORT - 306
Title:Quiz11Started:Submitted:Timespent:Totalscore:February25,20086:54PMFebruary25,20087:14PM00:19:4910/10=100% Totalscoreadjustedby0.0Maximumpossiblescore:101.Defineandrelatetoagriculturalcropsandhistory.OpiumWars:(2points)StudentResponse:
Rasmussen College - COST ACCOU - 101
Name:Section:Problem 7-21.Glide Tire CompanySales BudgetFor the Year Ended December 31, 2008Unit SalesVolumeProductPassenger car tiresTruck tiresTotalUnit SellingPriceTotal Sales-$-2.Glide Tire CompanyProduction BudgetFor the Year End
Jordan University of Science & Tech - TOURISM - 121
Reservation For Stanford Hotel Email: stanford@stanfordhotel.comTel: +852-2781-1881Website: http:/www.stanfordhongkong.com/en/Reservation For The Kimberley Hotel Email: hotel@kimberley.com.hkTel: +852-2723-3888Website: http:/www.kimberleyhotel.com.
Jordan University of Science & Tech - TOURISM - 121
Contents 2001 WorldatWork. The content islicensed for use by purchasers solely for their ownuse and not for resale or redistribution. No part ofthis article may be reproduced, excerpted orredistributed in any form without express writtenpermission of
Jordan University of Science & Tech - ECONS - 201
Political-Legal EnvironmentThe key feature for Subway is Franchise. In Singapore, franchising Subwayoffers a fast and easy approach to entrepreneurship. Firstly, there are nospecific laws governing franchising. Unlike some countries, there franchisors
Jordan University of Science & Tech - ECONS - 201
We observed that the mean hours spent on email per staff is 4.464. At least half of the staff will spent 4.4 hours on email while most of the staff will spent 4.7 hours or 5.3 hours. The median amount spent on email is higher for Executives.If we select
Jordan University of Science & Tech - ECONS - 301
Q4 (a)By ignoring the volatility, correlation and only focus on the achieving an expected re turns of 9% to 11%, we recommend Mr. David Tan to have a Balance portfolio. Theportfolio comprises of investing in different assets class with equal weighted al
Jordan University of Science & Tech - LAW - 343
Question 2:Background:1. Grace engaged Jane to teach her piano lessons for 10 lessons. Grace would payJane $500 per lesson. After 5 lessons, Grace could not continue with the lessons asshe needed to pay for her mothers medical bills. Jane offered to a
Jordan University of Science & Tech - LAW - 343
IntroductionRita (Principal) used materials to make art pieces to sale. Her neighbor, Barbie (agent)was aware of the kind of materials Rita used. Barbie saw some materials and wanted topurchase them for Rita, so she informed the seller (Third Party) th
Jordan University of Science & Tech - LAW - 343
Definition of ROTC?The Restraint of Trade Clause is applicable to the position of Design Engineer who has justbeen employed by CSM Pte Ltd to design a media player using voice-activated technology.This is a new entertainment device in the consumer mark
Berkeley - MATH 1B - 1
Name:Last,FirstMath 1B Exam 1Fall Program for Freshmen 2008Fred BourgoinYou have 80 minutes to answer all questions. You may use a scientic calculator but nota graphing calculator. Show all your steps. Partial credit will be awarded if andwhen des