This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
DISP_WIDTH = 640 | |
DISP_HEIGHT = 480 | |
def refreshScreen(): | |
window.fill( pygame.Color('black') ) | |
pygame.display.flip() | |
# init. pygame libr; create the screen and diplays a help message in the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this code is awesome, you will see it everywhere! | |
import sys | |
import random | |
import os | |
alphabet = [chr(i) for i in range(ord('a'),ord('z') + 1) ] | |
def genRandomName(): | |
name_length = random.randint(2,8) | |
lchar = list() | |
for i in xrange(name_length): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
print "Testing your knowledge on regular expressions" | |
partterns = [ | |
"a{4,}b", "Y.*g", "ro..c..ter", "[a,m,k]{5,8}" ] | |
for pat in partterns: | |
print "Try to type a string that matches the REGULAR EXPRESSION",pat | |
success = False | |
while True: | |
user_str = raw_input() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import time | |
def detPrecision( candidate, model): | |
chars_cand = list( candidate) | |
chars_model = list(model) | |
while( len(chars_cand)<len(chars_model) ): | |
chars_cand.append(' ') | |
while( len(chars_cand)>len(chars_model) ): | |
chars_cand.pop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This shows how we can define and use a META-function in python | |
def produce_incrementor( step): | |
''' it produces various increment functions''' | |
return lambda u:u+step | |
print "three by three" | |
increm_three = produce_incrementor(3) | |
k=0 | |
while k < 34: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
from time import sleep | |
import random | |
import math | |
DISP_WIDTH = 640 | |
DISP_HEIGHT = 480 | |
DIST_THRESHOLD = 256 | |
class MovingPix(): | |
def __init__(self , x,y): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
import math | |
from time import sleep | |
SCREEN_W = 640 | |
SCREEN_H = 480 | |
class MovingPix(): | |
def __init__(self , x,y ): | |
self.x = x | |
self.y = y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 =\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |