Sentiment Analyzer

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

from tkinter import *

def clear() :

    negativeField.delete(0, END)

    neutralField.delete(0, END)

    positiveField.delete(0, END)

    overallField.delete(0, END)

    textArea.delete(1.0, END)

def detect_sentiment():

    sentence = textArea.get("1.0", "end")

    sid_obj = SentimentIntensityAnalyzer()

    sentiment_dict = sid_obj.polarity_scores(sentence)

    string = str(sentiment_dict['neg']*100) + "% Negative"

    negativeField.insert(10, string)

    string = str(sentiment_dict['neu']*100) + "% Neutral"

    neutralField.insert(10, string)

    string = str(sentiment_dict['pos']*100) +"% Positive"

    positiveField.insert(10, string)

    if sentiment_dict['compound'] >= 0.05 :

        string = "Positive"

    elif sentiment_dict['compound'] <= - 0.05 :

        string = "Negative"

    else :

        string = "Neutral"

    overallField.insert(10, string)

if __name__ == "__main__" :

    gui = Tk()

    gui.config(background = "light blue")

    gui.title("Sentiment Detector")

    gui.geometry("250x400")

    enterText = Label(gui, text = "Enter Your Sentence",

                                    bg = "light blue")

    textArea = Text(gui, height = 5, width = 25, font = "lucida 13")

    check = Button(gui, text = "Check Sentiment", fg = "Black",

                        bg = "Red", command = detect_sentiment)

    negative = Label(gui, text = "sentence was rated as: ",

                                        bg = "light blue")

    neutral = Label(gui, text = "sentence was rated as: ",

                                    bg = "light blue")

    positive = Label(gui, text = "sentence was rated as: ",

                                        bg = "light blue")

    overall = Label(gui, text = "Sentence Overall Rated As: ",

                                        bg = "light blue")

    negativeField = Entry(gui)

    neutralField = Entry(gui)

    positiveField = Entry(gui)

    overallField = Entry(gui)

    clear = Button(gui, text = "Clear", fg = "Black",

                    bg = "Red", command = clear)

    Exit = Button(gui, text = "Exit", fg = "Black",

                        bg = "Red", command = exit)

    enterText.grid(row = 0, column = 2)

    textArea.grid(row = 1, column = 2, padx = 10, sticky = W)

    check.grid(row = 2, column = 2)

    negative.grid(row = 3, column = 2)

    neutral.grid(row = 5, column = 2)

    positive.grid(row = 7, column = 2)

    overall.grid(row = 9, column = 2)

    negativeField.grid(row = 4, column = 2)

    neutralField.grid(row = 6, column = 2)             

    positiveField.grid(row = 8, column = 2)

    overallField.grid(row = 10, column = 2)

    clear.grid(row = 11, column = 2)

    Exit.grid(row = 12, column = 2)

    gui.mainloop()

    


Racing Animation

from turtle import * 

from random import randint

speed(0)

penup()

goto(-140, 140)

for step in range(15):

write(step, align ='center')

right(90)

for num in range(8):

penup()

forward(10)

pendown()

forward(10)

penup()

backward(160)

left(90)

forward(20)

player_1 = Turtle()

player_1.color('red')

player_1.shape('turtle')

player_1.penup()

player_1.goto(-160, 100)

player_1.pendown()

for turn in range(10):

player_1.right(36)

player_2 = Turtle()

player_2.color('blue')

player_2.shape('turtle')

player_2.penup()

player_2.goto(-160, 70)

player_2.pendown()

for turn in range(72):

player_2.left(5)

player_3 = Turtle()

player_3.shape('turtle')

player_3.color('green')

player_3.penup()

player_3.goto(-160, 40)

player_3.pendown()

for turn in range(60):

player_3.right(6)

player_4 = Turtle()

player_4.shape('turtle')

player_4.color('orange')

player_4.penup()

player_4.goto(-160, 10)

player_4.pendown()

for turn in range(30):

player_4.left(12)

for turn in range(100):

player_1.forward(randint(1, 5))

player_2.forward(randint(1, 5))

player_3.forward(randint(1, 5))

player_4.forward(randint(1, 5))


BGR color palette

import cv2

import numpy as np

def emptyFunction():

pass

def main():

image = np.zeros((512, 512, 3), np.uint8)

windowName ="Open CV Color Palette"

cv2.namedWindow(windowName)

cv2.createTrackbar('Blue', windowName, 0, 255, emptyFunction)

cv2.createTrackbar('Green', windowName, 0, 255, emptyFunction)

cv2.createTrackbar('Red', windowName, 0, 255, emptyFunction)

while(True):

cv2.imshow(windowName, image)

if cv2.waitKey(1) == 27:

break

blue = cv2.getTrackbarPos('Blue', windowName)

green = cv2.getTrackbarPos('Green', windowName)

red = cv2.getTrackbarPos('Red', windowName)

image[:] = [blue, green, red]

print(blue, green, red)

cv2.destroyAllWindows()

if __name__=="__main__":

main()


Countdown Timer

import time

from tkinter import *

from tkinter import messagebox

root = Tk()

root.geometry("300x250")

root.title("Time Counter")

hour=StringVar()

minute=StringVar()

second=StringVar()

hour.set("00")

minute.set("00")

second.set("00")

hourEntry= Entry(root, width=3, font=("Arial",18,""),

textvariable=hour)

hourEntry.place(x=80,y=20)


minuteEntry= Entry(root, width=3, font=("Arial",18,""),

textvariable=minute)

minuteEntry.place(x=130,y=20)


secondEntry= Entry(root, width=3, font=("Arial",18,""),

textvariable=second)

secondEntry.place(x=180,y=20)

def submit():

try:

temp = int(hour.get())*3600 + int(minute.get())*60 + int(second.get())

except:

print("Please input the right value")

while temp >-1:

mins,secs = divmod(temp,60)

hours=0

if mins >60:

hours, mins = divmod(mins, 60)

hour.set("{0:2d}".format(hours))

minute.set("{0:2d}".format(mins))

second.set("{0:2d}".format(secs))

root.update()

time.sleep(1)

if (temp == 0):

messagebox.showinfo("Time Countdown", "Time's up ")

temp -= 1

btn = Button(root, text='Set Time Countdown', bd='5',

command= submit)

btn.place(x = 70,y = 120)

root.mainloop()


Pedestrian Detector for images

import cv2

import imutils

# detector

hog = cv2.HOGDescriptor()

hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())

# Reading the Image

image = cv2.imread('img_path')

# Resizing the Image

image = imutils.resize(image,

width=min(400, image.shape[1]))

# Detecting all the regions in the

# Image that has a pedestrians inside it

(regions, _) = hog.detectMultiScale(image,

winStride=(4, 4),

padding=(4, 4),

scale=1.05)

# Drawing the regions in the Image

for (x, y, w, h) in regions:

cv2.rectangle(image, (x, y),

(x + w, y + h),

(0, 0, 255), 2)

# Showing the output Image

cv2.imshow("Image", image)

cv2.waitKey(0)

cv2.destroyAllWindows()