MS Paint Tracing Game

1. Randomly generate a curve (upgrade to image)

2. User draws over curve

3. Grade similarity based on pixel intensity/area bounded by each curve

Import statements

import numpy as np import random from PIL import Image import keyboard

Pixel size of square drawing area

drawSize = 500 curveLength = 1000

Score

point = 0 img = Image.fromarray([0,0]) time = curveLength

class GameCurve: # This class will handle the generation of the curve which will be traced def init(d): gPixels = np.zeros((d, d))

def move(d, x, y): if d==0: if (gPixels[x][y+1]==1 or y==0): move(np.random.choice([0,1,2,3]),x,y) else: y+=1 elif d==1: if gPixels[x+1][y]==1 or x==drawSize-1: move(np.random.choice([0,1,2,3]),x,y) else: x+=1 elif d==2: if gPixels[x][y-1]==1 or y==drawSize-1: move(np.random.choice([0,1,2,3]),x,y) else: y-=1 else: if gPixels[x-1][y]==1 or x==0: move(np.random.choice([0,1,2,3]),x,y) else: x-=1 return x,y

def createCurve(): x = random.randint(0,drawSize) y = random.randint(0,drawSize) for p in range(curveLength): # [0,1,2,3] is [up, right, down, left] direction = np.random.choice([0,1,2,3]) x,y = move(direction, x, y) gPixels[x][y]=1;

def showCurve(): global img img = Image.fromarray(gPixels, 1) img.show()

class UserCurve: # This class will handle the reading of the user's drawing. uPixels = np.zeros((drawSize, drawSize))

def move(): # x,y from mouse coordinates global time while(time > 0): # Increment x,y and change uPixels value to 1 time-=1

def scoreCurves(a, b): # Compares either pixel intensity in each region or region bounded by curve global point for i in range(drawSize): for j in range(drawSize): if a.gPixels[i][j] == b.uPixels[i][j]: point += 1 # increases point value by 1 else : distance = 1
while (distance <= 5): for k in range(i-distance, i+distance): for l in range(j-distance, j+distance): if(a.gPixels[i][j] == b.uPixels[k][l]): point += 1 - .2*distance distance += 1 # points will also be awarded partial points for how close the user curve is to game curve # these points will be inversely proportional to the distance of the user curve to the game curve # in the future the pixels will not be monochromatic # so there will also be points awarded for how well the color of the pixel matches

##################################### MAIN

environment = GameCurve(drawSize) environment.createCurve() environment.showCurve() print("Hello, World!")

Share this project:

Updates