Advertisement
j0h

demo.py

j0h
Feb 21st, 2024 (edited)
1,104
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.03 KB | None | 0 0
  1. #!/usr/bin/python3
  2. import turtle
  3. import time
  4. import math
  5. # There is a chance all of this has to be in raw mode on the pi
  6. #Demo functions for sketch-y-etch
  7.  
  8. t = turtle.Turtle()
  9. t.hideturtle()
  10. t.speed(0.5)
  11. t.width(4)
  12. t.color("blue")
  13.  
  14. # Set up the turtle screen
  15. screen = turtle.Screen()
  16. screen.setup(width=1.0, height=1.0)  # Set the window to full-screen mode
  17.  
  18. ####General Use Function#####
  19. def blank():
  20.     t.clear()
  21.     t.goto(0,0)
  22.  
  23.  
  24. #######Function drawings#####
  25. def draw_Flower():
  26.     #inverted Arguelle's mandala
  27.     RAD = 200
  28.     radii = [RAD, RAD/1.25, RAD/1.5, RAD/1.75, RAD/2, RAD/2.25, RAD/3, RAD/4]
  29.  
  30.     def derp():
  31.         t.pendown()
  32.         for r in radii:
  33.             t.circle(r, 360)
  34.         t.penup()
  35.  
  36.     derp()
  37.     t.left(-90)
  38.     derp()
  39.     t.goto(0,0)
  40.     t.left(-180)
  41.     derp()
  42.     t.goto(0,0)
  43.     t.left(-270)
  44.     derp()
  45.    
  46. def mandala():
  47. ## http://programming1work.oyosite.com/ch_turtle-mandala.html
  48.     t.pendown()
  49.     for times in range(36):
  50.         t.color("blue")
  51.         t.speed(11)
  52.         t.circle(100)
  53.         t.color("red")
  54.         t.forward(200)
  55.         t.left(120)
  56.         t.color("orange")
  57.         t.forward(100)
  58.         t.right(120)
  59.         t.left(170)
  60.         t.left(20)
  61.         t.forward(15)
  62.        
  63.            
  64. def arguelles():
  65.     RAD = 200
  66.     radii = [RAD, RAD/1.25, RAD/1.5, RAD/1.75, RAD/2, RAD/2.25, RAD/3, RAD/4]
  67.  
  68.     def derp():
  69.         t.pendown()
  70.         for r in radii:
  71.             t.circle(r, 360)
  72.         t.penup()
  73.  
  74.     derp()
  75.     t.goto(RAD,RAD)
  76.     t.left(90)
  77.     derp()
  78.     t.goto(0,0)
  79.     t.goto(-RAD,RAD)
  80.     t.left(180)
  81.     derp()
  82.     t.goto(0,0)
  83.     t.goto(0,RAD*2)
  84.     t.left(270)
  85.     derp()
  86.    
  87. #Demo mode function for dumping source code clone to the turtle window
  88. def dumpSRC():
  89.     def draw_text_line(t, text, y):
  90.         t.penup()
  91.         t.goto(-300, y)  # Start position for the text
  92.         t.pendown()
  93.         t.write(text, font=("Arial", 12, "normal"))  # Write the text
  94.    
  95.     with open("source.txt", "r") as file:
  96.         y = 350  # Starting y-coordinate for the first line of text
  97.         for line in file:
  98.             draw_text_line(t, line.strip(), y)
  99.             y -= 20  # Move down for the next line
  100.  
  101.         # Check if the next line will exceed the window height
  102.             if y < -350:
  103.                 time.sleep(2)
  104.             # Clear the screen & resume writing
  105.                 t.clear()
  106.             # Reset the start position
  107.                 y = 350
  108.     draw_text_line(t, "Source Code Dump Successful", y)
  109.  
  110. # Draw a yin yang symbol
  111. def taiju():
  112.     t.penup()
  113.     RAD = 200
  114.     RAD2 = RAD / 2
  115.     RAD6 = RAD / 6
  116.     t.hideturtle()
  117.     t.degrees() # Switch to degrees
  118.     t.goto(0,-RAD)
  119.     t.pendown()
  120. # Draw the circle, radius 100, half black
  121.     t.fillcolor('black')
  122.     t.begin_fill()
  123.     t.circle(RAD, 180)
  124.     t.end_fill()
  125.     t.circle(RAD, 180)
  126.  
  127. # Draw black head
  128.     t.left(180)
  129.     t.penup()
  130.     t.goto(0, RAD)
  131.     t.pendown()
  132.     t.begin_fill()
  133.     t.circle(RAD2, 180)
  134.     t.end_fill()
  135.  
  136. # Draw white head
  137.     t.penup()
  138.     t.goto(0, -RAD)
  139.     t.pendown()
  140.     t.fillcolor('white')
  141.     t.begin_fill()
  142.     t.circle(RAD2, 180)
  143.     t.end_fill()
  144.  
  145. # Draw eyes
  146.     t.penup()
  147.     t.goto(0, RAD2 + RAD6)
  148.     t.begin_fill()
  149.     t.circle(RAD6)
  150.     t.end_fill()
  151.  
  152.     t.fillcolor('black')
  153.     #t.goto(0, 2 * (RAD - RAD6))
  154.     t.goto(0, 2 * (-RAD6))
  155.     t.begin_fill()
  156.     t.circle(RAD6)
  157.     t.end_fill()    
  158.            
  159. """
  160. Functions:
  161. draw_Flower()
  162. mandala()
  163. arguelles()
  164. dumpSRC()
  165. taiju()
  166. """  
  167.    
  168. arguelles()
  169. time.sleep(3)
  170. blank()
  171.  
  172. draw_Flower()
  173. time.sleep(3)
  174. blank()
  175.  
  176. dumpSRC() #text size could be increased
  177. time.sleep(3)
  178. t.clear()
  179.  
  180. t.color("black")
  181. taiju()        
  182. time.sleep(3)    
  183.  
  184. blank()
  185. mandala() # on func end color is yellow
  186. time.sleep(3)
  187.  
  188. """      
  189. #Todo
  190. *Fixed! bugs that occurred when making it run full screen
  191. add more functions,
  192. write a loop.
  193. listen for IO,
  194. kill other processes,
  195. write a class, or a library
  196. """      
  197.  
Advertisement
Comments
  • j0h
    j0h
    275 days
    # text 0.20 KB | 0 0
    1. turtle reset resets every thing, and turtle clear only errases the screen, not the other settings. blank() maintains things like cursor shape, width, color, pen-settings. etc. Clears the screen, and goes home
Add Comment
Please, Sign In to add comment
Advertisement