<commit_before>//
//  ShowStepMatchViewController.swift
//  Yep
//
//  Created by nixzhu on 15/8/20.
//  Copyright (c) 2015年 Catch Inc. All rights reserved.
//

import UIKit

class ShowStepMatchViewController: ShowStepViewController {

    @IBOutlet weak var camera: UIImageView!
    @IBOutlet weak var pen: UIImageView!
    @IBOutlet weak var book: UIImageView!
    @IBOutlet weak var controller: UIImageView!
    @IBOutlet weak var keyboard: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)

        animateKeyboard()
    }

    private func animateKeyboard() {

        let keyboardPath = UIBezierPath()

        let offset: UInt32 = 20
        let beginPoint = CGPoint(x: keyboard.center.x - CGFloat(arc4random() % offset), y: keyboard.center.y + CGFloat(arc4random() % offset) * 0.5 * (arc4random() % 2 == 0 ? -1 : 1))
        let endPoint = CGPoint(x: keyboard.center.x + CGFloat(arc4random() % offset), y: keyboard.center.y + CGFloat(arc4random() % offset) * 0.5 * (arc4random() % 2 == 0 ? -1 : 1))
        keyboardPath.moveToPoint(beginPoint)
        keyboardPath.addLineToPoint(endPoint)

        repeatAnimate(keyboard, alongWithPath: keyboardPath, duration: 4, autoreverses: true)

        repeatRotate(keyboard, fromValue: -0.1, toValue: 0.1, duration: 3)
   }

    private func repeatRotate(view: UIView, fromValue: AnyObject, toValue: AnyObject, duration: CFTimeInterval) {
        let rotate = CABasicAnimation(keyPath: "transform.rotation.z")
        rotate.fromValue = fromValue
        rotate.toValue = toValue
        rotate.duration = duration
        rotate.repeatCount = Float.infinity
        rotate.autoreverses = true
        rotate.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)

        view.layer.addAnimation(rotate, forKey: "Rotate")
    }
}
<commit_msg>refactor animate in StepMatch<commit_after>//
//  ShowStepMatchViewController.swift
//  Yep
//
//  Created by nixzhu on 15/8/20.
//  Copyright (c) 2015年 Catch Inc. All rights reserved.
//

import UIKit

class ShowStepMatchViewController: ShowStepViewController {

    @IBOutlet weak var camera: UIImageView!
    @IBOutlet weak var pen: UIImageView!
    @IBOutlet weak var book: UIImageView!
    @IBOutlet weak var controller: UIImageView!
    @IBOutlet weak var keyboard: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)

        animate(camera, offset: 10, duration: 4)
        animate(pen, offset: 5, duration: 5)
        animate(book, offset: 10, duration: 3)
        animate(controller, offset: 15, duration: 2)
        animate(keyboard, offset: 20, duration: 4)
    }

    private func animate(view: UIView, offset: UInt32, duration: CFTimeInterval) {

        let path = UIBezierPath()

        func flip() -> CGFloat {
            return arc4random() % 2 == 0 ? -1 : 1
        }

        let beginPoint = CGPoint(x: view.center.x + CGFloat(arc4random() % offset) * flip(), y: view.center.y + CGFloat(arc4random() % offset) * 0.5 * flip())
        let endPoint = CGPoint(x: view.center.x + CGFloat(arc4random() % offset) * flip(), y: view.center.y + CGFloat(arc4random() % offset) * 0.5 * flip())
        path.moveToPoint(beginPoint)
        path.addLineToPoint(endPoint)

        repeatAnimate(view, alongWithPath: path, duration: duration, autoreverses: true)

        repeatRotate(view, fromValue: -0.1, toValue: 0.1, duration: duration)
    }

//    private func animateKeyboard() {
//
//        let path = UIBezierPath()
//
//        let offset: UInt32 = 20
//        let beginPoint = CGPoint(x: keyboard.center.x - CGFloat(arc4random() % offset), y: keyboard.center.y + CGFloat(arc4random() % offset) * 0.5 * flip())
//        let endPoint = CGPoint(x: keyboard.center.x + CGFloat(arc4random() % offset), y: keyboard.center.y + CGFloat(arc4random() % offset) * 0.5 * flip())
//        path.moveToPoint(beginPoint)
//        path.addLineToPoint(endPoint)
//
//        repeatAnimate(keyboard, alongWithPath: path, duration: 4, autoreverses: true)
//
//        repeatRotate(keyboard, fromValue: -0.1, toValue: 0.1, duration: 3)
//   }

    private func repeatRotate(view: UIView, fromValue: AnyObject, toValue: AnyObject, duration: CFTimeInterval) {
        let rotate = CABasicAnimation(keyPath: "transform.rotation.z")
        rotate.fromValue = fromValue
        rotate.toValue = toValue
        rotate.duration = duration
        rotate.repeatCount = Float.infinity
        rotate.autoreverses = true
        rotate.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)

        view.layer.addAnimation(rotate, forKey: "Rotate")
    }
}

{'fraction_non_alphanumeric': 0.1167114232596571, 'fraction_numerical': 0.02003718240033051, 'mean_word_length': 3.045112781954887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4737602', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1509, 'n_words': 369}