#!/usr/bin/python import pygame import random import math MIN_DIST = 5.0 SCRN_SCALE = 1 DISP_SIZE = (640, 480) SCRN_SIZE = (DISP_SIZE[0] * SCRN_SCALE, DISP_SIZE[1] * SCRN_SCALE) def get_rand_col(): #return (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) return (random.randint(100, 150), random.randint(150, 200), random.randint(200, 255)) def norm(x, y): h = math.hypot(x, y) if h!=0: return (x/h, y/h, h) return (0.0, 0.0, 1.0) screen = pygame.display.set_mode(SCRN_SIZE, pygame.DOUBLEBUF) disp = pygame.surface.Surface(DISP_SIZE) disp.fill((255,255,255)) fade = pygame.surface.Surface(DISP_SIZE) fade.fill((20,20,20)) line_list = [] current_line=[] mouse_down = False last_point = (999999,999999) squiggliness = 1.0 done = False while not done: disp.blit(fade, (0,0), None, pygame.BLEND_ADD) #disp.fill((255,255,255)) mouse_pos = pygame.mouse.get_pos() mouse_pos = (mouse_pos[0] / SCRN_SCALE, mouse_pos[1] / SCRN_SCALE) if mouse_down: h = math.hypot(mouse_pos[0] - last_point[0], mouse_pos[1] - last_point[1]) if h > MIN_DIST: current_line.append(mouse_pos) last_point = mouse_pos for line in line_list: from_point = None for point in line: if from_point == None: from_point = (int(random.gauss(point[0], squiggliness)), int(random.gauss(point[1], squiggliness))) else: to_point = (int(random.gauss(point[0], squiggliness)), int(random.gauss(point[1], squiggliness))) pygame.draw.line(disp, (0,0,0), from_point, to_point, 2) from_point = to_point pygame.transform.scale(disp, SCRN_SIZE, screen) pygame.display.flip() for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: mouse_down = True current_line = [] line_list.append(current_line) if event.button == 4: squiggliness += 0.1 if event.button == 5: squiggliness -= 0.1 if event.type == pygame.MOUSEBUTTONUP: if event.button == 1: mouse_down = False last_point = (999999,999999) if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: done = True if event.key == pygame.K_SPACE: line_list = [] if event.type == pygame.QUIT: done = True