## Step 1 - Locate the correct file

The file that you are expected to modify is called ai_template.py. Its code is locate here:

This file imports the bare-bone AI class from ZDengine.py.
1. You must rename the class to follow the following pattern: zd_yourname_ainame This is the name that will be shown on the leaderboard.
2. You must rename the file using the exact same pattern, but also adding a .py file extension.
3. You must specify which division your entry belongs to.
You may create any number of AIs, but each must be uniquely named. In the end, you will submit your best entry.

## The Gist

In this challenge, you write an AI for the game Zombie Dice. The AI has to make a simple, binary decision: cash in the brains or roll again. You are provided with all of the code to play the game and run tournaments. The only thing that you may submit is an AI that inherits the based AI class. One of its method takes in a few parameters, and return a True/False decision.

## Overview

 Abstract art by Bruce Gray.
In this workshop, you will use a very simple graphics library to create images. There are plenty of "better" libraries do this kind of thing, but today is about creating with a simple set of tools.

A whole lot more can be done with this library, but these are starting points. You will know that you are getting what you should out of the workshop if:
• You can use the manual to do new things with the library.
• You can turn an idea into a script that reflects perfectly what you had in mind.

## Background

Here are some information that you may find useful for this workshop:

## What we'll do

In this workshop, we will:
1. Discuss about coordinates in computer graphics and try a guessing game to test your "eyeballing" skills.
3. Create windows and graphic object in a Python console to learn about syntax and the logic of object-based programming.
4. Attempt to create the closest possible knockoff of the Martian Crocodile artwork to test your ability to translate ideas into precise instructions.
5. Give you a taste of what can be done after this workshop.

Try to make your own version of my Martian Crocodile artwork. First, try to make it as similar as the original. This will challenge you to translate into code exactly what you have in mind. Once that you are done, feel free to make it more interesting. Hint: I used a window that was 1000 pixels wide and 200 pixels high.

 Can you make a copy as "good" as the original?

To do this, and before you even start typing on the keyboard, decompose the image into elements. Write down possible coordinates for them. Next, find out from the documentation what object would be useful, and how to create these elements. Finally, start working on your crocodile script.

## Going beyond

We have barely scratched the surface today. If you already know how to program or want to learn independently, try the challenges in Hacking One Circle. You should also browse the other scripts in the downloaded folder, you will find some interesting Python scripts there.

Have a look at this Google image search and try to figure out how you could create art using lines, boxes, ovals, circles and polygons.

## Can you generate Mondrian compositions look-alikes?

In particular, I'd like you to have a close look at this painting from Piet Mondrian.

 Composition with Yellow Red Black Blue Grey

You don't need to be a programmer to think like a computer scientist. On a piece of paper, imagine how you would create a program to generate random Mondrian Composition look-alikes. Make sure to share with me, or an helper, about your solution. We can help you to turn it into a functioning Python Script.

## Friday, May 15, 2015

### Background

Usually, working with computer graphics means that you have access to about 16 millions different colors. What makes this amazing is that you can select any of these colors by mixing three basic colours:

• How much Red? From 0 to 255
• How much Green? From 0 to 255
• How much Blue? From 0 to 255
This is called RGB encoding. Here is an online tool to find out what RGB code matches any given color.

 The RGB palette

### Why 16 millions?

Here are some fun facts about colors. There are three colour channel: Red, Green and Blue. Each channel uses 1 byte of memory (which contains 8 bits). This is just enough to store a number between 0 and 255 (or $$2^8$$ ). We'll denote colours as follow: $$color = (Red, Green, Blue)$$

For example, pure red is defined as such: $$red = (255, 0 , 0)$$ Pure white is a combination of all colours at the same time: $$white = (255, 255 , 255)$$ And Black is when there are no colours in any of the colour channel: $$black = (0, 0, 0)$$

To create colours in Python using the graphics library, use the following function:

my_red = color_rgb(255, 0, 0)

So, for each possible of value of Red (256 different values), there are 256 possible values for Green. That is a big enough number, 65,536 colors in fact. And for each of these 65,536 colors, there is 256 possible values of Blue. In other terms: $$n_{colours} = 256 \times 256 \times 256 = 256^3 = 16,777,216$$

Your eyes and brain can't even distinguish 16 million colours. You eye actually can distinguish only about 7 millions.

### Learn by doing

The best way to get a grasp of RGB, which can be tricky, is to play with a colour picker. Click on colours that you like and look at the corresponding RGB triples of values. What is the RGB value for yellow?

Interesting artwork often selects colours that harmonize well. Here is a tool to generate RGB code of harmonious colours from a single RGB code.

### Python trick: A random color

Random colours can be fun to use because you never know what you'll get each time that you run your script. Here is a code snippet to generate a random color.

from random import randint
from graphics import *

my_color = color_rgb(randint(0,255), randint(0,255), randint(0,255))

## Sunday, May 10, 2015

### PaA: Hacking a circle

This hackable file is the most simple file using the graphics library. It creates a window, then adds a circle on it. It looks like this:

Understanding the onecircle.py script
First, let's ake a look a the file:

# Import everything from Graphics
from graphics import *

# Build a window
win = GraphWin('Test 1', 600, 600)
win.setBackground('white')

# Draw one circle
poly = Circle( Point( 300, 300 ), 200 )
poly.setFill( 'red' )
poly.draw(win)

mytext = Text( Point(450, 520), 'by Random Bytes' )
mytext.setFill('red')
mytext.setSize( 30 )
mytext.draw(win)

# Wait to stop
win.getMouse()
win.close()


### Step 1 - Import useful code from other files

Python is such a useful language because it is possible to borrow code from other file,to do pretty much anything that you can think about. In this file, we need to tell our script to import all objects and function from the file graphics.py . Without this import statement, it wouldn't not be possible to create a window object (GraphWin), a point (Point), a circle (Circle) and some on-screen text (Text). The import code is made here of a single line:

from graphics import *


## Friday, May 8, 2015

### Coordinate system for 2D computer graphics

Computers have a peculiar way to orient the axis of their coordinate system. It looks like this:

### Basics

This means that the Upper-Left corner of an image or a window is (0,0).  In this type of programming, the unit along the axes is the pixel. When you create images, try using common image formats such as 800X480, or go for a square image of size 600X600.

With the graphics.py library, you can create a 800 pixels wide by 480 pixels high image using:

 mywindow = GraphWin( "Window Name", 800, 600 )


# Computer programming as art

## Overview

In this workshop, you will learn to use the Python language and a simple graphic library to create artwork. Whether you want to draw something in particular, or explore the use of randomness, is up to you!

## When, where?

June 13th 2015, 13:00 to 15:00. Teaching Lab 2, Goldberg Building, 6050 University Avenue. The workshop is now full, but you may let me know if you want to be contacted later with information for the next session.

## Who will benefit from this workshop?

This is mainly intended for youth who want to try something else with mathematics. I don't want to set an age range, but to get the most out of the workshop, you should be capable of doing the following:
• Create folders and operate the basics of software interface (Open, save, use menus).
• Reading skills good enough for short, technical instructions.
• Type on a keyboard well enough that it won't slow you down.
• Understand how cartesian coordinates work (video)
• Understand the concept of variable as values. For example: if a=15, then a-20=-5
• Can focus on work for 90 minutes.
We will do a short activity on cartesian coordinates before we hit the computers to make sure that everyone is comfortable.
Parents: This is meant to be fun. However, it is important to respect these guidelines to ensure that your kid/teen gets something valuable out of the workshop. I strongly encourage parent participation so you are part of the learning process.