                                                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() {

class ViewController: UIViewController {
    let INTERVAL: Double = 1.0 / 45
    let BYTES_PER_PIXEL = 4
    let IMAGE_SCALE: CGFloat  = 1
    
    var uiImageView: UIImageView?
    var slider: UISlider?
    
    var imageWidth = 0
    var imageHeight = 0
    var touching = false

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // define bitmap info for plasma
        imageWidth = Int(round(screenBounds.width * CGFloat(imageScale)))
        imageHeight = Int(round(screenBounds.height * CGFloat(imageScale)))
        // pixels565 = [UInt16](count: Int(imageWidth * imageHeight), repeatedValue: 0);
        pixelsARGB = [UInt32](repeating: 0, count: Int(imageWidth * imageHeight));
        maxRadius = Int(screenBounds.width / 3)
        
        // create UIImageView
        uiImageView = UIImageView(frame: screenBounds)
        //uiImageView?.contentMode = .ScaleAspectFill
        view.addSubview(uiImageView!)
        
        // palette button
        let button = UIButton(type: UIButtonType.contactAdd);
        button.frame = CGRect(x: 10, y: 20, width: 50, height: 50)
        //button.backgroundColor = UIColor.gray
        button.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside)
        view.addSubview(button)
        
        // zoom stepper
        let stepper = UIStepper(frame: CGRect(x: screenBounds.width - 120, y: 30, width: 100, height: 50))
        stepper.wraps = false
        stepper.autorepeat = false
        stepper.minimumValue = 0
        stepper.maximumValue = 0.5
        stepper.stepValue = 0.1
        stepper.value = 1 - Double(imageScale)
        stepper.addTarget(self, action: #selector(stepperValueChanged), for: .valueChanged)
        view.addSubview(stepper)
        
        // speed slider
        let sliderWidth = screenBounds.width * 0.9
        let sliderX = (screenBounds.width - sliderWidth) * 0.5
        let slider = UISlider(frame: CGRect(x: sliderX, y: screenBounds.height - 50, width: sliderWidth, height: 20))
        slider.minimumValue = -2
        slider.maximumValue = 2
        slider.isContinuous = true
        slider.value = -speed
        slider.addTarget(self, action: #selector(sliderValueDidChange), for: .valueChanged)
        view.addSubview(slider)
        
        // schedule repeated render
        Timer.scheduledTimer(timeInterval: INTERVAL, target: self,
