cs106a – Assignment #3 – Task #1

The complete specification of assignment #3 can be found as part of the stream at iTunes.

Set up the bricks

Before you start playing the game, you have to set up the various pieces. Thus, it probably makes sense to implement the run method as two method calls: one that sets up the game and one that plays it. An important part of the setup consists of creating the rows of bricks at the top of the game, which look like this:

cs106a – assignment #3 – task #1

The number, dimensions, and spacing of the bricks are specified using named constants in the starter file, as is the distance from the top of the window to the first line of bricks. The only value you need to compute is the x coordinate of the first column, which should be chosen so that the bricks are centered in the window, with the leftover space divided equally on the left and right sides. The color of the bricks remain constant for two rows and run in the following rainbow-like sequence: RED, ORANGE, YELLOW, GREEN, CYAN.

Continue reading “cs106a – Assignment #3 – Task #1”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Assignment #3 Extra Task #3

Please note, this blog entry is from a previous course. You might want to check out the current one.

Improve the performance of panning. To do this, you need to try to understand where the CPU cycles are going when the graph is drawn. Is it our inefficient runProgram:usingVariableValues: method? Or is it all the Core Graphics calls we are making each time? Is there a simple way to reduce calls to both of these things in our drawRect:? Or is the performance issue something else entirely? If you are very brave, you can try to figure out how to use the Time Profiler (hold down Run in Xcode and pick Profile, then choose the Time Profiler from the dialog that appears). That’s the way to really know where the time’s going.

Time Profiler shows that runProgram: takes about of 80% of the processing time when pinching or panning. To know when we are actually pinching or panning we add a new private property which will be set as long as a gesture has not finished:
Continue reading “Assignment #3 Extra Task #3”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Assignment #3 Extra Task #2

Please note, this blog entry is from a previous course. You might want to check out the current one.

If you do Extra Credit #1, you’ll notice that some functions (like sin(x)) look so much nicer using the “line to” strategy (at least when zoomed in appropriately). Try dragging a UISwitch into your user-interface which lets the user switch back and forth between “dot mode” and “line to” mode drawing.

Add a new property to our graph view protocol:

@property (nonatomic) BOOL drawDots; // YES: draw dots; NO: draw lines

Continue reading “Assignment #3 Extra Task #2”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Assignment #3 Extra Task #1

Please note, this blog entry is from a previous course. You might want to check out the current one.

In the Hints section it is noted that you are allowed to draw your graph by drawing a line from each point to the next point. Clearly if your function were discontinuous (e.g. 1/x) or if you had zoomed out so far that drawing a line between points would be jumping over a lot of changes in y, this would give misleading results to the user. The best thing would probably be to simply draw dots at each coordinate you calculate. This would not help much with the zoomed-out-too-far problem, but it would certainly be more accurate on discontinuous functions. It is up to you to figure out how to draw a dot at a point with Core Graphics.

For the mandatory tasks we connected the dots of every calculated point. Now we must draws, where there is no such drawing function in iOS, thus we draw small rectangles:

CGContextFillRect(context, 
    CGRectMake([self xPointFromPixel:xPixel inRect:area] - 0.5, 
    [self yPointFromValue:y inRect:area originAtPoint:origin scale:scale] - 0.5, 1.0 , 1.0)
);
FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Assignment #3 Finished Tasks

Please note, this blog entry is from a previous course. You might want to check out the current one.

The complete code of the mandatory tasks of assignment #3 can be found at github.

Addendum Task #7

The previously shown code for the pinch: method would zoom using the origin of the axis as center point thus moving a graph out of view if the currently shown area is not close to the origin. To provide a proper zoom function where the zoom happens centered to the touching point the origin has to adjusted as well as the scale:
Continue reading “Assignment #3 Finished Tasks”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Assignment #3 Task #8

Please note, this blog entry is from a previous course. You might want to check out the current one.

Make your Calculator work on the iPad too (in the same application, i.e., a Universal application) by having two storyboards, one for the iPhone (described above) and one for the iPad that uses a UISplitViewController to present your old Calculator MVC on the left of the screen (or in a popover) and your new graphing MVC on the right.

We start by changing Devices in in the Targets Summary tab from iPhone to Universal, rename the existing storyboard to iPhone.Storyboard and adjust the settings for the iPhone Deplayment Info accordingly.

Create a new storyboard using File -> New -> File… -> User Interface -> iPad and adjust the settings for the iPad Deplayment Info to the new storyboard.
Continue reading “Assignment #3 Task #8”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail