×

Day 6

Friday May 06, 2016
Category: Creative Pact 2016

Another simple test today. A button. Are buttons in iOS really this bad? Is there no UIControlAction that deals with touch releases being both inside and outside of a button? Odd.

Screenshot of software.

//
//  WorkSpace.swift
//  DAY6
//
//  Created by Adam Tindale on 2016-05-06.
//  Copyright © 2016 Adam Tindale. All rights reserved.
//

import UIKit

class WorkSpace: CanvasController {

    let trigger = UIButton(type:UIButtonType.System)
    var flocking = UIWebView()

    override func setup() {
        // loads flocking.js in home.html
        flocking.mediaPlaybackRequiresUserAction = false
        let url = NSBundle.mainBundle().URLForResource("home", withExtension: "html")
        let request = NSURLRequest(URL: url!)
        flocking.loadRequest(request)
        
        trigger.frame = CGRectMake(0, 0, 100, 30)
        trigger.center = CGPoint(canvas.center)
        trigger.setTitle("Press Me", forState: .Normal)
        canvas.add(trigger)
        
        trigger.addTarget(self, action: "triggerFlock", forControlEvents: .TouchDown)
        trigger.addTarget(self, action: "triggerFlockOff", forControlEvents: .TouchUpInside)
    }

    func triggerFlock(){
        self.flocking.stringByEvaluatingJavaScriptFromString("synth.set('thing.mul.gate', 1);")
    }
    
    func triggerFlockOff(){
        self.flocking.stringByEvaluatingJavaScriptFromString("synth.set('thing.mul.gate', 0);")
    }

}

View this code on GitHub

<html>
    <head>
        <style>
            *{border:0;margin:0;}
            #wave{position:fixed;top:0;left:0;width:100%;height:100%;background-color:blue;}
            </style>
    </head>
    <body>        
        <script src="flocking-all.min.js"></script>
        <script>
            var synth = flock.synth({
                synthDef:
                    {
                        id: "thing",
                        ugen: "flock.ugen.whiteNoise",
                        mul: {
                            ugen: "flock.ugen.env.simpleASR",
                            start: 0.0,
                            attack: 0.01,
                            sustain: 0.2,
                            release: 0.1,
                            gate: 0.0
                        }
                    }
                });
                synth.play();
            </script>
    </body>
</html>

View this code on GitHub


←   newer :: older   →