CS 541 Lecture -*- Outline -*- * stream design example main focus is conceptual modeling. could put coding problem in a class... Streams (from Rich Wagner's thesis...) Motivation is animation, want to move an icon from point S to point E in 4 steps. Put the code for moving it from current spot to a point in a block: moveIcon do this by ((S ~> E) size: 4) do: moveIcon Want (S ~> E) size: 4 to construct a stream of points, evenly spaced. How to solve this... simpler problem, one dimensional point movement, the type IntegerStream can this be combined to yield a stream of points? yes, slap them together so that the x or y-projection of the Point stream is an integer stream (might want to do this first) So need class IntegerSteam. What do the abstract values look like? Abstract values are ordered sequences of values: , where I[x] = F[x] truncated F[1] = start + (1/2) F[x] = F[x-1] + delta delta = ((end - start) /(size - 1)) provided that start ~= end and size > 1; otherwise, if start = end, then for each x from 1 to size, I[x] = start. How to represent them? note that delta = deltaw + (deltan / deltad), so when delta is written as an improper fraction, deltaw is the whole part, deltan is the numerator, and deltad is the denominator also w + (n/deltad) = F[x], hence I[x] = w. So use the following instance variables: start - an Integer, the start value end - an Integer, the ending value size - an Integer, the number of values between start and end deltaw - an Integer, whose value is delta truncated deltad - an Integer, whose value is 2*(size-1) deltan - an Integer, whose value is deltad * (delta - deltaw) x - an Integer, that counts from 1 to size, and represents the subscripts of F[X] and I[X] above w - an Integer, that represents the whole part of the improper fraction representation of F[X], so 1 <= w <= size n - an Integer, that represents the numerator of the improper fraction representation of F[X], so 0 <= n <= deltad start: s end: e size: n "Requires: if s~=e, then n >=2; if s=e, then n>=1." "initialize instance variables" next "Requires: self is not at its end." "Return the next element of self, advancing the position." ... rest "Return a List that contains all the integers of the receiver that haven't yet been yielded. Leaves self at its end." computeDeltas "Compute values of deltaw, deltad, deltan" size ^size atEnd "Return true iff self's position is such that no more elements remain to be yielded." atStart "Return true iff self is positioned at its start." contents "Return a List that contains all the integers of the receiver, regardless of its current position. Leaves self at its end." first "Return the first element of self" last "Return the last element of self" length "Return the distance between the first and last elements of self, in the sense of geometry" ============== Now design a PointStream type, so that points can move: rep is combination of 2 integer streams. Will need points...