Skip to content

The intro to py5 and python tutorials have coding challenges at the end of each of them, but there is no answer key #113

Open

Description

@hx2A

The intro to py5 and python tutorials have coding challenges at the end of each of them, but there is no answer key. Should there be one? Should it be on github?

https://py5coding.org/tutorials/intro_to_py5_and_python.html

Activity

  1. david-dunkley commented on Apr 25, 2024

    @david-dunkley

    Yes and yes! I use py5 to teach creative coding and this would help a lot. It would show at least one way to solve the challenges and provide teachers with a good standard for learning, teaching, and grading.

  2. added
    documentationImprovements or additions to documentation
    help wantedExtra attention is needed
    on Apr 25, 2024
  3. hx2A commented on Apr 25, 2024

    @hx2A
    CollaboratorAuthor

    Great, I just added some Labels in hopes that someone is interested in working on this. I don't have time at the moment, but this seems like a good task that someone else could pick up and contribute to. @villares , do you know anyone who would be interested in working on this?

  4. villares commented on Apr 25, 2024

    @villares
    Collaborator

    Great! I'll ask around!

  5. david-dunkley commented on Apr 26, 2025

    @david-dunkley

    Hi @villares & @hx2A This sounds great! Looking forward to helping y'all out and learning as well! Have a great weekend.

  6. villares commented on Jun 4, 2025

    @villares
    Collaborator

    @david-dunkley, I saw your email today, email is good.
    For the record, it's about "chapter 10": https://py5coding.org/tutorials/intro_to_py5_and_python_11_trigonometry_for_animation.html#engine-task

    I'll try to have a look this week!

  7. david-dunkley commented on Jun 4, 2025

    @david-dunkley

    Hi @villares ,
    Yes, 'Ch 10' Engine Task. 
    Thanks for the message and I look forward to hearing from you!
    Best,
    David 

  8. villares commented on Jun 9, 2025

    @villares
    Collaborator

    'Ch 10' Engine Task.

    Hi @david-dunkley!

    See if this helps... I took the one I thought was closest and tried to "refactor". I think it can still be improved, but looks plausible...

    #Ch 10 Engine Task 
    
    theta = 0
    radius = 30   # this was called speed but I think it is the radius!
    
    def setup():
        size(600, 600)
        no_fill()
        stroke('#FFFFFF')
        stroke_weight(3)
        
    def draw():
        global theta, radius
        theta -= 0.08
        background('#004477')
        #translate(width/2, height/2)  # let's try without this
        #circle and pison: side view
        push_matrix()        # backup the coordinate transforms
        translate(400, 200)  # this will be undone by pop_matrix()
        x = cos(theta)
        y = sin(theta)
        yc = 120  # center of the circle
        line(radius, yc, x * -radius + radius, y * radius + yc)
        diameter = radius * 2
        circle(radius, yc, diameter)
        #piston arm attached to inner arm: side view
        line( x + radius, y * radius + radius,
             -x * radius + radius, y * radius + yc)
        #piston body: side view 
        rect(x, y * radius, radius * 2, radius * 2)
        #piston body lines: side view
        line(x, y * radius + 15, x + radius * 2, y * radius + 15)
        line(x, y * radius + 10, x + radius * 2, y * radius + 10)
        line(x, y * radius + 5, x + radius * 2, y * radius + 5)
        pop_matrix() # resets coordinate transforms
    
        # working on the original coordinates: 0, 0, on top left corner    
        piston_body(50, 200, theta)
        piston_body(120, 200, theta + PI / 3)
        piston_body(190, 200, theta + 2 * PI / 3)
        
    def piston_body(xp, yp, theta):
        #piston body
        x = cos(theta)
        y = sin(theta)
        push_matrix()
        translate(xp, yp)
        rect(-radius, y*radius*+1, radius * 2, radius * 2) 
        line(-radius, y*radius+5, radius, y*radius+5)
        line(-radius, y*radius+10, radius, y*radius+10)
        line(-radius, y*radius+15, radius, y*radius+15)
        line(0, y*radius+30, 0, y*radius+150)
        pop_matrix()

    Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationhelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions