Skip to content

Instantly share code, notes, and snippets.

View arpit-omprakash's full-sized avatar

Arpit Omprakash arpit-omprakash

View GitHub Profile
@arpit-omprakash
arpit-omprakash / gist:486eff6fa0e5909c60223314ec598797
Created December 8, 2020 06:05
Snake.py (pygame implementation)
import pygame as pg
import random
from time import sleep
# For FPS
clock = pg.time.Clock()
# Colors
red = pg.Color(255, 0, 0)
green = pg.Color(0, 255, 0)
black = pg.Color(0, 0, 0)
@arpit-omprakash
arpit-omprakash / animation.py
Created June 1, 2020 15:21
A simple script demonstrating animation in pygame
import pygame, sys
from pygame.locals import *
pygame.init()
FPS = 60
fpsClock = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((400,300), 0, 32)
pygame.display.set_caption('Animation')
@arpit-omprakash
arpit-omprakash / image_animation.py
Created June 1, 2020 15:20
A simple moving ball
import pygame, sys
from pygame.locals import *
pygame.init()
FPS = 60
fpsClock = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((400,300), 0, 32)
pygame.display.set_caption('Animation')
@arpit-omprakash
arpit-omprakash / pygame_fonts.py
Created June 1, 2020 15:19
A simple Hello World program in Pygame to introduce users to fonts and text
import pygame, sys
from pygame.locals import *
pygame.init()
DISPLAYSURF = pygame.display.set_mode((400,300))
pygame.display.set_caption('Hello World')
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
BLUE = (0, 0, 128)
import pygame, sys
from pygame.locals import *
pygame.init()
# setup the window
DISPLAYSURF = pygame.display.set_mode((00, 400), 0, 32)
pygame.display.set_caption('Drawing')
# setup colors
╔════════════════════╦═══════════════════════════════════════════════════════════════════════╗
║ Attribute Name ║ Description ║
╠════════════════════╬═══════════════════════════════════════════════════════════════════════╣
║ myRect.left ║ The int value of the X-coordinate of the left side of the rectangle ║
║ myRect.right ║ The int value of the X-coordinate of the right side of the rectangle. ║
║ myRect.top ║ The int value of the Y-coordinate of the top side of the rectangle. ║
║ myRect.bottom ║ The int value of the Y-coordinate of the bottom side. ║
║ myRect.centerx ║ The int value of the X-coordinate of the center of the rectangle. ║
║ myRect.centery ║ The int value of the Y-coordinate of the center of the rectangle. ║
@arpit-omprakash
arpit-omprakash / pygame_intro.py
Last active May 15, 2020 03:58
Hello World program in pygame
import pygame, sys
from pygame.locals import *
pygame.init()
DISPLAYSURF = pygame.display.set_mode((400, 300))
pygame.display.set_caption('Hello World!')
while True: # main game loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
#!/usr/bin/env python3
# imports
import argparse
import random
from math import log
def main(range_end):
guesses_made = 0
# number of guesses is 1 + the log of the range
#!/usr/bin/env python3
import random
guesses_made = 0
name = input('Hello! What is your name?\n')
number = random.randint(1,20)
print('Well, {}, I am thinking of a number between 1 and 20'.format(name))
@arpit-omprakash
arpit-omprakash / drift.py
Created March 1, 2020 07:09
Simulating genetic drift using python
import random
import sys
generations = 5000
pop_size = 1000
gamete_no = 1000
pop = []
n = len(sys.argv)
if n == 2: