Posts

PENCIL SKETCHING in Python ..

Image
 You don't need Snapchat to covert your image to pencil-sketched image .. All you need is Python .. :) All you need is a picture in the same directory .. My image   You can choose any image you want .. import cv2               # pip install opencv-python filename = 'av.jpg'    # the picture img = cv2.imread(filename)     # reading the image gray_image = cv2.cvtColor(img , cv2.COLOR_BGR2GRAY)     # changing BGR to Gray inverted_gray_image = 255 - gray_image                    # inverting the Gray color blurred_img = cv2.GaussianBlur(inverted_gray_image , ( 21 , 21 ) , 0 ) # blurring the image inverted_blurred_img = 255 - blurred_img                  # inverting the blurred image pencil_sketch_IMG = cv2.divide(gray_image , inverted_blurred_img , scale = 256.0 ) #Show the origin...

Screenshot in Python ..

Image
 Taking screenshot in Python is very easy .. Let's take a look at the code .. import numpy as np # pip install numpy import cv2             # pip install opencv-python import pyautogui       # pip install pyautogui import datetime        # pre-installed module image = pyautogui.screenshot() # pyautogui takes screenshot .. image = cv2.cvtColor(np.array(image) , cv2.COLOR_RGB2BGR)        # image is converted to BGR time_stamp = datetime.datetime.now().strftime( '%Y-%m-%d %H-%M-%S' ) # time stamp file_name= f' { time_stamp } .png' # naming it as png file cv2.imwrite(file_name , image)     # saving the image And if we run the code ...

AMONG US in Python ..

Image
  If you like Among-Us then this Python project is for you .. import turtle # pre-installed module import random # pre-installed module win = turtle.getscreen() # the screen set-up impostor = turtle.Turtle() win.setup( width = 600 , height = 600 ) win.title( 'Among Us' ) win.bgcolor( 'black' ) color = random.randint( 1 , 10 ) # randomizing the colors if color == 1 : amo= 'red' elif color == 2 : amo = 'green' elif color == 3 : amo = 'cyan' elif color == 4 : amo = 'pink' elif color == 5 : amo = 'purple' elif color == 6 : amo = 'blue' elif color == 7 : amo = 'brown' elif color == 8 : amo = 'orange' elif color == 9 : amo = 'yellow' else : amo = 'white' body_color = amo # the color of the body glass_color = '#9acedc' # it can move forward backward left right def body (): """ draws the body """ ...

Machine learning in python ..

Image
Python is predominantly used for Artificial Intelligence ... Data science combines the scientific method, math and statistics, specialized programming, advanced analytics, AI, and even storytelling to uncover and explain the business insights buried in data. And Machine learning is one of the types of Data Science .. Here we are going to look how to create a very basic Machine Learning Model that predicts the human population in the upcoming years .. In your terminal ... pip install numpy pip install pandas pip install matplotlib pip install scikit-learn   The code .. # importing the modules import pandas as pd             import matplotlib.pyplot as plt # reading the excel file of population.xlsx data=pd.read_excel('population.xlsx')     print(data) x=data.year y=data.population plt.plot(x,y) plt.show() The excel file looks like this ... Year Population 1950 2,53,64,31,149 1955 2,77,30,19,936 1960 3,03,49,49,748 1965 3,33...

Clock development [part 2 : in Python]

Image
  Why buy a clock when you can build one .... ? If you know Python , it is so easy to make one .. The Code .. from PyQt5.QtWidgets import * # pip install PyQt5 from PyQt5 import QtCore , QtGui from PyQt5.QtGui import * from PyQt5.QtCore import * import sys # creating a clock class class Clock(QMainWindow): # constructor def __init__ ( self ): super (). __init__ () # creating the timer object timer = QTimer( self ) # moving the timer # update the whole code timer.timeout.connect( self .update) # setting the start time of the timer i.e 1 second timer.start( 1000 ) # setting window title self .setWindowTitle( 'Analog Clock' ) # setting window geometry self .setGeometry( 200 , 200 , 300 , 300 ) # setting background color to the window self .setStyleSheet( "background : black;" ) # creating hour hand self .hPointer = QtGui.QPolygon([QPo...

Clock development [PART 1 : in HTML]

Why buy a clock when you can build one .... ? If you know HTML , it is so easy to make one .. The Code .. <!DOCTYPE html> <html> <body> <canvas id= "canvas" width= "400" height= "400" style= "background-color:#333" > </canvas> <script> var canvas = document.getElementById( "canvas" ); var ctx = canvas.getContext( "2d" ); var radius = canvas.height / 2 ; ctx.translate(radius , radius); radius = radius * 0.90 setInterval(drawClock , 1000 ); function drawClock() { drawFace(ctx , radius); drawNumbers(ctx , radius); drawTime(ctx , radius); } function drawFace(ctx , radius) { var grad; ctx.beginPath(); ctx.arc( 0 , 0 , radius , 0 , 2 *Math.PI); ctx.fillStyle = 'white' ; ctx.fill(); grad = ctx.createRadialGradient( 0 , 0 , radius* 0.95 , 0 , 0 , radius* 1.05 ); grad.addColorStop( 0 , '#333' ); grad.addColorStop( 0.5 , 'white' ); grad.addColorStop( 1 ,...

Fidget Spinner in python ..😀

Image
  If you are a programmer who want to relax yourself without spending money on fidget spinner ,this project is for you ... from turtle import * # in-built module state={ 'turn' : 0 } def spinner (): # function to make it spin clear() angle=state[ 'turn' ]/ 10 right(angle) # will make the spinner spin right by the given angle above forward( 100 ) dot( 120 , 'blue' ) back( 100 ) right( 120 ) forward( 100 ) dot( 120 , 'blue' ) back( 100 ) right( 120 ) forward( 100 ) dot( 120 , 'blue' ) back( 100 ) right( 120 ) update() # update the given function def animate (): # function for animation if state[ 'turn' ]> 0 : state[ 'turn' ]-= 1 spinner() # calling the spinner function ontimer(animate , 20 ) def flick (): # function to flick the fidget spinner state[ 'turn' ]+= 50 tracer( False ) width( 20 ) bgcol...