Thursday, May 7, 2015

June 13th - Invitation

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.



What you will do

In a lab hosted by Dalhousie's Faculty of Computer Science, you will learn the basics of programming so that you may:
  • Create drawing surfaces.
  • Draw simple shapes (lines, circles, boxes, etc).
  • Read input from the mouse and use these clicks in your artwork.
  • Define colors using the RGB encoding.

I want to give it a try! (FULL for June 13th)

Please email Christian Blouin ( c b l o u i n @ d a l . c a ). Tell me what is your (or your child's) name, age and whether you (your child) ever programmed before. The number of people in the workshop will be kept small enough to ensure that everyone can get help.
People with experience with Python, and willing to lend a hand, are welcome.

Examples

These examples just gives an idea of what can be done with a few lines of code. You may find it more inspiring to start with one of these examples and "hack" it until it gives a neat result. You may as well start from scratch.


bubbles
What is this shape coming out of the shadows?

What can you do with 3 black circles? (Simple)

# Import everything from Graphics
from graphics import *
from random import randint

# Create a window
win = GraphWin('Mickey Mouse', 600, 600)

# Draw a head
head = Circle(Point(300, 400), 200)
head.setFill('black')
head.draw(win)

# Draw the ears
ears_y = 160
ears_sep = 150

# Left ear
l_ear = Circle(Point(300 - ears_sep, ears_y), 100)
l_ear.setFill('black')
l_ear.draw(win)

# right ear
r_ear = Circle(Point(300 + ears_sep, ears_y), 100)
r_ear.setFill('black')
r_ear.draw(win)

# Wait to stop
win.getMouse()
win.close()
  
This example show how, with only three circles, you can draw the outline of something familiar. How far can you take this to look like the real thing?

bubbles
This what you get when you leave it all to chance!

Abstract stained-glass (Intermediate)

# Import everything from Graphics
from graphics import *
from random import randint

# Return a random point on the surface
def RandomPoint():
 return Point( randint(5,595) , randint(5,595) )

# Return a random color
def RandomColor():
 return color_rgb( randint(0,255) , \\
                   randint(0, 255) , \\
                   randint(0, 255) )


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

# repeat something 40 times
for t in range(40):
 # Random triangle
 poly = Rectangle( RandomPoint(), RandomPoint() )
 poly.setFill( RandomColor() )
 poly.draw(win)

# Wait to stop
win.getMouse()
win.close()
  
This example shows how 40 triangles generated randomly look like. It uses a structure called a loop, and a special function to draw values that look like they are drawn by chance.

bubbles
A pattern like this is called recursive.

Make Bubble Lace (Advanced)

# Import everything from Graphics
from graphics import *
from random import randint


def Replicant(x,y,height, radius):
 # Master circle
 c = Circle(Point(x,y), radius)

 # find an interesting color
 relx = (x/600.)*255
 color = color_rgb(255-relx,randint(0,255),relx)
 c.setFill(color)

 c.draw(win)

 if height > 0:
  height -= 1
  Replicant(x-(radius/2),y,height,radius/2)
  Replicant(x+(radius/2),y,height,radius/2)


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

# Make a circle
Replicant(300,300,6,290)

# Wait to stop
win.getMouse()
win.close()
  
This is an example that is not for the faint-hearted. Everytime that you run this Python script, you get a different color scheme. Coming up with this can be tricky, but experimenting with this script gives interesting results: hack away!


For a solid challenge, you may want to try to write a script that makes a new Mondrian painting on demand. 



bubbles

Here is a source of inspiration, where do you want to go?


No comments:

Post a Comment