-
Notifications
You must be signed in to change notification settings - Fork 0
/
413991810.html
111 lines (98 loc) · 23.4 KB
/
413991810.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html>
<head>
<title>Di Luo : Di Luo's CS151 Project 3</title>
<link rel="stylesheet" href="styles/site.css" type="text/css" />
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body class="theme-default aui-theme-default">
<div id="page">
<div id="main" class="aui-page-panel">
<div id="main-header">
<div id="breadcrumb-section">
<ol id="breadcrumbs">
<li class="first">
<span><a href="index.html">Di Luo</a></span>
</li>
<li>
<span><a href="413631037.html">Di Luo’s Home</a></span>
</li>
<li>
<span><a href="474513786.html">Di Luo's CS151</a></span>
</li>
</ol>
</div>
<h1 id="title-heading" class="pagetitle">
<span id="title-text">
Di Luo : Di Luo's CS151 Project 3
</span>
</h1>
</div>
<div id="content" class="view">
<div class="page-metadata">
Created by <span class='author'> Di Luo</span>, last modified on Sep 23, 2018
</div>
<div id="main-content" class="wiki-content group">
<div><strong><u>Description:</u></strong></div><div>In Project 3, we need to make use of parameters, loops, and conditional statements to make our codes from Project 2 more efficient. The functions of scenes should be improved so that the whole scene can be resized and some aspects of the desert scenes can be changed by the arguments in command line. The parameters are used to control different values of shapes, the loops are used to simplify the functions and the conditional statements are used to determine if the shapes are filled with colors or not. By the end of the project, we need to create a scene, such as the desert scene, within another scene, such as the gallery scene.</div><div><u><strong><br/></strong></u></div><div><u><strong>Task 1</strong></u><strong><u><br/></u></strong></div><div>The first task was to rewrite the function of block() that I wrote in Project 2 for drawing a block at (x, y) of the given width and height. While rewriting, I took advantage of looping to simplified the function, added a parameter for changing the color of the block, and added a parameter <samp>fill</samp> that is an if statement to control the fill of the turtle. If the <samp>fill</samp> variable has the value True, then the block would be filled; if <samp>fill </samp>has the value False, then the block would not be filled.</div><div><u><strong><br/></strong></u></div><div><u><strong>Task 2</strong></u></div><div>The second task was to rewrite other functions of basic shapes that I wrote in Project 2, which were sun() for drawing a circle as sun at (x, y) of the given scale and triangle() for drawing a triangle with at (x, y) of the given side length. For rewriting, I used for loop to simplified the function of triangle(), added parameters for changing color for each functions, and also added parameters <samp>fill</samp></div><div> that is an if statement to control the fill of the turtle.</div><div><u><strong><br/></strong></u></div><div><u><strong>Task 3</strong></u></div><div>The third task was to rewrite the aggregate shapes from Project 2 with the renewed functions of basic shapes. So I chose to rewrite cactus(), drawing a cactus combined by five blocks, and stone(), drawing a stone combined by two triangles.</div><div><u><strong><br/></strong></u></div><div><u><strong>Task 4</strong></u></div><div>The fourth task was to <span style="color: rgb(34,51,68);">re-write a scene from Project 2 so the entire scene is parameterized by an x, y location and a scale parameter. I rewrote the scene desert1 so that I could draw the desert1<span style="color: rgb(34,51,68);"> scene anywhere on the screen at any scale.</span></span></div><div><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><br/></span></span></div><div><u><strong><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);">Task 5</span></span></strong></u></div><div>The fifth task was to draw the desert1 scene with three different scales on different positions, and the picture is shown below.<span style="color: rgb(34,51,68);"> </span></div><div><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="500" src="attachments/413991810/414122891.png" data-image-src="attachments/413991810/414122891.png" data-unresolved-comment-count="0" data-linked-resource-id="414122891" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="Screen Shot 2018-09-23 at 9.57.13 AM.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="413991810" data-linked-resource-container-version="6"></span>(Required picture 1)</div><div><u><strong><br/></strong></u></div><div><u><strong>Task 6</strong></u></div><div>The sixth task was to incorporate the desert1 scene into another scene. So I wrote the function gallery() to draw a scene of a gallery and the desert1 scene was used as a painting that was being shown in the gallery scene, which is shown below.</div><div><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="500" src="attachments/413991810/414122892.png" data-image-src="attachments/413991810/414122892.png" data-unresolved-comment-count="0" data-linked-resource-id="414122892" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="Screen Shot 2018-09-23 at 10.51.03 AM.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="413991810" data-linked-resource-container-version="6"></span>(Required picture 2)</div><div><u><strong><br/></strong></u></div><div><u><strong>Task 7</strong></u></div><div>The seventh task was to e<span style="color: rgb(34,51,68);">dit one of my two scenes so that some aspects of the scene depend on a new parameter to the scene function. I chose to edit the gallery scene and added a parameter color3 to control the color of chairs and tables in the gallery scene. Then I set up the Python files by using the components below so that the main code can only be run from command line and the value parameter color3 comes from a command-line argument: sys.argv[1]. I put all the main codes under the function main() and added the if statement below so that if someone didn't type in anything, the color would be set as 'brown'; if the color was typed on command line, the color would be what is typed.</span></div><div><span style="color: rgb(34,51,68);"><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image confluence-thumbnail" draggable="false" width="100" src="attachments/413991810/414122911.png" data-image-src="attachments/413991810/414122911.png" data-unresolved-comment-count="0" data-linked-resource-id="414122911" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="Screen Shot 2018-09-23 at 4.11.21 PM.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="413991810" data-linked-resource-container-version="6"></span></span></div><div><span style="color: rgb(34,51,68);"><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image confluence-thumbnail" draggable="false" width="200" src="attachments/413991810/414122912.png" data-image-src="attachments/413991810/414122912.png" data-unresolved-comment-count="0" data-linked-resource-id="414122912" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="Screen Shot 2018-09-23 at 4.11.16 PM.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="413991810" data-linked-resource-container-version="6"></span></span></div><div><span style="color: rgb(34,51,68);"><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image confluence-thumbnail" draggable="false" width="200" src="attachments/413991810/414122913.png" data-image-src="attachments/413991810/414122913.png" data-unresolved-comment-count="0" data-linked-resource-id="414122913" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="Screen Shot 2018-09-23 at 4.10.57 PM.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="413991810" data-linked-resource-container-version="6"></span></span></div><div><span style="color: rgb(34,51,68);">Then the colors of chairs and tables can be changed by using different arguments in command line. I changed the color into green and then pink and the scenes are showing below.</span></div><div><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="500" src="attachments/413991810/414122893.png" data-image-src="attachments/413991810/414122893.png" data-unresolved-comment-count="0" data-linked-resource-id="414122893" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="Screen Shot 2018-09-23 at 11.23.58 AM.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="413991810" data-linked-resource-container-version="6"></span>(Required picture 3)</div><div><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="500" src="attachments/413991810/414122894.png" data-image-src="attachments/413991810/414122894.png" data-unresolved-comment-count="0" data-linked-resource-id="414122894" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="Screen Shot 2018-09-23 at 11.25.05 AM.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="413991810" data-linked-resource-container-version="6"></span>(Required picture 4)</div><div><u><strong><br/></strong></u></div><div><u><strong>Extensions</strong></u></div><div>For extensions, I continued using random package to put different aggregate shapes on the desert1 scene. Because the scene is parameterized, the range of randomness can also vary as the scale changes so that the shapes won't be drown outside the scene. The random scales of shapes are also controlled.</div><div><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="500" src="attachments/413991810/414122927.png" data-image-src="attachments/413991810/414122927.png" data-unresolved-comment-count="0" data-linked-resource-id="414122927" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="Screen Shot 2018-09-23 at 4.52.28 PM.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="413991810" data-linked-resource-container-version="6"></span></div><div>Besides, I created the function of gallery2 in extensions.py. gallery2() draws the scene of gallery with the scenes of both desert1 and desert2 inside. In order to use the chairAndTable() function in task2.py, I imported task2.py into extension.py and run the function as what is shown below. Because I put the main code in main() and used "if __name__ == '__main__':" in task2.py, the main code will not run when I imported task2.py into extensions.py.</div><div><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image confluence-thumbnail" draggable="false" width="100" src="attachments/413991810/414122985.png" data-image-src="attachments/413991810/414122985.png" data-unresolved-comment-count="0" data-linked-resource-id="414122985" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="Screen Shot 2018-09-23 at 8.20.44 PM.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="413991810" data-linked-resource-container-version="6"></span></div><div><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="300" src="attachments/413991810/414122986.png" data-image-src="attachments/413991810/414122986.png" data-unresolved-comment-count="0" data-linked-resource-id="414122986" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="Screen Shot 2018-09-23 at 8.20.52 PM.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="413991810" data-linked-resource-container-version="6"></span></div><div><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="300" src="attachments/413991810/414122981.png" data-image-src="attachments/413991810/414122981.png" data-unresolved-comment-count="0" data-linked-resource-id="414122981" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="Screen Shot 2018-09-23 at 5.23.26 PM.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="413991810" data-linked-resource-container-version="6"></span></div><div>Then, in extension.py I added an if statement and added another argument to the command line so that I can get the scene without being filled.</div><div><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image confluence-thumbnail" draggable="false" width="200" src="attachments/413991810/414122987.png" data-image-src="attachments/413991810/414122987.png" data-unresolved-comment-count="0" data-linked-resource-id="414122987" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="Screen Shot 2018-09-23 at 8.19.34 PM.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="413991810" data-linked-resource-container-version="6"></span></div><div><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="300" src="attachments/413991810/414122989.png" data-image-src="attachments/413991810/414122989.png" data-unresolved-comment-count="0" data-linked-resource-id="414122989" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="Screen Shot 2018-09-23 at 8.18.45 PM.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="413991810" data-linked-resource-container-version="6"></span></div><div><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="500" src="attachments/413991810/414122988.png" data-image-src="attachments/413991810/414122988.png" data-unresolved-comment-count="0" data-linked-resource-id="414122988" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="Screen Shot 2018-09-23 at 5.57.25 PM.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="413991810" data-linked-resource-container-version="6"></span></div><div>Finally, I created the function of gallery3 in extension.py. gallery3 also draws the scene of a Art Gallery but with a scene of gallery inside. The scene of gallery is a minimized scene of what gallery() draws so it also has the scene of desert1 inside, so I created a <span style="color: rgb(34,51,68);">encapsulation.</span></div><div><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="500" src="attachments/413991810/414122991.png" data-image-src="attachments/413991810/414122991.png" data-unresolved-comment-count="0" data-linked-resource-id="414122991" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="Screen Shot 2018-09-23 at 6.32.02 PM.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="413991810" data-linked-resource-container-version="6"></span></div><div><u><strong><br/></strong></u></div><div><u><strong>Reflection</strong></u></div><div>By doing the project, I recapped how to use loops to simplify the function and how to determine if a shape is filled with color by using conditional statements. I learned how to parameterize the function of a whole scene so that the scene can be shown with different scales on different positions in other scenes. I also studied how to use conditional statements and sys package to give parameter a default value and change the value with the arguments in command line.</div><div><u><strong><br/></strong></u></div><div><u><strong>Source</strong></u></div><div>I worked by myself on this project.</div><p> </p>
</div>
<div class="pageSection group">
<div class="pageSectionHeader">
<h2 id="attachments" class="pageSectionTitle">Attachments:</h2>
</div>
<div class="greybox" align="left">
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/413991810/414122891.png">Screen Shot 2018-09-23 at 9.57.13 AM.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/413991810/414122892.png">Screen Shot 2018-09-23 at 10.51.03 AM.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/413991810/414122893.png">Screen Shot 2018-09-23 at 11.23.58 AM.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/413991810/414122894.png">Screen Shot 2018-09-23 at 11.25.05 AM.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/413991810/414122911.png">Screen Shot 2018-09-23 at 4.11.21 PM.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/413991810/414122912.png">Screen Shot 2018-09-23 at 4.11.16 PM.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/413991810/414122913.png">Screen Shot 2018-09-23 at 4.10.57 PM.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/413991810/414122927.png">Screen Shot 2018-09-23 at 4.52.28 PM.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/413991810/414122981.png">Screen Shot 2018-09-23 at 5.23.26 PM.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/413991810/414122985.png">Screen Shot 2018-09-23 at 8.20.44 PM.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/413991810/414122986.png">Screen Shot 2018-09-23 at 8.20.52 PM.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/413991810/414122987.png">Screen Shot 2018-09-23 at 8.19.34 PM.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/413991810/414122988.png">Screen Shot 2018-09-23 at 5.57.25 PM.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/413991810/414122989.png">Screen Shot 2018-09-23 at 8.18.45 PM.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/413991810/414122991.png">Screen Shot 2018-09-23 at 6.32.02 PM.png</a> (image/png)
<br/>
</div>
</div>
</div> </div>
<div id="footer" role="contentinfo">
<section class="footer-body">
<p>Document generated by Confluence on Aug 29, 2022 09:29</p>
<div id="footer-logo"><a href="http://www.atlassian.com/">Atlassian</a></div>
</section>
</div>
</div> </body>
</html>