This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController, CAAnimationDelegate { | |
let color1: CGColor = UIColor(red: 209/255, green: 107/255, blue: 165/255, alpha: 1).cgColor | |
let color2: CGColor = UIColor(red: 134/255, green: 168/255, blue: 231/255, alpha: 1).cgColor | |
let color3: CGColor = UIColor(red: 95/255, green: 251/255, blue: 241/255, alpha: 1).cgColor | |
let gradient: CAGradientLayer = CAGradientLayer() | |
var gradientColorSet: [[CGColor]] = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func animateGradient() { | |
/* | |
Assign the colors to the gradient layer that you want the animation to begin with. | |
These colors are given by the colorIndex: | |
*/ | |
gradient.colors = gradientColorSet[colorIndex] | |
//Initialize a gradient animation object and assign an animation duration. | |
let gradientAnimation = CABasicAnimation(keyPath: "colors") | |
gradientAnimation.duration = 3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let color1: CGColor = UIColor(red: 209/255, green: 107/255, blue: 165/255, alpha: 1).cgColor | |
let color2: CGColor = UIColor(red: 134/255, green: 168/255, blue: 231/255, alpha: 1).cgColor | |
let color3: CGColor = UIColor(red: 95/255, green: 251/255, blue: 241/255, alpha: 1).cgColor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func setupGradient(){ | |
// Create some color pairs for the gradient. The animator will juggle with these colors to create the gradients. | |
gradientColorSet = [ | |
[color1, color2], | |
[color2, color3], | |
[color3, color1] | |
] | |
// Assign a color pair from the gradientColorSet array to the gradient layer. (The colorIndex is 0 ATM.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func generateQRCode(from string: String) -> UIImage? { | |
let data = string.data(using: String.Encoding.ascii) | |
if let QRFilter = CIFilter(name: "CIQRCodeGenerator") { | |
QRFilter.setValue(data, forKey: "inputMessage") | |
guard let QRImage = QRFilter.outputImage else { return nil } | |
return UIImage(ciImage: QRImage) | |
} | |
return nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func generateQRCode(from string: String) -> UIImage? { | |
let data = string.data(using: String.Encoding.ascii) | |
if let QRFilter = CIFilter(name: "CIQRCodeGenerator") { | |
QRFilter.setValue(data, forKey: "inputMessage") | |
guard let QRImage = QRFilter.outputImage else { return nil } | |
let scaleUp = CGAffineTransform(scaleX: 10.0, y: 10.0) | |
let scaledQR = QRImage.transformed(by: scaleUp) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from moviepy.editor import VideoFileClip | |
from tkinter.filedialog import * | |
video_file = askopenfilename() | |
clip = VideoFileClip(video_file) | |
clip.write_gif("ouput.gif", fps=10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from moviepy.editor import VideoFileClip | |
from tkinter.filedialog import * | |
import os | |
# Accept only .mov and .mp4 files. Feel free to change. | |
accepted_files = [("Mov files", "*.mov"), ("MP4 files", "*.mp4")] | |
# Select a video which is one of the accepted file types from your machine | |
video_file = askopenfilename(filetypes=accepted_files) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Vec3D<T> { | |
let x, y, z: T | |
init(x: T, y: T, z: T) { | |
self.x = x | |
self.y = y | |
self.z = z | |
} | |
} | |
let intVector = Vec3D(x: 1, y: 2, z: 5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func change(_ number: inout Int){ | |
number = 2 | |
} | |
var number = 1 | |
change(&number) | |
print(number) | |
// Output: |