teaching machines

CS 145 Lecture 25 – Shape Plotter

Agenda program this a Point class the problem with arrays a growable array of Points ArrayList Program This You have: A list of points/vertices of a polygon. The ability to draw lines. How do you draw the polygon? Code Point.java package prefinal; public class Point { private int x; private int y; public Point(int x, […]

CS 330 Lecture 37 – Sundries

Agenda more on hijacking a language applicative- vs. normal-order evaluation writing an if macro macros in C dangers of normal-order evaluation of expressions with side-effects list ranges list comprehensions lazy evaluation TODO http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf http://www.haskell.org/haskellwiki/Why_Haskell_matters Code macros.ss (define myif (lambda (predicate? true-expr false-expr) (cond (predicate? 1) (else 0)))) (define-syntax spiffy (syntax-rules () ((spiffy predicate? true-expr false-expr) […]

CS 145 Lecture 24 – Adding Gravity

Agenda when to create an object you have a clear picture of identity/actor you can multiple instances of set of data revisit to event-driven programming adding gravity to ball dropper canvas composition collaboration graphs in SMC law #31: try local first Code DroppingCircles.java package prefinal; import java.util.Timer; import java.util.TimerTask; import javax.swing.JFrame; public class DroppingCircles { public […]

CS 330 Lecture 36 – GIMP example, macros

Agenda program this GIMP Script-Fu floodfilling example Program this Sketch out the pseudocode for implementing a paintbucket operation in an image editor. Script-Fu template Code hackbucket.scm (define floodfill (lambda (image color x y) (let ((layer (car (gimp-image-get-active-layer image))) (fill-color (cons-array 3 ‘byte))) ; check for fill != init (floodfill-helper layer (car (cdr (gimp-drawable-get-pixel layer x […]

CS 330 Lecture 35 – Lsystem evaluation

Agenda lexical vs. dynamic scope Perl’s scope narrowing scope in Scheme with let executing user code sandboxed evaluation side-effects in Scheme Code lsystem.ss #lang racket (require racket/sandbox) (define apply-productions-once (lambda (loa substitutions) (cond ((null? loa) ‘()) (else (append (cdr (assoc (car loa) substitutions)) (apply-productions-once (cdr loa) substitutions)))))) (define apply-productions-n-times (lambda (current substitutions n) (cond ((= […]

CS 145 Homework 4 – due before Wednesday, May 9

See the PDF.

CS 145 Lecture 23 – GUIs, Non-zero Gravity

Agenda TIOBE flip Swing GUI framework a tease of inheritance event-driven programming painting dropping circles composition collaboration graphs in SMC law #31: try local first Code DroppingCircles.java package prefinal; import javax.swing.JFrame; public class DroppingCircles { public static void main(String[] args) { JFrame frame = new JFrame(“Drop Circles”); // frame.add(new JButton(“Click me!”)); // frame.add(new JLabel(“Read me!”)); frame.add(new […]

CS 330 Lecture 34 – Scope and eval

Agenda final project deadline association lists (Scheme’s hash) program this dynamic interpretation sandboxing L-systems Program This Pick one: Write a function apply-productions-once that takes as arguments a list-of-atoms and an association list. Each atom in the list is replaced by the value for which the atom is the key in the association-list. For example, (apply-productions-once […]

CS 145 Lecture 22 – Stopwatch

Agenda Paragraph.plot takes Image, not 2-D array PPMViewer lab gotchas other instances as parameters invoking object is not a parameter writing a Stopwatch Code NDeckerBurger.java package prefinal; public class NDeckerBurger { private int nDecks; private boolean hasCheese; public static final int CALORIES_PER_DECK = 211; public NDeckerBurger(int givenDeckCount) { nDecks = givenDeckCount; } public NDeckerBurger(int givenDeckCount, […]

CS 330 Homework 5 – due before Tuesday, May 8

See the PDF.

1 201 202 203 204 205 232