Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit c7419b6

Browse files
Merge pull request #5 from ankitdobhal/master
Getting changes
2 parents 1df0168 + 5e512fb commit c7419b6

File tree

46 files changed

+1920
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1920
-1
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# function to convert infix to postfix using array as stack
2+
def infix_to_postfix(infix_expression):
3+
"""
4+
Function to change infix expression to postfix one
5+
Params:
6+
infix_expression: Infix Expression provided by user
7+
Returns:
8+
postfix_expression: Postfix Expression convertef from Infix one
9+
"""
10+
11+
# initially empty stack
12+
stack = []
13+
# initially empty postfix_expression
14+
postfix_expression = ""
15+
for char in infix_expression:
16+
# if an operand then put it directly in postfix expression
17+
if char not in operators:
18+
postfix_expression += char
19+
# else if operators should be put in stack
20+
elif char == "(":
21+
"""append function to push
22+
elements in the stack"""
23+
stack.append("(")
24+
elif char == ")":
25+
while stack and stack[-1] != "(":
26+
postfix_expression += stack.pop()
27+
""" pop function to pop
28+
elements from stack in LIFO order """
29+
stack.pop()
30+
else:
31+
"""if priority of char in infix_expression is less than or equal to
32+
char at stack[-1] pop out and put in postfix_expression"""
33+
while (
34+
stack and stack[-1] != "(" and priorities[char] <= priorities[stack[-1]]
35+
):
36+
postfix_expression += stack.pop()
37+
stack.append(char)
38+
while stack:
39+
postfix_expression += stack.pop()
40+
return postfix_expression
41+
42+
43+
# Set of operators
44+
operators = set(["+", "-", "*", "/", "(", ")", "^"])
45+
46+
# dictionary having priorities
47+
priorities = {"+": 1, "-": 1, "*": 2, "/": 2, "^": 3}
48+
49+
print("Input")
50+
infix_expression = input("Enter infix expression\n")
51+
print("Output")
52+
53+
# Displaying the Output
54+
print("Postfix expression: ", infix_to_postfix(infix_expression))
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### Infix to Postfix
2+
3+
> • In Infix expression operator is in between every pair of operands.<br>
4+
> • In Postfix expression, the operator is followed for every pair of operands.
5+
6+
> Infix expression is converted to postfix conversion using Stack.
7+
> Postfix expression is evaluated using Stack in Left to Right order.
8+
9+
##### If the scanned character is operand, show it as output. Else, If precedence of scanned operator is greater than the precedence of the operator in the stack,push it.
10+
11+
> Else, Pop all the operators from the stack which are greater than or equal to in precedence than that of the scanned operator.
12+
13+
• If the scanned input is '(', push it into stack<br>
14+
• If the scanned input is ')' ,pop the stack and the output it until '(' comes.<br>
15+
• Repeat above steps. Continue Pop and output from stack until it becomes empty.
16+
17+
##### It makes the code more efficient and even reduces the time complexity.
18+
### Constraints
19+
"""
20+
Input:
21+
Enter infix expression: A+C*(B^D-E)^(G+H*K)-K
22+
Output:
23+
Postfix expression: ACBD^E-GHK*+^*+K-
24+
25+
Time Complexity : O(n)
26+
Space Complexity: Θ(n)
27+
"""

