Skip to content

Instantly share code, notes, and snippets.

View wkta's full-sized avatar

moonbak wkta

View GitHub Profile
@wkta
wkta / day_11.py
Created March 13, 2014 21:43
#MonthOfCode day 11 - ascii
import os
from time import sleep
import random
DISP_WIDTH = 96
DISP_HEIGHT = 32
NB_MAX_CHAR_GEN=64
class MovingChar():
def __init__(self , display):
@wkta
wkta / day_12.py
Last active August 29, 2015 13:57
#MonthOfCode day 12 - pixel
import pygame
from time import sleep
import random
import sys
BLACK = ( 0, 0, 0)
NB_PIX_BATCH = 64
DISP_WIDTH = 640
DISP_HEIGHT = 480
REFR_RATE = 0.008
@wkta
wkta / day_14.py
Created March 18, 2014 08:00
#MonthOfCode day 14 - loop
from __future__ import print_function
import sys
def printMultiples(k, sup_bound):
map(print, [ k*i for i in xrange(1,1+(sup_bound/k) ) ] )
if (len(sys.argv)<3 ):
print("this program prints multiples of k up to a cernain bound")
print("usage: python "+sys.argv[0]+" k sup_bound")
sys.exit(1)
@wkta
wkta / day_13.py
Created March 22, 2014 11:21
#MonthOfCode day 13 - sound
import pygame
from time import sleep
#replace this by some cool sound effect & music !
SFX = 'alrighty.wav'
MUSIC = '4sequence.mp3'
# init pygame ; load n play a sound effect
pygame.init()
soundObj = pygame.mixer.Sound('alrighty.wav')
@wkta
wkta / day_15.py
Created March 22, 2014 11:22
#MonthOfCode day 15 - yellow
import pygame
from pygame.locals import *
import sys
from time import sleep
# init. pygame libr; create the screen and diplays a help message in the console
pygame.init()
DISPLAYSURF = pygame.display.set_mode((640, 480))
src_color = pygame.Color('antiquewhite3')
targ_color = pygame.Color('yellow')
@wkta
wkta / day_16.py
Created March 22, 2014 11:23
#MonthOfCode day 16 - square
import random
import pygame
from pygame.locals import *
def generateRandColorObj():
return pygame.Color(
random.randint(0,255), random.randint(0,255), random.randint(0,255), 255 )
def addSquare(start_pos, end_pos, color ):
square_list.append( (start_pos, end_pos, color))
@wkta
wkta / day_17.py
Created March 22, 2014 17:37
#MonthOfCode day 17 - random
import time
current_milli_time = lambda: int(round(time.time() * 1000))
# we use the Factory Design Pattern, RngCreator is the abstract class
class RngCreator(object):
def createRng(self):
raise NotImplementedError("Please Implement this method")
def inputParams(self, p_dict):
raise NotImplementedError("Please Implement this method")
@wkta
wkta / day_18.py
Created March 28, 2014 12:19
#MonthOfCode day 18 - search
import random
# This code implements the so-called "descent method" which is a kind of NEIGHBOR SEARCH METHOD
# often used in optimization.
# I apply it to the simple problem of finding the minimum value in a huge random matrix
# I count the nb of values tested to show how this kind of search is efficient in practice
# I initiale a random matrix and compute the global min. value on-the-fly to know
# if the descent method eventually succeeds in finding it.
N = 128 ; M = 128
MAX_VAL = 255
@wkta
wkta / day_19.py
Created March 28, 2014 15:54
#MonthOfCode day 19 - tree
# this program draws a random TREE-LIKE shape, inspired by L-Systems
import pygame
from time import sleep
import random
import sys
DISP_WIDTH = 640
DISP_HEIGHT = 480
def randPeriod():
return random.choice((1, 16, 64) ) #determines the slope with wich the emerging branch grows
@wkta
wkta / day_20.py
Created March 30, 2014 10:54
#MonthOfCode day 20 - play
import random
import pygame
from pygame.locals import *
SCREEN_W = 640
SCREEN_H = 480
def refeshFunction():
DISPLAYSURF.fill( pygame.Color('antiquewhite3') )
# draws the paddle
rect_rep_paddle =\