                                                userInfo: nil, repeats: true)
     }
     
-    func sliderValueDidChange(_ sender: UISlider!)
-    {
-        print("value: \(sender.value)")
+    @IBAction func buttonPressed(_ sender: UIButton!)
+    {
+        palette += 1
+        set_palette(CInt(palette))
+    }
+    
+    @IBAction func stepperValueChanged(_ sender: UIStepper!)
+    {
+        imageScale = Float(1 - sender.value)
+        imageWidth = Int(round(screenBounds.width * CGFloat(imageScale)))
+        imageHeight = Int(round(screenBounds.height * CGFloat(imageScale)))
+    }
+    
+    @IBAction func sliderValueDidChange(_ sender: UISlider!)
+    {
+        speed = Float(-sender!.value)
     }
 
     override func didReceiveMemoryWarning() {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // get screen size
        let screenBounds = UIScreen.main.bounds
        
        // define bitmap info for plasma
        imageWidth = Int(round(screenBounds.width * IMAGE_SCALE))
        imageHeight = Int(round(screenBounds.height * IMAGE_SCALE))
        // pixels565 = [UInt16](count: Int(imageWidth * imageHeight), repeatedValue: 0);
        pixelsARGB = [UInt32](repeating: 0, count: Int(imageWidth * imageHeight));
        maxRadius = imageWidth / 3
        
        // create UIImageView
        uiImageView = UIImageView(frame: screenBounds)
        //uiImageView?.contentMode = .ScaleAspectFill
        view.addSubview(uiImageView!)
        
        // speed slider
        let sliderWidth = screenBounds.width * 0.9
        let sliderX = (screenBounds.width - sliderWidth) * 0.5
        slider = UISlider(frame: CGRect(x: sliderX, y: screenBounds.height - 50, width: sliderWidth, height: 20))
        slider!.minimumValue = -2
        slider!.maximumValue = 2
        slider!.isContinuous = true
        //sliderDemo.tintColor = UIColor.redColor()
        slider!.value = -1
        //slider!.addTarget(self, action: "sliderValueDidChange:", forControlEvents: .ValueChanged)
        view.addSubview(slider!)
        
        // schedule repeated render
        Timer.scheduledTimer(timeInterval: INTERVAL, target: self,

class ViewController: UIViewController {
    let INTERVAL: Double = 1.0 / 45
    let BYTES_PER_PIXEL = 4
    
    let screenBounds = UIScreen.main.bounds
    var uiImageView: UIImageView?
    
    var palette = 0
    var speed: Float = 1.0
    var imageScale: Float = 1.0
    var imageWidth = 0
    var imageHeight = 0
    var touching = false
