Using conditionals and variables to make multiple objects placed on a screen in python processing 13.
Must use python in processing 13. Only the task 2 of the assignment needs to be completed. Instructions are fairly simple to make functions that generate an object when called. Have the object 1/4th of the display size. The object must be a vaild option which is a house, animal, or stick figure. Use the random function to have the object appear randomly. Utilize conditionals to reset the screen. Utilize built in variables to control the size of the objects.
Get Help With a similar task to - Using conditionals and variables to make multiple objects placed on a screen in python processing 13.
3 Individual Assignment: For this lab you are going to expand on the idea of automate movement. This will e↵ectively be creating an animation. To do this, you will be leveraging variables as well as learning how to work more with quantitative reasoning. Program Goal: You are going to design a program that will create leverage func- tions, conditionals and variables to produce multiple “objects” on the screen. Your object needs to be either a house, animal, or stick figure; made using primitives. It needs to make 10 of the object, placed at random locations on the display and then start over. Requirements: • Have proper header (see lab 3) • Have a display size of 600 by 600 • Have a non-default color background • Create a function to generate your “object” when called • Have your “object” a maximum of 1/4th the display size • Your “object” must be a valid option (house, animal, or stick figure) made using primitives • Have the “object” appear at random locations • Utilize the random function • After 10 “objects” are added to the screen, reset the screen • Utilize a conditional to control when you reset the screen • Proper and complete commenting • You must use a minimum of one global variable • Utilize built in variables to control the size of the “objects” • Frame rate of 10 • No looping allowed (no for or while) 4 Task 1: As with standard procedure, you need to do some planning to prepare for implemen- tation. This lab you will plan the setup function, draw function, and your “object” function separately. Create your choice of an algorithm or flowchart for each of the functions. You will also need to draw out a plan for the “object”, this should be done like it was approached in Lecture 11. To help with planning, here are some helpful explanations. Linear Execution As we have explored with the use of the fill function and our primitives, lines of code are performed in the order that they are written. This is one of the reasons why the algorithm/flowchart task is important. If we want a primitive to be a specific color, then we have to select the color before we make the primitive. Extended Use of Background The background we have seen in setup to initialize the background that everything goes on top of. In reality, the background is just a primitive that is the shape of the display with the color specified. Since it is fixed to the display, we only specify the color. This function can be ran more than once. Each time it runs, it will over write all the content that has been places on the display, creating a fresh start. You can review lecture 13 for an introduction to the concepts on the background. Conditional Logic This topic was introduced on March 6th. The conditional logic is used to control the options of actions. In this case, your conditional is only focused on when to reset the background. Task 2: You are now going to implement your plan to accomplish the goal. Since you will be expanding your concepts with this implementation, it is broken into phases to complete and test after each phase. Not all phases are described in the order you want. Setup Function The first task you are going to accomplish is the configuration of the setup in accor- dance to the assignment requirements. Use your planning from Task 1 to accomplish 5 this. Once this step is complete, test it to verify that you satisfy the requirements related to the setup function. “object” Function This is where you will configure your primitives to create your “object”. The “object” has to be one of the valid choices. To help with your implementation of this function, consider your planning from Task 1 and the importance of how linear execution works in processing. Once this is configured, you can call it in the format as demonstrated in Lecture 17. It is advisable you test only one call of this function until you have the “object” creating the correct output. Draw Function For this step, you have many tasks to accomplish, the order for many of them to be implemented are up to you based on your planning. • Conditional Implementation: To make a conditional, there are a few things you need to identify. The first is what the condition is that you want the content in the conditional to execute on. So if you want the content to execute on odd numbers for the variable X, your sensitivity statement that corresponds with the if will be: (X%2) > 0. Your syntax and logic was introduced in the lecture on March 6. • Increasing the Value of a Variable: To make a variable increase each time that the draw function runs through, you can’t initialize the variable in the draw function. You need to make that variable ”global” meaning all functions can access the value. To do this, you place the variable initialization at the top of the code before your setup func- tion. Once it is setup, then you need to tell the function it is allowed to use it. This is done by using the keyword global followed by a space then the variable name you want to be able to use. You would want to use your global variable inside the draw function, so that is where you put that line of code. A key thing you are doing is to make sure your variable is increasing. So your variable is equal to your current variable value plus the value you are increasing by. To test this, output the value of your variable to the console and watch it change all by itself. This is the exact same idea that needs to be used to control the background. 6 • Randomness: In Python there is a function known as random() that allows for the creation of a float to be randomly selected within a specified range. Figure 1: Reference information for the Random function. 7 • Keeping a Variable’s Value in Range: The display is only so big and the options for colors are only so many. To stay in range, modulo arithmetic is a great tool to leverage. The idea goes back to how long division works. When you do long division, you get a quotient and a remainder. To access the remainder, that is what the mod operator does. Some Examples: ⌅ 4 mod 2 = 0 ⌅ 3 mod 2 = 1 ⌅ 6 mod 6 = 0 ⌅ 9 mod 10 = 9 If you want to stay in the display range, you would want to take your value and mod it by the built in variable that corresponds with the axis you are moving the primitive along. If you want to stay in a valid color range, you will need to stay between 0 and 255. To test this, print out your variable’s values to the console and make sure that they reset to smaller values after the maximum value is reached. If it just keeps getting bigger and doesn’t reset, then your mod operator is not correct. • Frame Rates: The idea of the frame rate corresponds to how often the draw function is ran. The larger the value for the frame rate, the faster it will update. The smaller the value for the frame rate, the slower the frequency the function will run. There is a built in function that allows you to specify the frame rate by call- ing it with the input parameter being the value for the new frame rate you want. To test this, you need something to happen each time draw is ran. This can be printing something to the console or moving something on the display. • Addressing Smear Hint: The smear e↵ect can be seen in the lecture exam- ples for interactivity. Each time the draw function runs, everything that was on the screen stays and the new stu↵ that is generated in the draw function is added on top. To get rid of everything on the display from the previous run of draw, you should leverage a function that sets the entire display to an initial state. The key with setting the color is that you want the entire display to be e↵ected, just like when you initialized the display. To test this, you will need some sort of primitive being generated in each call of the draw function. You can explore this by modifying the interactivity example from lecture. • Built In Variables for the Display: When you configure the size function to control the display, you are also setting the values of two key built in variables: 8 width and height. These variables always exist and can be accessed by any function at any time. Rubric for individual assignment grading: Criteria Beginning Novice Proficient Exemplary Quiz Graded Separately - 20 Points Task 1: Setup Algorithm/ Flowchart No planning (0 Points) Very broad, missing many details, or too many extra ones (1 Point) Close but either a few extra and/or missing details (3 Points) Complete plan (5 Points) Task 1: Draw Algorithm/ Flowchart No planning (0 Points) Very broad, missing many details, or too many extra ones (1 Point) Close but either a few extra and/or missing details (3 Points) Complete plan (5 Points) Task 1: “Object” Algorithm/ Flowchart No planning (0 Points) Very broad, missing many details, or too many extra ones (1 Point) Close but either a few extra and/or missing details (3 Points) Complete plan (5 Points) Task 1: “Object” Draw- ing No planning (0 Points) Very broad, missing many details, or too many extra ones (1 Point) Close but either a few extra and/or missing details (3 Points) Complete plan (5 Points) Task 2: Size of the display No (0 Points) Yes (2 Points) Task 2: Background Control Default color ap- pears (0 Points) Non-default color, never resets (1 Points) Non-default color appears and resets as appropriate (3 Points) Task 2: Make the display update at No rate change or code does not run (0 Points) Rate changed but not correct (1 Points) 10 frames per second (3 Points) 9 Task 2: “Object” Function No objects function (0 Points) Function exists but contains no code (2 Points) Complete function with correct parameters (5 Points) Task 2: Valid “Object” No “object” function (0 Points) “Object” is made but not within the options allowed (1 Point) “Object” is one of the allowed options but does not use primitives (2 Points) Object is one of the allowed options and uses primitives (5 Points) Task 2: “Object” Function Used No “object” function (0 Points) function properly called to make all “objects” (5 Points) Task 2: “Object” Size No objects (0 Points) “Object” made but size exceeds the maximum specified (1 Point) “Object” size is within specifications, does not use built in variables (2 Points) “Object” size is within specifications and uses built in variables (5 Points) Task 2: “Object” Loca- tion No objects (0 Points) “Object” made but not in ran- dom locations (2 Points) “Object” made in random loca- tions using the random function (5 Points) Task 2: “Object” Count No objects (0 Points) “Object” made but only 1 or more than specified (1 Point) Correct number of “Objects” appear then stops (2 Points) The correct number of objects appear and then it resets (5 Points) Task 2: Conditional No conditional (0 Points) Conditional made but not correct (2 Points) Correct Conditional (5 Points) Task 2: Global Variable None (0 Points) Made but not used (2 Points) Made and used (5 Points) 10 Task 2: Comments None or very few (0 Points) Some key ones, but insu�cient (1 Points) Not optimal but close (2 Points) Comments for every segment and each line of code (7 Points) Task 2: Code runs No (0 Points) Yes (5 Points) 11 Syntax References Function Behavior General Syntax Structure circle() Draws a circle circle(a, b, extent) arc() Draws an arc arc(a, b, c, d, start, stop) arc(a, b, c, d, start, stop, mode) square() Draws a square square(a, b, extent) rect() Draws a rectangle rect(a, b, c, d) rect(a, b, c, d, r) rect(a, b, c, d, tl, tr, br, bl) quad() Draw a quadrilateral quad(x1, y1, x2, y2, x3, y3, x4, y4) line() Draws a line (a direct path between two points) to the screen. The version of line() with four parameters draws the line in 2D. line(x1, y1, x2, y2) line(x1, y1, z1, x2, y2, z2) point() Draws a point, a coordinate in space at the dimension of one pixel. point(x,y) ellipse() Draws an ellipse (oval) to the screen. ellipse(a, b, c, d) triangle() A triangle is a plane created by connecting three points. The first two arguments spec- ify the first point, the middle two arguments specify the second point, and the last two arguments specify the third point. triangle(x1, y1, x2, y2, x3, y3) 12 fill() Sets color to fill shape fill(rgb) fill(rgb, alpha) fill(gray) fill(gray, alpha) fill(v1, v2, v3) fill(v1, v2, v3, alpha) mouseX The system variable mouseX always con- tains the current horizontal coordinate of the mouse. mouseX mouseY The system variable mouseY always contains the current vertical coordinate of the mouse. mouseY draw() The draw() function is repeatedly invoked until the program is stopped or noLoop() is called. draw() is called automatically and should never be called explicitly. def draw(): #code setup() The setup() function is called once when the program starts. It’s used to define initial en- vironment properties such as screen size and background color and to load media such as images and fonts as the program starts. def setup(): #code size() Defines the dimension of the display window width and height in units of pixels. In a pro- gram that has the setup() function, the size() function must be the first line of code inside setup(). size(w,h) size(w,h,renderer) 13 background() The background() function sets the color used for the background of the Processing window. The default background is light gray. This function is typically used within draw() to clear the display window at the beginning of each frame, but it can be used inside setup() to set the background on the first frame of animation or if the background need only be set once. background(rgb) background(rgb, alpha) background(gray) background(gray, alpha) background(v1, v2, v3) background(v1, v2, v3, alpha) background(image) noFill() Disables filling geometry noFill() frameRate() Specifies the number of frames to be dis- played every second. For example, the func- tion call frameRate(30) will attempt to re- fresh 30 times a second. If the processor is not fast enough to maintain the specified rate, the frame rate will not be achieved. Set- ting the frame rate within setup() is recom- mended. The default rate is 60 frames per second. frameRate(fps) print() Prints content to the console print(what) println() Prints content to the console println(what) 14 Builtin Constants HALF PI (1.57079...) PI (3.14159...) QUARTER PI (0.78539...) TAU (6.28318...) TWO PI (6.28318...) Mathematical Operators Addition: + Subtraction: - Multiplication: * Division: / Mod: % width System variable that stores the width of the display window. This value is set by the first parameter of the size() function. For exam- ple, the function call size(320, 240) sets the width variable to the value 320. The value of width defaults to 100 if size() is not used in a program. width height System variable that stores the height of the display window. height if() Allows the program to make a decision about which code to execute. If the test evaluates to True, the statements enclosed within the block are executed and if the test evaluates to False the statements are not executed. if test: statements 15 Relational Operators ! = (inequality) < (less than) <= (less than or equal to) == (equality) > (greater than) >= (greater than or equal to) Logical Operators && (logical AND) not (logical NOT) or (logical OR)
Tutlance Experts offer help in a wide range of topics. Here are some of our top services:
- Math homework help
- Nursing homework help
- Statistics homework help
- Nursing coursework help
- Capstone project writing services
- Essay writers for hire
- Case study writing help
- Buy college papers online
- Buy college research papers
- College homework help
- Professional resume writing services
- Programming homework help
- Coursework writing help
- Term paper writing help
- Biology homework help
- Do my physics homework
- Dissertation data analysis help
- PhD Dissertation writing services
- Chemistry homework help
Post your project now for free and watch professional experts outbid each other in just a few minutes.