CodeSkulptor3 (Simple Graph) Aug 2020

I built a short presentation demonstrating the use of CodeSkulptor3 (Python 3).

This time, my goal was to illustrate coding a small graphic program — accessible from any device — desktop, phone, iPad.
Feel free to follow the links and to offer a critique.
CodeSkulptor3 is a free Python language 'sandbox' for messing around with simple programs

How to Make a Graph
Link to my layout PDF

Code Text

Copy the code below
Paste it into CodeSkulptor3.
and press the run button


# CodeSkulptor3 runs Python programs in your browser.
# Click the upper left button to run this simple demo.

# CodeSkulptor is tested to run in recent versions of
# Chrome, Firefox, and Safari.

import simplegui

message = "Welcome!"

# Handler for mouse click
def click():
    global message
    message = "Good job!"

# Handler to draw on canvas
def draw(canvas):
    
    # see PDF for layout and coordinates of shapes s1, s2, s3, s4
    # using zip function to zip xcoords to ycoords for each s
    # using the zip function is easier to type -- much fewer parentheses
    # as an example, after the zip s1 = [(30, 30), (90, 30), (90, 70), (30, 70)]

    s1 = list(zip([30, 90, 90, 30],
                  [30, 30, 70, 70]))
    s2 = list(zip([170, 190, 140],
                  [60, 100, 100]))
    s3 = list(zip([80, 100, 100, 130, 130, 70, 60, 60, 80],
                  [110, 110, 160, 160, 200, 200, 180, 130, 130]))
    s4 = list(zip([180, 240, 210, 180],
                  [150, 130, 180, 200]))
    
    canvas.draw_text(message, [220, 50], 14, "Cyan")

    canvas.draw_polygon(s1, 3, 'Green')
    canvas.draw_polygon(s2, 6, 'Red')
    canvas.draw_polygon(s3, 4, 'Blue', 'White')
    canvas.draw_polygon(s4, 10, 'Yellow', 'Orange')    

# Create a frame and assign callbacks to event handlers
frame = simplegui.create_frame("Home", 300, 250)
frame.add_button("Click me", click)
frame.set_draw_handler(draw)

# Start the frame animation
frame.start()

Leave a Reply

Your email address will not be published. Required fields are marked *