Let us worry about your assignment instead!

We Helped With This Python Programming Assignment: Have A Similar One?

SOLVED
CategoryProgramming
SubjectPython
DifficultyUndergraduate
StatusSolved
More InfoPython Help
170011

Assignment Code


# 1) The background of the game is white if there are less than 5 smileys,
#    blue if there are between 5 and 10 smileys (extremes included),
#    brown if there are more than 10 smileys.
#    You can color the background by drawing a colored rectangle behind
#    everything else.
# 2) Every time a smile bounces, it becomes 20% smaller.
# 3) Clicking inside an existing smiley changes the color of that smiley
#    (or those smileys if there are more than one) to yellow. No new
#    smiley is created in this case (a new pink smiley is still created
#    if you click at a point where there is no smiley).
# 4) "c" deletes all the smileys.
# 5) "v" turn all the yellow smileys orange, and all the pink smileys green.
# 6) Every 3 times a smiley bounces, it turns white. 
# 7) Unleash your creativity and add a feature of your choice to this animation.

from Tkinter import *
import time

def init():
    canvas.data.x = [50, 300, 400] # x coordinate of the smileys
    canvas.data.y = [100, 250, 400] # y coordinate of the smileys
    canvas.data.vx = [150, 200, -100] # x velocity of the smileys
    canvas.data.r = [50, 70, 30] # radius of the smileys
    canvas.data.color = ["green", "yellow", "orange"] # color of the smileys
    canvas.data.clicks = 0

def mousePressed(event):
    # event.x and event.y contain the coordinates of the mouse click
    canvas.data.x += [event.x]
    canvas.data.y += [event.y]
    canvas.data.color += ["pink"]
    canvas.data.r += [50]
    if event.x < int(canvas.cget("width")) / 2:
        canvas.data.vx += [70]
    else:
        canvas.data.vx += [-70]
    canvas.data.clicks += 1
    redrawAll()

def keyPressed(event):
    # event.char contains the character pressed on the keyboard
    # event.keysym contains the special key pressed on the keyboard
    if event.char == "z":
        for i in range(len(canvas.data.vx)):
            canvas.data.vx[i] *= 1.3
    elif event.char == "x":
        for i in range(len(canvas.data.vx)):
            canvas.data.vx[i] *= 0.7
    redrawAll()

def timerFired(previousTime):
    currentTime = time.time()
    # time passed since the last execution of the timer
    dt = currentTime - previousTime

    canvasWidth = int(canvas.cget("width")) # width of the canvas

    for i in range(len(canvas.data.x)):
        # update the position of the smiley
        canvas.data.x[i] += canvas.data.vx[i] * dt
        # check collision with right wall 
        if canvas.data.x[i] + canvas.data.r[i] > canvasWidth:
            canvas.data.x[i] = canvasWidth - canvas.data.r[i] # anti-stuck
            canvas.data.vx[i] = -canvas.data.vx[i]
        # check collision with left wall 
        elif canvas.data.x[i] - canvas.data.r[i] < 0:
            canvas.data.x[i] = canvas.data.r[i] # anti-stuck
            canvas.data.vx[i] = -canvas.data.vx[i]

    # update the view
    redrawAll()
    # schedule the next call to timerFired
    canvas.after(40, timerFired, currentTime)

def redrawAll():
    canvas.delete(ALL)
    # draw all the smileys
    for i in range(len(canvas.data.x)):
        x = canvas.data.x[i]
        y = canvas.data.y[i]
        r = canvas.data.r[i]
        canvas.create_oval(x-r, y-r, x+r, y+r, fill=canvas.data.color[i]) # face
        if canvas.data.vx[i] > 100 or canvas.data.vx[i] < -100:
            eyeColor = "red"
        else:
            eyeColor = "black"
        canvas.create_oval(x-r/2, y-r/2, x-r/4, y, fill=eyeColor) # left eye
        canvas.create_oval(x+r/2, y-r/2, x+r/4, y, fill=eyeColor) # right eye
        canvas.create_line(x, y, x, y+r/3) # nose
        canvas.create_arc(x-r/2, y, x+r/2, y+2*r/3,
                          start=-15, extent=-150, style=ARC) # mouth
    # draw the counter
    canvas.create_text(10, 10, text="Clicks: " + str(canvas.data.clicks),
                       anchor=NW)
##### DO NOT CHANGE ANYTHING IN THE CODE BELOW ###########
def run():
    global canvas
    root = Tk()
    canvas = Canvas(root, width=500, height=500, bg="white")
    canvas.pack()
    root.canvas = canvas.canvas = canvas
    class MyModel: pass
    canvas.data = MyModel()
    init()
    root.bind("<Button-1>", mousePressed)
    root.bind("<Key>", keyPressed)
    timerFired(time.time())
    root.mainloop()

run()

Assignment Code


# Cannon
#
# Explore the interactive animation below, then add the following
# features to it.
#
# 1) At the top left corner of the screen there are two counters:
#    the number of bullets currently going up, and the number of
#    bullets currently falling down.
# 2) Pressing "z" fires a red bullet with twice the current power
#    level of the cannon.
# 3) Pressing the "Up" arrow key makes the gun rotate 5 degrees
#    counter-clockwise; the "Down" arrow key makes it rotate
#    5 degrees clockwise. However, the gun cannot rotate to more
#    than 180 degrees or less than 0 degrees.
#    Additionally, a label at the top right corner of the screen
#    shows the current rotation angle of the cannon in degrees.
#    Show only the integer part of the angle.
#    Hints:
#    - To convert radians to degrees, the formula is
#      degrees = radians * 180 / math.pi
#    - The function int(x) truncates a floating point number x
#      to an integer.
# 4) Pressing "x" decreases the power of the cannon by 10 units;
#    "c" increases its power by 10 units. The power cannot become
#    lower than 50 or higher than 750 units.
#    Additionally, a red bar at the bottom of the screen shows the
#    current power level. The bar starts from the bottom left corner
#    of the screen and extends horizontally with a length
#    proportional to the power of the cannon. A label inside the bar
#    shows the numeric value of the current power of the cannon.
# 5) Pressing "v" makes the whole cannon (gun and wheel) 20% bigger;
#    "b" makes it 20% smaller. Make sure that the bullets are still
#    fired from the mouth of the gun after you rescale the cannon.
# 6) Unleash your creativity and add a feature of your choice to this animation.

from Tkinter import *
import time
import math
def init():
    canvas.data.cx = 100 # x position of the cannon
    canvas.data.cy = 420 # y position of the cannon
    canvas.data.ca = math.pi / 4 # angle of the cannon (in radians)
    canvas.data.power = 250 # power of the cannon
    # List of bullets. Each bullet is a list [x, y, vx, vy, size, color]
    canvas.data.bullets = []
    canvas.data.bulletRate = 3.0 # number of new bullets per second
    canvas.data.bulletCountdown = 1.0 # when it reaches 0, fire a bullet

def mousePressed(event):
    # event.x and event.y contain the coordinates of the mouse click
    redrawAll()

def keyPressed(event):
    # event.char contains the character pressed on the keyboard
    # event.keysym contains the special key pressed on the keyboard
    if event.keysym == "Left":
        canvas.data.cx -= 10
    elif event.keysym == "Right":
        canvas.data.cx += 10
    redrawAll()

