Coding unit one
When does the Inspector include the borderWidth in its feedback?
You may have to run some code from above a few times to answer this question. Answer: When the borderWidth is any value except the default value of 2.
fill=None, border='blue', borderWidth=6)
fill=“yellow”, border=None no border if u don’t want
In general, what is the leftmost point of a circle with radius r centered at (x,y)?
(x-r,y)
What is a circle's width, in terms of its (x,y) center and its radius r?
Answer: The circle's width is double its radius. We use the asterisk (*) to multiply, so it's 2*r.
What is a circle's width, in terms of its (x,y) center and its radius r?
What is a circle's height, in terms of its (x,y) center and its radius r? Answer: For a circle, its height is the same as its width, so it is also 2*r.
A line runs from a point (x1, y1) to another point (x2, y2). We include those points when drawing a line. So we draw a line from (50, 100) to (75, 200)
Lines do not have a border. It is an error to set the border of a line. Instead, use fill for the line's color.
Lines do not have a borderWidth. It is an error to set the borderWidth of a line. Instead, use lineWidth. Like borders, lines can also have dashes by setting dashes=True or dashes=(dashWidth, gapWidth).
This draws the value 'hello' centered at (200, 200). In general, Label takes 3 arguments -- the value to draw, and the (x,y) center where to draw it. For now, we will only use label values that are strings. String values are in quotes ('single-quotes' or "double-quotes"), just like the color names we've been using. Be sure to include quotes, or you will get a syntax error!
Bolding
Label('This is plain!', 200, 50, size=36) # normal default style
Label('This is bold!', 200, 150, size=36, bold=True)
Label('This is italic!', 200, 250, size=36, italic=True)
Label('This is bold and italic!', 200, 350, size=36, bold=True, italic=True)
Italic and font
Label('This is default!', 200, 50, size=36) # default font
Label('This is arial!', 200, 125, size=36, font='arial')
Label('This is sans!', 200, 200, size=36, font='sans')
Label('This is courier!', 200, 275, size=36, font='courier')
Label('This is monospace!', 200, 350, size=36, font='monospace')
Fills and borders
Label('This is black!', 200, 50, size=36) # default color
Label('This is blue!', 200, 150, size=36, fill='blue')
Label('This has a red border!', 200, 250, size=36, fill=None, border='red')
Label('This has a gradient!', 200, 350, size=36, fill=gradient('blue', 'orange'))
How can we make a label with no fill and a gradient border?
Set the fill property to None and the border property to a gradient.
Interactive coding
first_name = input('Enter your first name: ')
last_name = input('Enter your last name: ')
print('Hello', first_name, last_name)
grade = int(input('What is your grade? ')) # \n adds a new line
print('You are in grade:', grade)
r = float(input('What is the radius? '))
area = 3.1415927 * r **2
print('Area is:', area)
Input – Processing – Output Plan
-all user input needed
-any values needed for calculations
-what variables should be created
Processing
-formulas/calculations that need to be performed
Output
-what results are needed -what results are shown to the user
-go back to the question and make sure you answered it
Regular Polygons
-We know how to draw a square -- we use Rect and make the width and height the same. But what about a triangle? Or a pentagon (with 5 sides) or a hexagon (with 6 sides), and so on? These are called regular polygons, and we draw these using Regular Polygon.
Share with your friends: |