Download presentation
Presentation is loading. Please wait.
Published byAlyson Heath Modified over 9 years ago
1
Recursion H-Tree and Sierpinski Triangle
3
order 1order 2order 3
4
Your job: 1.On a piece of paper, draw an order 5 H-tree 2.On a blank sheet of paper, describe how to draw the tree in the first question
5
public static void draw(int n, double x, double y, double size) { if (n == 0) return; drawH(x, y, size); // compute x- and y-coordinates of the 4 half-size H-trees double x0 = x - size/2; double x1 = x + size/2; double y0 = y - size/2; double y1 = y + size/2; // recursively draw 4 half-size H-trees of order n-1 draw(n-1, x0, y0, size/2); // lower left H-tree draw(n-1, x0, y1, size/2); // upper left H-tree draw(n-1, x1, y0, size/2); // lower right H-tree draw(n-1, x1, y1, size/2); // upper right H-tree }
6
Sierpinski Triangle
8
Order 0Order 1Order 2
9
Can you draw order 5 Sierpinski Triangle?
11
math.bu.edu/DYSYS/applets/chaos-game.html
12
Homework Form a group of no more than 3 people Come up with a story that involves conversation with at least 3 actors (sprites) Make your story about 3-4 minute long Next class: we will program your story with SNAP! snap.berkeley.edu
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.