소스 검색

Update 'README.md'

+ example
tBKwtWS 1 일 전
부모
커밋
2bc429ad33
1개의 변경된 파일45개의 추가작업 그리고 1개의 파일을 삭제
  1. 45 1
      README.md

+ 45 - 1
README.md

@@ -12,7 +12,8 @@ For use by students who want to make art or games with Karel as a character.
     * Or by downloading/cloning this project and uploading the karel_asset.py file with the upload button on the CIP IDE
 
 ## Using karel_asset.py when it is added to a CIP project
-1. In your main.py or any other project file on CIP, add: `from karel_asset import *`
+In your main.py or any other project file on CIP, add: `from karel_asset import *`
+
 ### Drawing Karel
 To simply draw a Karel in the top left corner use: `draw_karel(canvas)`
 But surely this will not suffice for any project so there are optional arguments to pass:
@@ -29,11 +30,13 @@ To draw a Karel in the middle of X / Y coordinates 100 / 100, use the optional a
 ```
 draw_karel(canvas, 100, 100)
 ```
+
 #### Size
 To draw a Karel of size 200, use the optional argument size:
 ```
 draw_karel(canvas, size=200)
 ```
+
 #### Orientation
 To draw a Karel facing north, use the optional argument orientation:
 ```
@@ -49,6 +52,7 @@ Orientation options:
 * "south"
 * "south-flipped"
 Flipped makes Karel appear upside down.
+
 #### Colour
 To draw a Karel in any colour use the optional argument colour:
 ```
@@ -99,4 +103,44 @@ To remove a Karel from the canvas, use erase_karel(karel):
 ```
 my_karel = draw_karel(canvas, colour="red", background="blue")
 my_karel = erase_karel(my_karel)
+```
+
+## Example
+```
+from graphics import Canvas
+from karel_asset import *
+from time import sleep
+
+# Constants    
+CANVAS_WIDTH = 120
+CANVAS_HEIGHT = 70
+
+def main():
+    canvas = Canvas(CANVAS_WIDTH, CANVAS_HEIGHT)
+    
+    while True:    # Keep repeating the following code forever
+    
+        # Draw four Karels
+        karel_east = draw_karel(canvas, 35, 35)
+        karel_east_mirrored = draw_karel(canvas, 85, 35, orientation="east-flipped", colour="red")
+        karel_west = draw_karel(canvas, 135, 35, orientation="west", background="red")
+        karel_west_mirrored = draw_karel(canvas, 185, 35, orientation="west-flipped", colour="red", background="red")
+        
+        # Wait five seconds
+        sleep(5)
+        
+        # Change the colour of one Karel to random colours
+        karel_east = recolour_karel(big_karel_east, "random", "random")
+        
+        # Move one Karel
+        karel_east_mirrored = move_karel(karel_east_mirrored, 10, 10)
+        
+        # Wait five seconds
+        sleep(5)
+        
+        # Erase four Karels
+        erase_karel(karel_east)
+        erase_karel(karel_east_mirrored)
+        erase_karel(karel_west)
+        erase_karel(karel_west_mirrored)
 ```