def timerFired(previousTime):
    currentTime = time.time()
    dt = currentTime - previousTime

    # move the bullets and
    # eliminate the bullets below the bottom of the screen
    gravity = 150
    keepBullets = []
    for b in canvas.data.bullets:
        b[0] += b[2] * dt
        b[1] += b[3] * dt
        b[3] += gravity * dt
        if b[1] <= 605:
            keepBullets.append(b)
    canvas.data.bullets = keepBullets

    # decrease the countdown for a new bullet
    canvas.data.bulletCountdown -= dt
    
    if canvas.data.bulletCountdown <= 0:
        # create a new bullet
        d1 = 70 # length of the gun
        d2 = 30 # width of the gun
        a = canvas.data.ca
        bx = canvas.data.cx + d1 * math.cos(a) + d2 * math.cos(a + math.pi/2) / 2
        by = canvas.data.cy - d1 * math.sin(a) - d2 * math.sin(a + math.pi/2) / 2
        bvx = canvas.data.power * math.cos(canvas.data.ca)
        bvy = -canvas.data.power * math.sin(canvas.data.ca)
        br = 5
        bcolor = "blue"
        canvas.data.bullets.append([bx, by, bvx, bvy, br, bcolor])
        # reset the bullet countdown
        canvas.data.bulletCountdown = 1.0 / canvas.data.bulletRate
      
    redrawAll()
    canvas.after(40, timerFired, currentTime)

def redrawAll():
    canvas.delete(ALL)
    # paint the ground
    canvas.create_rectangle(0, 400, 800, 600, fill="black")
    # paint the cannon
    paintCannon()
    # paint the bullets
    for b in canvas.data.bullets:
        canvas.create_oval(b[0] - b[4], b[1] - b[4],
                           b[0] + b[4], b[1] + b[4],
                           fill=b[5])    

def paintCannon():
    d1 = 70 # length of the gun
    d2 = 30 # width of the gun
    r = 20 # radius of the wheel
    x = canvas.data.cx
    y = canvas.data.cy
    a = canvas.data.ca
    sinA = math.sin(a)
    cosA = math.cos(a)
    sinA2 = math.sin(a + math.pi / 2)
    cosA2 = math.cos(a + math.pi / 2)
    canvas.create_oval(x - r, y - r, x + r, y + r, fill="brown")
    canvas.create_polygon(x, y,
                          x + d1 * cosA, y - d1 * sinA,
                          x + d1 * cosA + d2 * cosA2, y - d1 * sinA - d2 * sinA2,
                          x + d2 * cosA2, y - d2 * sinA2,
                          fill="orange")
                          

##### DO NOT CHANGE ANYTHING IN THE CODE BELOW ###########
def run():
    global canvas
    root = Tk()
    canvas = Canvas(root, width=800, height=600, bg="lightblue")
    canvas.pack()
    root.canvas = canvas.canvas = canvas
    class MyModel: pass
    canvas.data = MyModel()
    init()
    root.bind("<Button-1>", mousePressed)
    root.bind("<Key>", keyPressed)
    timerFired(time.time())
    root.mainloop()

run()

Assignment Code


# PulsingCircles
#
# Look at the interactive animation program below, then add the following
# features to it.
#    
# 1) Each circle contains an inner concentric black circle
#    whose radius is 1/4 of the radius of the outer circle.
# 2) Clicking the mouse creates a new circle centered in the location
#    of the click. The initial radius of the circle is 0 and its radial
#    speed is a random number between 0 and 100.
# 3) Pressing "z" increases the maximum size of all the circles by 15%;
#    "x" decreases the maximum size of all the circles by 15%.
# 4) Pressing "c" increases the radial speed of all circles by 10%;
#    "v" decreases the radial speed of all the circles by 10%.
# 5) Pressing "b" freezes the largest circle.
# 6) Each circle has its own different color chosen randomly. To generate
#    a random color, you can use the function randomColor() already
#    implemented for you. Make sure that also the new circles that are
#    created when the player clicks will have their own random color.
# 7) Unleash your creativity and add a feature of your choice to this animation.

from Tkinter import *
import time
import random

def init():
    # Each circle is a list of integers defining its properties
    # [x, y, r, vr]
    # where:
    # x: horizontal position of the center
    # y: vertical position of the center
    # r: radius
    # vr: speed of growth of the radius
    canvas.data.circles = [[100, 200, 20, 70, randomColor()],
                           [500, 100, 0, 20, randomColor()],
                           [400, 300, 40, -30, randomColor()],
                           [300, 150, 10, 50, randomColor()]
			 ]
    canvas.data.maxR = 50 # maximum radius of the circles

