1 void DrawContents( TGrafPort* thePort ) 2 { 3 TEllipse normalEllipse( TGEllipse ( TGRect( 10, 10, 20, 20 ) ), 4 TGrafBundle( TRGBColor( 0,0,0 ) ) ); 5 6 TCachedGraphic fastEllipse( normalEllipse ); 7 8 init i; 9 TGPoint offset( 5, 5 ); 10 for( i = 0; i < 50, i++ ) 11 { 12 normalEllipse.Draw( port ); 13 normalEllipse.TranslateObjectBy( offset ); 14 } 15 16 for( i = 0; i < 50, i++ ) 17 { 18 fastEllipse.Draw( port ); 19 fastEllipse.TranslateObjectBy( offset ); 20 } 21 22 TGPoint scale( 1.05, 1.05 ); 23 fastEllipse.ScaleBy( scale ); 24 fastEllipse.Draw( port ); 25 }
Line 6: Created a cached ellipse.
Lines 8 through 14: Draw 50 ellipses without caching.
Lines 16 through 20: Draw 50 ellipses with caching. The first one is slow because the cache gets initialized the first time.
Lines 22 through 24: Scale the cached ellipse. The cache is discarded and must be regenerated. This is slow.