Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 141 - 2615_KEC
P. 141

    HANDS-ON PROJECT

                     PROJECT: Creating a Scene (Independence Day/Christmas) Using SimpleGUI

                     Software Used: CodeSkulptor
                     Objective:

                     Use SimpleGUI in CodeSkulptor3 (Codeskulptor3.-https://py3.codeskulptor.org/) to draw shapes
                     and design a visual scene representing Independence Day, Christmas or any themed event.

                     Use Codeskulptor3-https://py3.codeskulptor.org/

                     Step-by-Step Instructions: (Plan IPO)
                     1.  Input:

                             Plan the objects/entities you want to display on the canvas (e.g., flag, star, snowman, tree).

                             Identify the basic shapes (lines, circles, polygons) that make up each object.

                     2.  Process: Use SimpleGUI drawing functions to create your scene:
                             canvas.draw_line – Draws a straight line between two points (e.g., flagpole or ground line).

                             canvas.draw_polygon – Creates  a closed  shape  by  connecting  multiple  points
                             (e.g., flags, stars).

                             canvas.draw_circle –  Draws  a circle with a specified  center  and radius  (e.g., sun,
                             ornaments or balloons).

                             canvas.draw_arc – Draws a curved line or arc (e.g., rainbow, semi-circles).
                     3.  Sample Code:

                         import simplegui

                         message = "Welcome!"

                         message2 = "ABC XYZ 7C"

                         # Handler to draw on canvas
                         def draw(canvas):

                             canvas.draw_text(message, [50,112], 48, "yellow")

                             canvas.draw_line([120,100],[12,100],5,"red")

                             canvas.draw_circle([60,30],20,8,"white","green")

                             canvas.draw_text(message2, [240,195], 10, "yellow")
                         # Create a frame and assign callbacks to event handlers

                         frame = simplegui.create_frame("Home", 300, 200)

                                                                                                     Canvas in Python   139

| 136 137 138 139 140 141 142 143 144 145 146 |