Basic-Scripts/SnakeGame.py

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/usr/bin/env python
2+
# coding: utf-8
3+
4+
# In[ ]:
5+
6+
7+
import pygame,sys
8+
import time
9+
import random
10+
11+
pygame.init()
12+
13+
white = (255,255,255)
14+
black = (100,0,0)
15+
red = (255,0,0)
16+
window_width = 800
17+
window_height = 600
18+
19+
gameDisplay = pygame.display.set_mode((window_width,window_height))
20+
pygame.display.set_caption('slither')
21+
22+
clock = pygame.time.Clock()
23+
FPS = 5
24+
blockSize = 20
25+
noPixel = 0
26+
'''
27+
sizeGrd = window_width // blockSize
28+
row = 0
29+
col = 0
30+
for nextline in range(sizeGrd):
31+
'''
32+
def myquit():
33+
''' Self explanatory '''
34+
pygame.quit()
35+
sys.exit(0)
36+
37+
font = pygame.font.SysFont(None, 25, bold=True)
38+
def drawGrid():
39+
sizeGrd = window_width // blockSize
40+
def snake(blockSize, snakelist):
41+
#x = 250 - (segment_width + segment_margin) * i
42+
for size in snakelist:
43+
pygame.draw.rect(gameDisplay, black,[size[0]+5,size[1],blockSize,blockSize],2)
44+
45+
def message_to_screen(msg, color):
46+
screen_text = font.render(msg, True, color)
47+
gameDisplay.blit(screen_text, [window_width/2, window_height/2])
48+
49+
def gameLoop():
50+
gameExit = False
51+
gameOver = False
52+
53+
lead_x = window_width/2
54+
lead_y = window_height/2
55+
56+
change_pixels_of_x = 0
57+
change_pixels_of_y = 0
58+
59+
snakelist = []
60+
snakeLength = 1
61+
62+
randomAppleX = round(random.randrange(0, window_width-blockSize)/10.0)*10.0
63+
randomAppleY = round(random.randrange(0, window_height-blockSize)/10.0)*10.0
64+
65+
while not gameExit:
66+
67+
while gameOver == True:
68+
gameDisplay.fill(white)
69+
message_to_screen("Game over, press c to play again or Q to quit", red)
70+
pygame.display.update()
71+
72+
for event in pygame.event.get():
73+
if event.type == pygame.QUIT:
74+
gameOver = False
75+
gameExit = True
76+
77+
if event.type == pygame.KEYDOWN:
78+
if event.key == pygame.K_q:
79+
gameExit = True
80+
gameOver = False
81+
if event.key == pygame.K_c:
82+
gameLoop()
83+
84+
for event in pygame.event.get():
85+
if event.type == pygame.QUIT:
86+
gameExit = True
87+
88+
if event.type == pygame.KEYDOWN:
89+
if event.key == pygame.K_ESCAPE:
90+
myquit()
91+
leftArrow = event.key == pygame.K_LEFT
92+
rightArrow = event.key == pygame.K_RIGHT
93+
upArrow = event.key == pygame.K_UP
94+
downArrow = event.key == pygame.K_DOWN
95+
96+
if leftArrow:
97+
change_pixels_of_x = -blockSize
98+
change_pixels_of_y = noPixel
99+
elif rightArrow:
100+
change_pixels_of_x = blockSize
101+
change_pixels_of_y = noPixel
102+
elif upArrow:
103+
change_pixels_of_y = -blockSize
104+
change_pixels_of_x = noPixel
105+
elif downArrow:
106+
change_pixels_of_y = blockSize
107+
change_pixels_of_x = noPixel
108+
109+
if lead_x >= window_width or lead_x < 0 or lead_y >= window_height or lead_y < 0:
110+
gameOver = True
111+
112+
lead_x += change_pixels_of_x
113+
lead_y += change_pixels_of_y
114+
115+
gameDisplay.fill(white)
116+
117+
AppleThickness = 20
118+
119+
print([int(randomAppleX),int(randomAppleY),AppleThickness,AppleThickness])
120+
pygame.draw.rect(gameDisplay, red, [randomAppleX,randomAppleY,AppleThickness,AppleThickness])
121+
122+
allspriteslist = []
123+
allspriteslist.append(lead_x)
124+
allspriteslist.append(lead_y)
125+
snakelist.append(allspriteslist)
126+
127+
if len(snakelist) > snakeLength:
128+
del snakelist[0]
129+
130+
for eachSegment in snakelist [:-1]:
131+
if eachSegment == allspriteslist:
132+
gameOver = True
133+
134+
snake(blockSize, snakelist)
135+
136+
pygame.display.update()
137+
138+
if lead_x >= randomAppleX and lead_x <= randomAppleX + AppleThickness:
139+
if lead_y >= randomAppleY and lead_y <= randomAppleY + AppleThickness:
140+
randomAppleX = round(random.randrange(0, window_width-blockSize)/10.0)*10.0
141+
randomAppleY = round(random.randrange(0, window_height-blockSize)/10.0)*10.0
142+
snakeLength += 1
143+
144+
145+
clock.tick(FPS)
146+
147+
pygame.quit()
148+
quit()
149+
gameLoop()
150+

CODE_OF_CONDUCT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Importing Libraries
2+
import cv2
3+
import numpy as np
4+
from skimage import io
5+
6+
# Class Defination
7+
class Cartoon:
8+
def __init__(self):
9+
img = io.imread("images/sunset.jpg")
10+
# 1) Edges Image
11+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
12+
gray = cv2.medianBlur(gray, 5)
13+
edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 9, 7)
14+
15+
# 2) Color Image
16+
color = cv2.bilateralFilter(img, 10, 300, 300)
17+
RGB_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
18+
19+
# 3) Cartoon Image
20+
cartoon = cv2.bitwise_and(color, color, mask=edges)
21+
cartoon_img = cv2.cvtColor(cartoon, cv2.COLOR_BGR2RGB)
22+
23+
# Re-sizeing Image
24+
resize = cv2.resize(RGB_img, (600, 450))
25+
resize2 = cv2.resize(cartoon_img, (600, 450))
26+
self.resize = resize
27+
self.resize2 = resize2
28+
29+
# Displaying Image
30+
# Creating an object of class Cartoon
31+
c1 = Cartoon()
32+
c1.resize
33+
c1.resize2
34+
cv2.imshow("Original_Image", c1.resize)
35+
cv2.imshow("Cartoonified_Image", c1.resize2)
36+
cv2.waitKey(0)
37+
cv2.destroyAllWindows()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<h1>Cartoonify Image</h1>
2+
3+
The code converts your original image i.e. the image which you have given as input, to cartoonified image.<br>
4+
When you run Cartoonify.py, both the input image and output image will be displayed.<br>
5+
It can be further implemented for pencil-sketch, color-pencil-sketch, water-color image, sepia effect, oldifying, etc.
6+
7+
<h2>Results:</h2>
8+
9+
<h4>Original Image</h4>
10+
<p align="left">
11+
<img src="images/Original%20Image.PNG" width="600" height="500"/></p>
12+
13+
<h4>Cartoonified Image</h4>
14+
<p align="left">
15+
<img src="images/Cartoonified%20Image.PNG" width="600" height="500"/></p>
Loading
Loading
Loading
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Color Detection
2+
3+
This is a python script which we can use to determine the color of a part of image.
4+
5+
## Installation
6+
7+
* Use the package manager [pip](https://pip.pypa.io/en/stable/) to install Opencv.
8+
9+
```bash
10+
pip install opencv-python
11+
```
12+
* Install Numpy
13+
14+
```bash
15+
pip install numpy
16+
```
17+
* Install Pandas
18+
19+
```bash
20+
pip install pandas
21+
```
22+
23+
## How it works
24+
25+
* When the user double clicks on the image, then color of that part of image is shown in a box.
26+
27+
## How to run in CMD
28+
29+
> python color_detection.py -i <colorpic.jpg>
30+
31+
## Screenshot
32+
33+
![](../Color_Detection/color_sample.png)

0 commit comments

Comments
 (0)