from turtle import *
state = {'turn': 0}
def spinner():
"Draw fidget spinner."
clear()
angle = state['turn'] / 10
left(angle)
forward(100)
dot(120, 'red')
back(100)
left(120)
forward(100)
dot(120, 'red')
back(100)
left(120)
forward(100)
dot(120, 'red')
back(100)
left(120)
update()
def animate():
"Animate fidget spinner."
if state['turn'] > 0:
state['turn'] -= 1
spinner()
ontimer(animate, 20)
def flick():
"Flick fidget spinner."
state['turn'] += 50
tracer(False)
width(20)
onkey(flick, 'space')
listen()
animate()
done()
state = {'turn': 0}
def spinner():
"Draw fidget spinner."
clear()
angle = state['turn'] / 10
left(angle)
forward(100)
dot(120, 'red')
back(100)
left(120)
forward(100)
dot(120, 'red')
back(100)
left(120)
forward(100)
dot(120, 'red')
back(100)
left(120)
update()
def animate():
"Animate fidget spinner."
if state['turn'] > 0:
state['turn'] -= 1
spinner()
ontimer(animate, 20)
def flick():
"Flick fidget spinner."
state['turn'] += 50
tracer(False)
width(20)
onkey(flick, 'space')
listen()
animate()
done()
https://youtu.be/BKwnOOs0ml8. Guys video out now 🙋
YouTube
| How to create a Snake game using python | | AK python |
In this video we are going to see about how to create a snake game using python
We are using three libraries to create this epic game that is turtle, random and freegames
Snake game is an epic game. And it provides so many past moments to you
Download…
We are using three libraries to create this epic game that is turtle, random and freegames
Snake game is an epic game. And it provides so many past moments to you
Download…
👍1
from turtle import *
from random import randrange
from freegames import square, vector
food = vector(0, 0)
snake = [vector(10, 0)]
aim = vector(0, -10)
def change(x, y):
"Change snake direction."
aim.x = x
aim.y = y
def inside(head):
"Return True if head inside boundaries."
return -200 < head.x < 190 and -200 < head.y < 190
def move():
"Move snake forward one segment."
head = snake[-1].copy()
head.move(aim)
if not inside(head) or head in snake:
square(head.x, head.y, 9, 'red')
update()
return
snake.append(head)
if head == food:
print('Snake:', len(snake))
food.x = randrange(-15, 15) * 10
food.y = randrange(-15, 15) * 10
else:
snake.pop(0)
clear()
for body in snake:
square(body.x, body.y, 9, 'green')
square(food.x, food.y, 9, 'red')
update()
ontimer(move, 100)
hideturtle()
tracer(False)
listen()
onkey(lambda: change(10, 0), 'Right')
onkey(lambda: change(-10, 0), 'Left')
onkey(lambda: change(0, 10), 'Up')
onkey(lambda: change(0, -10), 'Down')
move()
done()
from random import randrange
from freegames import square, vector
food = vector(0, 0)
snake = [vector(10, 0)]
aim = vector(0, -10)
def change(x, y):
"Change snake direction."
aim.x = x
aim.y = y
def inside(head):
"Return True if head inside boundaries."
return -200 < head.x < 190 and -200 < head.y < 190
def move():
"Move snake forward one segment."
head = snake[-1].copy()
head.move(aim)
if not inside(head) or head in snake:
square(head.x, head.y, 9, 'red')
update()
return
snake.append(head)
if head == food:
print('Snake:', len(snake))
food.x = randrange(-15, 15) * 10
food.y = randrange(-15, 15) * 10
else:
snake.pop(0)
clear()
for body in snake:
square(body.x, body.y, 9, 'green')
square(food.x, food.y, 9, 'red')
update()
ontimer(move, 100)
hideturtle()
tracer(False)
listen()
onkey(lambda: change(10, 0), 'Right')
onkey(lambda: change(-10, 0), 'Left')
onkey(lambda: change(0, 10), 'Up')
onkey(lambda: change(0, -10), 'Down')
move()
done()
👍7👏1
import psutil
battery = psutil.sensors_battery()
percent = battery.percent
from pynotifier import Notification
Notification(
title="Battery Percentage.",
description=str(percent) + "% Battery remaining.",
duration=5, # Duration in seconds
).send()
battery = psutil.sensors_battery()
percent = battery.percent
from pynotifier import Notification
Notification(
title="Battery Percentage.",
description=str(percent) + "% Battery remaining.",
duration=5, # Duration in seconds
).send()
👍2
import COVID19Py
covid19 = COVID19Py.COVID19(data_source="jhu")
latest = covid19.getLatest()
from pynotifier import Notification
Notification(
title="Today COVID 19 News updates.",
description=str(latest),
duration=30, # Duration in seconds
).send()
covid19 = COVID19Py.COVID19(data_source="jhu")
latest = covid19.getLatest()
from pynotifier import Notification
Notification(
title="Today COVID 19 News updates.",
description=str(latest),
duration=30, # Duration in seconds
).send()
This media is not supported in your browser
VIEW IN TELEGRAM
Keep support and share. I will try my best❤️
import moviepy.editor as mp
clip=mp.VideoFileClip(r'Path of your video file')
clip.audio.write_audiofile(r'Path of your audio file')
clip=mp.VideoFileClip(r'Path of your video file')
clip.audio.write_audiofile(r'Path of your audio file')
👍1