# Returns a string representing a random color
def randomColor():
    r = random.randint(0, 255)
    g = random.randint(0, 255)
    b = random.randint(0, 255)
    color = "#%02x%02x%02x" % (r, g, b)
    return color

def mousePressed(event):
    # event.x and event.y contain the coordinates of the mouse click
    redrawAll()

def keyPressed(event):
    # event.char contains the character pressed on the keyboard
    # event.keysym contains the special key pressed on the keyboard
    
    redrawAll()

def timerFired(previousTime):
    currentTime = time.time()
    dt = currentTime - previousTime

    for c in canvas.data.circles:
        c[2] += c[3] * dt
        if c[2] > canvas.data.maxR:
            c[2] = canvas.data.maxR
            c[3] = -c[3]
        elif c[2] < 0:
            c[2]= 0
            c[3] = -c[3]

    redrawAll()
    canvas.after(40, timerFired, currentTime)

def redrawAll():
    canvas.delete(ALL)
    
    for c in canvas.data.circles:
        x=c[0]
        y=c[1]
        r=c[2]
        color=c[4]
        canvas.create_oval(x - r, y - r,
                            x + r, y + r,
                            fill=color)
        

##### DO NOT CHANGE ANYTHING IN THE CODE BELOW ###########
def run():
    global canvas
    root = Tk()
    canvas = Canvas(root, width=600, height=400, bg="white")
    canvas.pack()
    root.canvas = canvas.canvas = canvas
    class MyModel: pass
    canvas.data = MyModel()
    init()
    root.bind("<Button-1>", mousePressed)
    root.bind("<Key>", keyPressed)
    timerFired(time.time())
    root.mainloop()

run()


Frequently Asked Questions

Is it free to get my assignment evaluated?

Yes. No hidden fees. You pay for the solution only, and all the explanations about how to run it are included in the price. It takes up to 24 hours to get a quote from an expert. In some cases, we can help you faster if an expert is available, but you should always order in advance to avoid the risks. You can place a new order here.

How much does it cost?

The cost depends on many factors: how far away the deadline is, how hard/big the task is, if it is code only or a report, etc. We try to give rough estimates here, but it is just for orientation (in USD):

Regular homework$20 - $150
Advanced homework$100 - $300
Group project or a report$200 - $500
Mid-term or final project$200 - $800
Live exam help$100 - $300
Full thesis$1000 - $3000

How do I pay?

Credit card or PayPal. You don't need to create/have a Payal account in order to pay by a credit card. Paypal offers you "buyer's protection" in case of any issues.

Why do I need to pay in advance?

We have no way to request money after we send you the solution. PayPal works as a middleman, which protects you in case of any disputes, so you should feel safe paying using PayPal.

Do you do essays?

No, unless it is a data analysis essay or report. This is because essays are very personal and it is easy to see when they are written by another person. This is not the case with math and programming.

Why there are no discounts?

It is because we don't want to lie - in such services no discount can be set in advance because we set the price knowing that there is a discount. For example, if we wanted to ask for $100, we could tell that the price is $200 and because you are special, we can do a 50% discount. It is the way all scam websites operate. We set honest prices instead, so there is no need for fake discounts.

Do you do live tutoring?

No, it is simply not how we operate. How often do you meet a great programmer who is also a great speaker? Rarely. It is why we encourage our experts to write down explanations instead of having a live call. It is often enough to get you started - analyzing and running the solutions is a big part of learning.

What happens if I am not satisfied with the solution?

Another expert will review the task, and if your claim is reasonable - we refund the payment and often block the freelancer from our platform. Because we are so harsh with our experts - the ones working with us are very trustworthy to deliver high-quality assignment solutions on time.

Customer Feedback

"Thanks for explanations after the assignment was already completed... Emily is such a nice tutor! "

Order #13073

Find Us On

soc fb soc insta


Paypal supported