CMSC B110: Introduction to Computing

Fall 2012 - Section 2

CMSC B110: Introduction to Computing

Fall 2012 - Section 2

What is Computing?

The Internet

Movies and Games

Digital Photography

Search for planets that can support life

Deciphering the Human Genome

http://biology.kenyon.edu/courses/biol114/Chap08/Chapter_08a.html

Art

Protobytes, Ira Greenburg

Computer science is no more about computers than astronomy is about telescopes.

Edsger Dijkstra

What can be programmed?

Google's Self-Driving Car

http://spectrum.ieee.org/automaton/robotics/artificial-intelligence/how-google-self-driving-car-works/

Robotics in the Laboratory

Photo: Matthew Cahn

Robotics in the Laboratory

Our Goal

How do you program?

What is a computer program?

A collection of human and machine readable statements that can be translated to instructions executable by a computing device.

A text file. For example...

# Mouse orbiter
from Processing import *

size(500, 300)
background(255)

# Orbit angle state variable
angle = 0

def draw(o, e):
    global angle
    background(255)
    fill(0, 0, 255)
    ...

Computing Platform

Calico

Python

Using Python Interactively

Python Resources

Calico Processing

Getting Started with Calico Processing

A first program

Getting Started with Calico Processing

A first program

Anatomy of a Function

Opening a new Processing Window

from Processing import *

window( width, height )

Drawing Primitives in Processing

line( x1, y1, x2, y2 )

triangle( x1, y1, x2, y2, x3, y3 )

quad( x1, y1, x2, y2, x3, y3, x4, y4 )

rect( x, y, width, height )

ellipse( x, y, width, height )

Coordinate System

(0, 0) +X +Y
coords.py

Colors

Colors can be composed of four elements:

  1. Red
  2. Green
  3. Blue
  4. Alpha (Transparency)

...all are assigned values in the range [0..255]

Colors

http://www.jswidget.com/lab/canvas-based-color-picker.html

Why 255?

Byte from 8 Bits - Click bit to flip

Shape Formatting

Shape fill color, line color and line thickness can be set.

  1. Fill Color
  2. Line Color
  3. Line Thickness

Shape attributes are set *before* a shape is painted, as if the paintbrush properties are selected.

Fill/Stroke Color

Use the fill() command to set the fill color of all shapes.

Use the stroke() command to set the stroke color of all shapes.

from Processing import *
window(200, 200)
background(255)

fill(255, 0, 0)
stroke(0, 255, 0)
strokeWeight(5)
rect(50, 50, 100, 100)

fill() Command Options

fill(red, green, blue, alpha)

fill(red, green, blue)

fill(gray, alpha)

fill(gray)

noFill()

stroke() Command Options

stroke(red, green, blue, alpha)

stroke(red, green, blue)

stroke(gray, alpha)

stroke(gray)

noStroke()

background() Command Options

Fills the entire sketch with the specified color

background(red, green, blue, alpha)

background(red, green, blue)

background(gray, alpha)

background(gray)

ellipseMode() and rectMode()

Defines how the first two arguments of rect() and ellipse() are interpreted.

from Processing import *
window(225, 125)
background(255)

# Default setting
rectMode(CORNER)
fill(255, 0, 0)
rect(50, 50, 50, 50)

rectMode(CENTER)
fill(0, 255, 0)
rect(50, 50, 50, 50)
from Processing import *
window(225, 125)
background(255)

ellipseMode(CORNER)
fill(255, 0, 0)
ellipse(150, 50, 50, 50)

# Default setting
ellipseMode(CENTER)
fill(0, 255, 0)
ellipse(150, 50, 50, 50)

Dropbox

We will use Dropbox for assignment submissions

Sign up at http://www.dropbox.com

/

#