<commit_before>//
//  CellView.swift
//  GameOfLifeScreenSaver
//
//  Created by <NAME> on 10/27/20.
//

import Cocoa

class CellView: NSView {
    
    private static let waveOrigin = CGPoint(x: 0.0, y: 0.0)
    
    private static let deadColor = NSColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0).cgColor
    private static let aliveColor = NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0).cgColor

    private let stepPeriod: CGFloat
    
    init(stepPeriod: CGFloat) {
        self.stepPeriod = stepPeriod
        super.init(frame: .zero)
        self.layer?.backgroundColor = CellView.deadColor
    }
    
    func update(cell: GameOfLifeCellState) {
        let cellStateDelay = cell.isAlive ? 0.0 : (self.stepPeriod * 0.15)
        
        let distanceFromWaveOrigin = CellView.waveOrigin.distance(to: self.frame.origin)
        let maxDistanceFromWaveOrigin = CellView.waveOrigin.distance(to: self.superview!.frame.size.point)
        let waveDistanceDelayProportion = distanceFromWaveOrigin / maxDistanceFromWaveOrigin
        
        let delay = cellStateDelay + (self.stepPeriod * 0.55 * waveDistanceDelayProportion)
        let animationStartTime = DispatchTime.now() + Double(delay)
        
        DispatchQueue.main.asyncAfter(deadline: animationStartTime) {
            let layer = self.layer!
            let newColor = cell.isAlive ? CellView.aliveColor : CellView.deadColor
            
            let animation = CABasicAnimation(keyPath: "backgroundColor")
            animation.fromValue = layer.backgroundColor
            animation.toValue = newColor
            animation.duration = Double(self.stepPeriod * 0.30)

            layer.add(animation, forKey: nil)
            
            CATransaction.begin()
            CATransaction.setDisableActions(true)
            layer.backgroundColor = newColor<commit_msg>Move the wave origin around<commit_after>//
//  CellView.swift
//  GameOfLifeScreenSaver
//
//  Created by <NAME> on 10/27/20.
//

import Cocoa

class CellView: NSView {
    
    private static let deadColor = NSColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0).cgColor
    private static let aliveColor = NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0).cgColor

    private let stepPeriod: CGFloat
    
    init(stepPeriod: CGFloat) {
        self.stepPeriod = stepPeriod
        super.init(frame: .zero)
        self.layer?.backgroundColor = CellView.deadColor
    }
    
    func update(cell: GameOfLifeCellState) {
        let waveOrigin = CGPoint(
            x: self.superview!.frame.width / 2.0,
            y: self.superview!.frame.height / 2.0
        )

        let distanceFromWaveOrigin = waveOrigin.distance(to: self.frame.origin)
        let maxDistanceFromWaveOrigin = waveOrigin.distance(to: self.superview!.frame.size.point)
        let waveDistanceDelayProportion = distanceFromWaveOrigin / maxDistanceFromWaveOrigin
        
        let cellStateDelay = cell.isAlive ? 0.0 : (self.stepPeriod * 0.15)
        let delay = cellStateDelay + (self.stepPeriod * 0.55 * waveDistanceDelayProportion)
        let animationStartTime = DispatchTime.now() + Double(delay)
        
        DispatchQueue.main.asyncAfter(deadline: animationStartTime) {
            let layer = self.layer!
            let newColor = cell.isAlive ? CellView.aliveColor : CellView.deadColor
            
            let animation = CABasicAnimation(keyPath: "backgroundColor")
            animation.fromValue = layer.backgroundColor
            animation.toValue = newColor
            animation.duration = Double(self.stepPeriod * 0.25)

            layer.add(animation, forKey: nil)
            
            CATransaction.begin()
            CATransaction.setDisableActions(true)
            layer.backgroundColor = newColor
{'fraction_non_alphanumeric': 0.09498540726983284, 'fraction_numerical': 0.019633855133987795, 'mean_word_length': 2.4335154826958107, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6611683', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1086, 'n_words': 236}