import numpy as np
import matplotlib.pyplot as plt
# ساخت یه دایره با اندازه یکسان در تمام جهتها
circle = plt.Circle((0, 0), 0.5, color='gray', fill=True)
# مختصات محورها تو حالت خاکستری روشن
x = np.linspace(-1, 1, 1000)
X, Y = np.meshgrid(x, x)
Z = np.sqrt(X*X + Y*Y)
# رسم محورها و دایره در یه نمودار
fig, ax = plt.subplots()
ax.contourf(X, Y, Z, levels=30, cmap='gray')
ax.add_artist(circle)
# رسم نمودار
plt.axis('scaled')
plt.show()
#نشون_دادن_کره_ماه
Coders
import numpy as np import matplotlib.pyplot as plt # ساخت یه دایره با اندازه یکسان در تمام جهتها c
کتابخونه هاشم که بلدین کدوما هستن
import tkinter as tk
import time
class TimerApp:
def init(self, master):
self.master = master
master.title("Timer App")
self.time_var = tk.StringVar()
self.time_var.set('00:00:00')
self.timer_label = tk.Label(master, textvariable=self.time_var, font=('Helvetica', 48))
self.timer_label.pack()
self.start_button = tk.Button(master, text="Start", command=self.start_timer)
self.start_button.pack()
self.running = False
def start_timer(self):
if not self.running:
self.running = True
self.start_button.config(text="Stop")
self.start_time = time.time()
self.update_timer()
else:
self.master.after_cancel(self.timer_job)
self.running = False
self.start_button.config(text="Start")
def update_timer(self):
elapsed_time = time.time() - self.start_time
hours, rem = divmod(elapsed_time, 3600)
minutes, seconds = divmod(rem, 60)
time_string = '{:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds))
self.time_var.set(time_string)
self.timer_job = self.master.after(1000, self.update_timer)
root = tk.Tk()
timer_app = TimerApp(root)
root.mainloop()
#ساخت_یک_تایمر_پیشرفته
این کد به شما کمک می کنه تا یه آهنگ رو از اینترنت دانلود کرده و در پوشه موسیقی ذخیره کنین
اول باید کتابخونه requests رو نصب کنین
pip install requests
بعدش با استفاده از کد زیر لینک آهنگ مورد نظر خود رو تو قسمت url قرار بدید
import requests
url = "https://example.com/song.mp3"
response = requests.get(url)
with open("music/song.mp3", "wb") as f:
f.write(response.content)
تو اینجا فایل mp3 با نام song تو پوشه music ذخیره می شه
پیاده سازی پروژه تشخیص حرکت با استفاده از کتابخانه OpenCV:
اول کتابخونه رو از ترمینال دانلود کنین :
pip3 install opencv-python –user
کد :
#Import Library
import cv2
#First frame
first_frame = None
#Capture Video
our_video = cv2.VideoCapture(0)
while True:
#Check if loaded correctly
check, frame = our_video.read()
#Conver to Gray
our_frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
our_frame_gray = cv2.GaussianBlur(our_frame_gray,(21,21),0)
#Set first frame
if first_frame is None:
first_frame=our_frame_gray
continue
#Delta frame
#Compare first frame to current frame
delta_frame = cv2.absdiff(first_frame, our_frame_gray)
#Thresold frame
threshold_frame = cv2.threshold(delta_frame, 30, 255, cv2.THRESH_BINARY)[1]
threshold_frame = cv2.dilate(threshold_frame, None, iterations=2)
#Contours
cnts, hierarchy = cv2.findContours(threshold_frame.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
#Draw rectangle for moving objects
for contour in cnts:
if cv2.contourArea(contour) < 500:
continue
x, y, w, h = cv2.boundingRect(contour)
cv2.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), 3)
#Show the captured frame of video
cv2.imshow("First Frame", first_frame)
cv2.imshow("Capturing first ", our_frame_gray)
cv2.imshow("Delta Frame", delta_frame)
cv2.imshow("Threshold Frame", threshold_frame)
cv2.imshow("Detecting objects", frame)
#Set q=quit
key = cv2.waitKey(1)
if(key == ord('q')):
break
our_video.release()
cv2.destroyAllWindows
#پروژه_تشخیص_حرکت