Introduction to Xcode and Swift

Apple_Swift_Logo

Logo_xcodeToday, we were introduced to the programming environment of which we will be using to create our apps. Due to previously using java in processing to create our interactive piece, I feel my programming knowledge has advanced. It was important to initially understand the similarities and differences between java and swift programming languages. Using the ‘playground’ feature in Xcode, we were able to experiment with swift and see the results immediately. A main difference was the use of ‘;’ at the end of each line of code, also declaring constants and variables, and using basic conditional statements, and for loops seemed to be simpler. Here is an example:

Screen Shot 2015-02-15 at 14.58.17

Constants are declared with the let keyword and variables with the var keyword. The value of a constant cannot be changed once it is set, whereas a variable can be set to a different value in the future.

A feature that is new in Swift is optionals, which handle the absence of a value. ‘Optionals are an example of the fact that Swift is a type safe language. Swift helps you to be clear about the types of values your code can work with’ (iOS Developer Library).
? = optional values
! = unwrap values
: = is of type

Here is an example of creating a class using swift, in this example I have created the blueprint for a person, consisting of variables: their name and age and optional gender.

Screen Shot 2015-02-15 at 15.21.42

It was important to learn the basic switch from java to swift and I think this workshop was beneficial. Understanding these basic features are essential in order for me to progress my xcode and swift knowledge further in order to create a successful ios application. From this, in each workshop we will be developing mini apps, in order to progress knowledge and advance our skills in order to be able to successfully make the app for Salisbury Cathedral.

iOS Developer Library, 2015. The Swift Programming Language [online]. Available from: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-ID309 [Accessed 5 February 2015].

Advertisements

Improvements – Mirroring Piece

An improvement I received when testing my piece was to mirror the video capture. It came to my awareness that at the moment it captures the video the wrong way round, so when users put up their right hand, on the screen their hand goes up on the left. This makes the interaction quite confusing which could deter people from interacting with my piece. I have found this improvement quite difficult to do and have had quite a bit of difficulty with the programming. Through reading online forums, I managed to gain some help from others who had similar problems. Here are the steps I went through and the various problems I encountered:

Screen Shot 2015-01-13 at 12.58.02To start with I managed to get my piece to mirror by adding this code:
Screen Shot 2015-01-12 at 12.23.50

This got the video capture to mirror but meant the brightness thresholding wouldn’t work correctly and so the video capture was in colour. This meant that obstructing the falling objects didn’t work as well as it was harder to detect the threshold on colours. Also, I felt that the black and white capture looked better as the coloured shapes stand out more.

As I was having difficulty, I decided to start my piece from scratch as originally I had used the brightness thresholding example. I felt that starting from scratch would help me to solve the problems easier as I would be writing out all the code step by step, in a way that I understood. I managed to resolve the problem by adding in videoMirror and a for loop to go through each of the video pixels. Then, instead of using the normal formula of x+y*width to access the array of pixels, I set it equal to [(width-(x+1))+y*width].

Screen Shot 2015-01-13 at 10.28.16

This flipped the video capture and the brightness thresholding still worked correctly. However, this caused the an error with the falling shapes. Now, when you put up your right hand to obstruct the shapes, it obstructs them up the left hand side. This meant I had to flip the shapes too, which I managed to do by changing the x co-ordinate of the shapes to (width-1-x).

Screen Shot 2015-01-13 at 13.04.08

Carrying out user testing with my family and friends was very useful and now my piece is mirrored correctly. This shows that I have followed an iterative design process as I created my piece, got feedback and then made improvements. I have learnt a lot more by carrying out this improvement, especially in relation to the advantages and disadvantages of hacking/programming. I feel that now I have programmed from scratch, my knowledge and understanding has advanced and I’m more confident with resolving any further problems I may encounter.  Next, I will go on to explore some other suggested improvements, such as adding more of each shape and altering speeds. Then, I will go on to test my piece in the studio room, capturing full body movement using a white screen.

Processing Forum, 2014. Mirroring a Webcam in a Sketch. Processing [online]. Available from: http://forum.processing.org/one/topic/mirroring-a-webcam-in-a-sketch.html [Accessed12 Jan].

Processing Forum, 2014. Flip the Video Capture on the X-axis.Processing [online]. Available from: http://forum.processing.org/one/topic/flip-the-video-capture-on-the-x-axis.html [Accessed11 Jan].

Processing Experiments – Popping Bubbles

When working on my piece, I decided to experiment with an idea that when the user hits the balls they disappear. I edited my existing code so that instead of ascending when they hit a black pixel, they now disappear. If I was to develop this idea, I would create it so they pop like a bubble, rather than just immediately disappearing. Here is a video clip showing the experiment:

I think this works well and with further improvements could look better. However, after talking to my audience, and showing them my progress so far they preferred my initial idea of being able to obstruct falling objects. I will continue to work on my idea, developing the programming for it.

Pseudo Code For Idea

Here is the basic pseudo code for my idea:

Screen Shot 2014-12-05 at 12.15.14This has allowed me to briefly see the steps I need to follow in order produce my interactive piece and the processing knowledge I need. I need to ensure that I have sufficient knowledge in video capturing, object orientated programming, motion thresholding and conditional statements. Next, I will go on to further explore the concept of surrealism, of which my piece will relate to, as well as developing my processing knowledge.

Pseudo-code

Pseudo-code is a informal notation resembling a simplified programming language. Pseudo-code can be applied to all programming languages and is a helpful step in order to process various ideas into code. It is a simply written, step by step structure, to help write the actual programming language. Using pseudo-code can be beneficial as it allows us to plan work more thoroughly rather than jumping straight into programming. However, it is a extra step that sometimes isn’t always necessary for advanced programers. Here is a simple example of both a flowchart and pseudo-code in order to make a cup of tea:

cup-of-tea1

The steps are simple for anyone to understand and from this can be transferred into the required programming language. For my project, I am using Java within Processing and as I am not advanced in this language I could use pseudo-code in order to structure my idea and help me to transform it into code. I feel by doing this it would be beneficial, as it will help me to fully plan my idea and enable me to clearly see whether it is realistic to achieve by the deadline. By carrying out efficient planning, it can then result in a more efficient development process and means that fewer problems arise during coding. Next, I will go on to further plan out my idea and write out a basic pseudo-code for it.