generated from mwc/project_drawing
My third commit will consist of my third round of changes. What has changed during my third commit were my functions. In this attempt I was given feedback to consider how can I add more parameters or loops to my existing code. I did both by adding customizable parameters to allow a house and sun of any color. I also added a for loop that gives me three houses of different color instead of one.
What got me stuck in the beginning was how can I add more parameters or loops to my existing code. What I figured out was that by adding more parameters and loops to my existing code I would be able to create a drawing that would give me three house and a sun with customizable color of my choosing. A strategy I used to get unstuck was to continue using ideas from previous lessons about parameters and trial and error to see where things went right and wrong. What I wonder is how can I use super turtle to create an animated sun. What I want to learn more about is how to properly use super turtle. Since I have more houses and sun with customizable color my future project idea could be to create three houses and a sun with customizable coloring but this time using super turtle to creaete an animated rising sun.
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
My second commit will consist of my second round of changes. What has changed is
|
My third commit will consist of my third round of changes. What has changed during my third commit were my functions. In this attempt I was given feedback to consider how can I add more parameters or loops to my existing code. I did both by adding customizable parameters to allow a house and sun of any color. I also added a for loop that gives me three houses of different color instead of one.
|
||||||
my functions in drawing.py and shapes.py have been updated to show a house and sun.
|
|
||||||
|
|
||||||
What got me stuck in the beginning is figuring out where to begin. It was an easy fix because I used the previous assignments to help me with making shapes using various parameters. I figured out that the previous lessons still prove to be a great help to look back at when stuck. I was specifically stuck with the animation of the sun rising. A different method was used to create a rising sun but was outside of the realm of super turtle which ultimately had me back track. It took longer to try and learn animation with super turtle so I reached out to my professor and decided I will continue with my house but the sun will be stationary rather than rising. Something I want to learn more about is animating using super turtle. An idea for a future project will be to create a house and a rising sun using the tools of super turtle.
|
What got me stuck in the beginning was how can I add more parameters or loops to my existing code. What I figured out was that by adding more parameters and loops to my existing code I would be able to create a drawing that would give me three house and a sun with customizable color of my choosing. A strategy I used to get unstuck was to continue using ideas from previous lessons about parameters and trial and error to see where things went right and wrong. What I wonder is how can I use super turtle to create an animated sun. What I want to learn more about is how to properly use super turtle. Since I have more houses and sun with customizable color my future project idea could be to create three houses and a sun with customizable coloring but this time using super turtle to creaete an animated rising sun.
|
||||||
|
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
# Write your entire commit message above this line.
|
# Write your entire commit message above this line.
|
||||||
|
|||||||
Binary file not shown.
73
drawing.py
73
drawing.py
@@ -1,61 +1,84 @@
|
|||||||
# drawing.py
|
# drawing.py
|
||||||
# ----------
|
# ----------
|
||||||
# By ____(you)___________
|
# By Angelo Trelles
|
||||||
#
|
#
|
||||||
# (Briefly describe what this program does.)
|
# This program allows me to create a drawing of a house and a sun. The code is split
|
||||||
|
# into two files for organization. Shapes.py contains functions to draw basic shapes
|
||||||
|
# such as squares, rectangles, trianlges, and circles. Each function includes
|
||||||
|
# options for size, outline color, and fill color so they can be reused in
|
||||||
|
# different ways. The second file, drawing.py, uses the functions to draw a complete
|
||||||
|
# scene that includes a house with a roof, windows, and a door, along with a sun
|
||||||
|
# in the corner. The project shows how to use functions, loops, and parameters to
|
||||||
|
# make drawings customizable.
|
||||||
|
|
||||||
import turtle
|
import turtle
|
||||||
from shapes import draw_square, draw_triangle, draw_rectangle, draw_circle
|
from shapes import draw_square, draw_triangle, draw_rectangle, draw_circle
|
||||||
|
|
||||||
# setup
|
# setup
|
||||||
screen = turtle.Screen()
|
screen = turtle.Screen()
|
||||||
screen.setup(width=800, height=600)
|
screen.setup(width=1000, height=600)
|
||||||
screen.bgcolor("skyblue")
|
screen.bgcolor("skyblue")
|
||||||
|
|
||||||
pen = turtle.Turtle()
|
pen = turtle.Turtle()
|
||||||
pen.speed(0)
|
pen.speed(0)
|
||||||
pen.hideturtle()
|
pen.hideturtle()
|
||||||
|
|
||||||
# draw house
|
# first house with color options
|
||||||
def draw_house():
|
def draw_house(x, base_color="lightgrey", roof_color="brown", door_color="darkred", window_color="lightblue"):
|
||||||
# house base
|
# base position
|
||||||
pen.penup()
|
pen.penup()
|
||||||
pen.goto(-100, -200)
|
pen.goto(x, -200)
|
||||||
pen.pendown()
|
pen.pendown()
|
||||||
draw_square(pen, 200, color="black", fill="lightgrey")
|
draw_square(pen, 200, color="black", fill=base_color)
|
||||||
|
|
||||||
# roof (lowered)
|
# roof
|
||||||
pen.penup()
|
pen.penup()
|
||||||
pen.goto(-100, -200)
|
pen.goto(x, -200)
|
||||||
pen.pendown()
|
pen.pendown()
|
||||||
draw_triangle(pen, 200, color="black", fill="brown")
|
draw_triangle(pen, 200, color="black", fill=roof_color)
|
||||||
|
|
||||||
# door
|
# door
|
||||||
pen.penup()
|
pen.penup()
|
||||||
pen.goto(-30, -200)
|
pen.goto(x + 70, -200)
|
||||||
pen.pendown()
|
pen.pendown()
|
||||||
draw_rectangle(pen, 60, 100, color="black", fill="darkred")
|
draw_rectangle(pen, 60, 100, color="black", fill=door_color)
|
||||||
|
|
||||||
# windows (lowered)
|
# windows (left and right)
|
||||||
pen.penup()
|
pen.penup()
|
||||||
pen.goto(-80, -210)
|
pen.goto(x + 20, -210)
|
||||||
pen.pendown()
|
pen.pendown()
|
||||||
draw_square(pen, 40, color="black", fill="lightblue")
|
draw_square(pen, 40, color="black", fill=window_color)
|
||||||
|
|
||||||
pen.penup()
|
pen.penup()
|
||||||
pen.goto(40, -210)
|
pen.goto(x + 140, -210)
|
||||||
pen.pendown()
|
pen.pendown()
|
||||||
draw_square(pen, 40, color="black", fill="lightblue")
|
draw_square(pen, 40, color="black", fill=window_color)
|
||||||
|
|
||||||
# draw sun (stationary)
|
# draw stationary sun
|
||||||
def draw_sun():
|
def draw_sun(x=300, y=180, sun_color="yellow"):
|
||||||
pen.penup()
|
pen.penup()
|
||||||
pen.goto(250, 180) # top-right corner
|
pen.goto(x, y)
|
||||||
pen.pendown()
|
pen.pendown()
|
||||||
draw_circle(pen, 50, color="black", fill="yellow")
|
draw_circle(pen, 50, color="black", fill=sun_color)
|
||||||
|
|
||||||
# main
|
# --- main scene ---
|
||||||
draw_house()
|
def main():
|
||||||
draw_sun()
|
# draw the sun (customizable color)
|
||||||
|
draw_sun(sun_color="yellow")
|
||||||
|
|
||||||
|
# a loop to draw multiple houses with different colors (customizable color options)
|
||||||
|
colors = [
|
||||||
|
("lightgrey", "brown", "darkred", "lightblue"),
|
||||||
|
("lightyellow", "red", "blue", "white"),
|
||||||
|
("lightgreen", "purple", "darkblue", "yellow")
|
||||||
|
]
|
||||||
|
|
||||||
|
x_position = -400
|
||||||
|
for base, roof, door, window in colors:
|
||||||
|
draw_house(x_position, base, roof, door, window)
|
||||||
|
x_position += 300
|
||||||
|
|
||||||
turtle.done()
|
turtle.done()
|
||||||
|
|
||||||
|
# to run program
|
||||||
|
main()
|
||||||
59
shapes.py
59
shapes.py
@@ -1,41 +1,50 @@
|
|||||||
import turtle
|
import turtle
|
||||||
|
|
||||||
def draw_square(t, size, color="black", fill=""):
|
|
||||||
t.color(color, fill)
|
def draw_square(pen, size, color="black", fill=None):
|
||||||
|
"""Draw a square with optional fill color."""
|
||||||
|
pen.color(color)
|
||||||
if fill:
|
if fill:
|
||||||
t.begin_fill()
|
pen.fillcolor(fill)
|
||||||
|
pen.begin_fill()
|
||||||
for _ in range(4):
|
for _ in range(4):
|
||||||
t.forward(size)
|
pen.forward(size)
|
||||||
t.right(90)
|
pen.right(90)
|
||||||
if fill:
|
if fill:
|
||||||
t.end_fill()
|
pen.end_fill()
|
||||||
|
|
||||||
def draw_rectangle(t, width, height, color="black", fill=""):
|
def draw_rectangle(pen, width, height, color="black", fill=None):
|
||||||
t.color(color, fill)
|
"""Draw a rectangle with optional fill color."""
|
||||||
|
pen.color(color)
|
||||||
if fill:
|
if fill:
|
||||||
t.begin_fill()
|
pen.fillcolor(fill)
|
||||||
|
pen.begin_fill()
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
t.forward(width)
|
pen.forward(width)
|
||||||
t.right(90)
|
pen.right(90)
|
||||||
t.forward(height)
|
pen.forward(height)
|
||||||
t.right(90)
|
pen.right(90)
|
||||||
if fill:
|
if fill:
|
||||||
t.end_fill()
|
pen.end_fill()
|
||||||
|
|
||||||
def draw_triangle(t, size, color="black", fill=""):
|
def draw_triangle(pen, size, color="black", fill=None):
|
||||||
t.color(color, fill)
|
"""Draw an equilateral triangle with optional fill color."""
|
||||||
|
pen.color(color)
|
||||||
if fill:
|
if fill:
|
||||||
t.begin_fill()
|
pen.fillcolor(fill)
|
||||||
|
pen.begin_fill()
|
||||||
for _ in range(3):
|
for _ in range(3):
|
||||||
t.forward(size)
|
pen.forward(size)
|
||||||
t.left(120)
|
pen.left(120)
|
||||||
if fill:
|
if fill:
|
||||||
t.end_fill()
|
pen.end_fill()
|
||||||
|
|
||||||
def draw_circle(t, radius, color="black", fill=""):
|
def draw_circle(pen, radius, color="black", fill=None):
|
||||||
t.color(color, fill)
|
"""Draw a circle with optional fill color."""
|
||||||
|
pen.color(color)
|
||||||
if fill:
|
if fill:
|
||||||
t.begin_fill()
|
pen.fillcolor(fill)
|
||||||
t.circle(radius)
|
pen.begin_fill()
|
||||||
|
pen.circle(radius)
|
||||||
if fill:
|
if fill:
|
||||||
t.end_fill()
|
pen.end_fill()
|
||||||
Reference in New Issue
Block a user