Skip to main content

SWIFT PLAYGROUND / QR Code Generator

This is a quick test to make QR Code Generator that will run on Swift Playground app on iPad. I sourced some of the code online from few forums.

The resulting QR Image on "Playground Preview" is stretched, however it seems to still work when I am using iPhone camera to scan it. Ideally the Playground Preview should not be stretched like this and keeping the QR image square. Saving the QR Code itself is another mystery.



The whole code is actually very simple, taking advantage of Core Image CIFilter "CIQRCodeGenerator" as below:

import Foundation
import UIKit
import PlaygroundSupport

let data = "https://youtube.com/c/jimmygunawan".data(using: .utf8)
let filter = CIFilter(name: "CIQRCodeGenerator", withInputParameters: ["inputMessage" : data, "inputCorrectionLevel":"L"])
let ciimage = filter!.outputImage! let transform = CGAffineTransform(scaleX: 20.0, y: 20.0)

let image = ciimage.transformed(by: transform)
let img = UIImage(ciImage: image)

PlaygroundPage.current.liveView = UIImageView(image: img)


SOURCE:
https://medium.com/@MedvedevTheDev/generating-basic-qr-codes-in-swift-63d7222aa011
http://www.jensmeder.de/git/2017/05/18/generating-qr-codes-with-core-image.html

Comments

Popular posts from this blog

WOLFRAM / Making Text With Rainbow Color

Continuing with my Wolfram Mathematica Trial Experience... I watched and went through some more Mathematica introduction videos, read lots of Mathematica documentation and also going through the Wolfram Lab Online again a few times. There are some major learning curves and Mathematica is a lot different from normal programming language. Sometimes there is a lot of interesting "shortcuts", say like: FindFaces[] , WordCloud[] . Sometimes I got a little confused on how one can do iterations. Normally FOR LOOP concept is introduced early, but in Wolfram, because everything is EXPRESSIONS and ENTITY (like OBJECTS), sometimes it gets quite quirky. Mind you I am still in the first impression and having to look at many tutorials. Lots of NEAT EXAMPLES from documentation, but sometimes I got lost. I found Wolfram to be really awesome with LIST and generating list. It's almost too easy when it works visually. I cannot explain them with my own words yet, but there are ...

PYTHON PROCESSING / It only really begins ...

Back into Processing again, with Python! While Daniel Shiffman is continuously inspiring us with his CODING TRAIN series on YouTube, using Processing with Java and Javascript language, I decided to free my mind and trying to really do something using Processing and Python language. Installing Python language version on Processing 3 is easy enough, just first download the latest Processing and install the Python language mode via Add Mode button. Other link that might help: https://github.com/jdf/processing.py http://py.processing.org/tutorials/ BLANK MODE As soon as Processing Python Mode, opens up and running I am presented with a  blank environment. Suddenly I recalled my journey in learning programming from zero until now... With Python, outside Processing, commonly people will be introduced to Python IDE or IDLE environment. Something that looks like Console Window or Command Prompt, where we type single liners command. Python Command Line and IDE normally ha...

SONICPI / Ruby, Python, MIDI and OSC

I have a big curiosity on how we can use OSC or MIDI to send message from one app to another app, potentially to generate (realtime) synth sound, visualization, and animation. This is especially a fun area and environment when we wanted to use CODE for CREATIVITY. Sonic Pi (by Sam Aaron) is one app I really love to use when dealing with Synth and Sonic generator. I remember using ChucK in the past by Ge Wang, ChucK is also cool, but Sonic Pi is a lot more friendly. http://sonic-pi.net Sonic Pi multi-threaded ness and LIVE LOOP is really something new for me. But Sam made it easy enough so that we could generate "listener" very easily. MAKING SOUND WITH CODE There are plenty of ways we can "trigger" Sonic Pi to generate sound. Obviously we can just use the built in RUBY language inside Sonic Pi app. Fairly simple and fun language to use and you can generate some noise in no time! Sonic Pi RUBY language documentation is really in depth and a full on progr...