Tracking Apple Pencil angles and pressure with Xamarin

Rumor has it that Apple will support the Apple Pencil in the forthcoming iPad. If so, more developers will want to use the new features of UITouch — force, angle, and elevation — supported by the incredibly-precise stylus.

Basically, it’s trivial:

— Force is UITouch.Force;
— Angle is UITouch.GetAzimuthAngle(UIView); and
— Angle above horizontal is UITouch.AltitudeAngle

(The UIView objects are there, I think, to make it easier to create a custom angular transform that is more natural to the task at hand — i.e., an artist could “rotate” the page slightly to accommodate the angle with which they like to work. I think.)

Anyhow, here’s some code:


namespace UITouch0

open System
open UIKit
open Foundation
open System.Drawing
open CoreGraphics

type ContentView(color : UIColor) as this = 
   inherit UIView()
   do this.BackgroundColor <- color

   let MaxRadius = 200.0
   let MaxStrokeWidth = nfloat 10.0

   //Mutable!
   member val Circle : (CGPoint * nfloat * nfloat * nfloat ) option = None with get, set

   member this.DrawTouch (touch : UITouch) = 
      let radius = (1.0 - (float touch.AltitudeAngle) / (Math.PI / 2.0)) * MaxRadius |> nfloat
      this.Circle <- Some (touch.LocationInView(this), radius, touch.GetAzimuthAngle(this), touch.Force)
      this.SetNeedsDisplay()


   override this.Draw rect = 

      match this.Circle with
      | Some (location, radius, angle, force) ->
         let rectUL = new CGPoint(location.X - radius, location.Y - radius)
         let rectSize = new CGSize(radius * (nfloat 2.0), radius * (nfloat 2.0))
         use g = UIGraphics.GetCurrentContext()
         let strokeWidth = force * MaxStrokeWidth
         g.SetLineWidth(strokeWidth)
         let hue = angle / nfloat (Math.PI * 2.0)
         let color = UIColor.FromHSB(hue, nfloat 1.0, nfloat 1.0) 
         g.SetStrokeColor(color.CGColor)
         g.AddEllipseInRect <| new CGRect(rectUL, rectSize)
         g.MoveTo (location.X, location.Y)
         let endX = location.X + nfloat (cos(float angle)) * radius
         let endY = location.Y + nfloat (sin(float angle)) * radius
         g.AddLineToPoint (endX, endY)
         g.StrokePath()
      | None -> ignore() 

type SimpleController() = 
   inherit UIViewController()
   override this.ViewDidLoad() = 
      this.View <- new ContentView(UIColor.Blue)

   override this.TouchesBegan(touches, evt) =
     let cv = this.View :?> ContentView
       
     touches |> Seq.map (fun o -> o :?> UITouch) |> Seq.iter cv.DrawTouch

   override this.TouchesMoved(touches, evt) = 
      let cv = this.View :?> ContentView
      touches |> Seq.map (fun o -> o :?> UITouch) |> Seq.iter cv.DrawTouch
   


[<Register("AppDelegate")>]
type AppDelegate() = 
   inherit UIApplicationDelegate()
   let window = new UIWindow(UIScreen.MainScreen.Bounds)

   override this.FinishedLaunching(app, options) = 
      let viewController = new SimpleController()
      viewController.Title <- "F# Rocks"
      let navController = new UINavigationController(viewController)
      window.RootViewController <- navController
      window.MakeKeyAndVisible()
      true

   
module Main = 
   [<EntryPoint>]
   let main args = 
      UIApplication.Main(args, null, "AppDelegate")
      0

And it looks like this:

Airport Time Capsule considered harmful

The premise of the Apple ecosystem is “It just works.” It is a world of hardware and software in which you pay a premium for not having to worry about fiddling with configurations and command-line options and incompatibility.

The Airport Time Capsule is a wireless router that also contains a hard drive for backups and media sharing. Bizarrely, though, the hard drive it contains is not accessible to OS X’s Drive Utility program, so a run-of-the-mill filesystem error can cause the disk to be inaccessible. It’s the antithesis of “It Just Works.” It’s “It Just Will Not Work.”

Don’t buy an Airport Time Capsule.

Experiment in Auto-Generated UML as a Documentation Tool

I wrote a program to automatically generate class diagrams, filtered by coupling. Here is the result for CoreBluetooth in iOS:

 

Screenshot 2014-12-20 08.33.14

 

You can see there are clusters around CBPeer, CBPeripheral, and CBCentral and that CBCharacteristic is another class with lots of references.

Obviously, huge class diagrams are more noise than signal, but if I further filtered this down to specific topics…?

I dunno’.

 

P.S. Yeah, yeah, they should be open diamonds, not filled diamonds.

 

Good Bye, Dr. Dobb’s

Today comes the shitty news that Dr. Dobb’s (…Journal of Computer Calisthenics and Orthodontia) is shutting down.

I would not have had the career I have had without DDJ: first as an inspiration, then as a competitor, and then as the last torch of technically rigorous, personally-voiced but professionally edited high-quality programming articles.

DDJ was the last of the great programming magazines and was, probably, the greatest. Only Byte could, perhaps, have an equal claim to the crown. All the rest of ours, an entire industry, envied their columnists, technical editors, and authors. Even the standouts (Microcornucopia, Programmer’s Journal, C/C++ Programmer’s Journal, Unix Review, PC Techniques, WinTech Journal, and, … hell, it’s my feed… Computer Language, Software Development, and Game Developer) could only occasionally match their quality.

Perhaps what I admired most about Dobb’s was that it never wavered from being a programming magazine. In the early 90s, I decreed that Computer Language would never again refer to our profession as “programming,” it would only be referred to as “software development.” We published articles about management, about architecture and design, we boasted (boasted) of how little source code we published (because we talked about “the real issues”). And while I think there was a valid point to be made, the truth is that programming — the infinitely challenging alchemy of turning sparks traveling through blocks of sand into computation and information  — is what drew me to the profession, why I will code when I retire, and why I would have a computer under the floorboards if programming were illegal. Dr. Dobb’s understood, and celebrated, that mysterious joy. Perhaps that is why it out-lasted all the rest.

Now, it seems like, if our industry has a face, it’s the face of an arrogant Silicon Valley douchebag who knows everything about monetization, socialization, and micro-localization and nothing about algorithms, memory models, and programming languages. Dr. Dobb’s wasn’t a magazine for venture capitalists or “Digital Prophet”s or “Brand-Story Architect“s. It was a magazine for hard-core coders, people who could appreciate the trade-offs in the design of a macro preprocessor, get an “ah-hah!” moment from reading an assembly language listing for a chip they didn’t know, or  grasp the theme of an implementation discussed over a year of columns.

It will be missed.

For Immediate Release…

FOR IMMEDIATE RELEASE:

NEANY Inc. to Exhibit Unmanned Solutions at AUVSI’s Unmanned Systems North America 2013

~ Arrow UAV, Ground Control Station, and Unmanned Surface Vehicle will be on display~

Hollywood, MD – August 07, 2013 (myPressManager.com) —

NEANY Inc., an industry leader in providing time-sensitive tactical solutions for a variety of missions, is a proud supporter at this year’s AUVSI’s Unmanned Systems North America 2013 in Washington, DC August 12 – 15. Conference attendees will see firsthand NEANY’s flagship UAS, the Arrow, integrated with Raytheon’s Pyros™, a UAS weapon specially designed for tactical level missions, and the aXiom™ 9000 Series, Tachyon’s state-of the-art Beyond Line-of-Site communications system. NEANY’s display will also feature its latest autonomous surface vehicle, the DragonSpy, equipped with the ARES Inc. 7.62mm Externally Powered Gun (EPG) mounted on L-3 Communications IOS’s Advanced Remote Weapon Station (ARWS). The DragonSpy is ideal for providing rapid response capabilities in maritime/littoral environments. In addition, visitors will have the opportunity to operate one of NEANY’s signature ground control stations to further experience the capabilities of these systems.

NEANY Inc. is a minority-owned, SBA 8(a)-certified research, design, test and evaluation engineering firm specializing in unmanned systems with integrated payloads supporting a variety of global missions. These missions include homeland defense and security, border and port patrol, urban mapping, counter-narcotics applications, disaster preparedness, and Intelligence, Surveillance, and Reconnaissance (ISR). In addition to unmanned systems, NEANY’s expertise includes ground control stations, systems integration, rapid prototype fabrication, pilot training, and theater deployment and logistics. NEANY continues to demonstrate unprecedented in-theater expertise that includes deployment-to-extraction logistical support as nearly 50% of NEANY’s personnel are currently forward deployed. In a period where financial resources are limited, NEANY is confident in its ability to offer cost-effective unmanned solutions capable of supporting national and international defense applications.

NEANY will have literature and personnel on hand to demonstrate and discuss our full line of available products and systems. Please take time to visit NEANY at booth #2103.

For more information on the NEANY advantage, please visit www.neanyinc.com.

For more information on AUVSI’s Unmanned Systems North America 2013, please visit

How many programmers are there?

According to Evans Data, the worldwide developer community will reach 29M by 2019. The largest growth is expected to come from China and, to a lesser extent, other developing economies.

I tend to be very skeptical about quantitative analysis of the developer community, and more-so when it comes to global analysis and forecasting, but I have no prima facie reason to criticize those numbers.

As always, I turn my attention to questions of the distribution of developer productivity. Is the distribution of talent among these 29M more like:

curves

A normal distribution would imply that the most effective team structures would be fairly democratic.

The “superprogrammer” distribution, in which an elite (but not vanishingly small) population is vastly more productive than median would imply the most effective team structure as being one structured like a surgical team (the team is structure in service to the elite member).

The “incompetent” distribution, in which a good number of exceptionally bad programmers manage to stay employed, implies that instead of seeking out “rockstars” and “ninjas,” teams should take a satisficing approach. In this world, the median professional programmer is pretty darn good, but sees a lot of unacceptable crap.

A belief in the “superprogrammer” distribution is prevalent, but the “incompetent” distribution best explains the world I’ve seen over the past 30 years.

How Many Python Programmers Are There?

Giles Thomas makes the case that the Python programming community numbers in the low millions. This seems right to me: that’s a large community, but it’s not quite at the level of the most popular programming languages. That size is supported by this chart, which has impressed me as “feeling right” when it comes to the popularity of various languages.

One point, though, is that Python has made very significant inroads in the scientific community, which I believe is a key influencer and leading indicator: the libraries that scientists build become building blocks for future work. When you look at the history of programming languages, you see that scientists and engineers were clear driving forces behind FORTRAN and although C and C++ were broadly popular, their performance benefits made them extremely popular in labs as well.

I’m not sure that the popularity of Python in labs is going to be captured by metrics that focus on the professional programming community, so if anything, I suspect that the Python community might even be a moderate amount larger than Giles suggests.

Alaska Bear Adventures

Yes, it’s worth it.

It’s a pity that the phrase “…in their natural habitat,” is so boring. The difference between this:

and this:

is the difference between a pixel and the Sistine Chapel.

Deciding to spend the money on this trip was the hardest part of our Alaska trip. My wife DALOR (Did A Lot Of Research) and there can be no guarantees about what you’ll see. Our day highlighted that: we had thin ground-fog that limited visibility to a couple hundred yards. If the air was three degrees cooler, it would have been soup and we might not have seen anything; if it had been three degrees warmer and the fog burned off, we would have seen more and my photos would be twice as sharp.

One thing we learned was that Alaska Bear Adventures has the best reputation for fair-dealing in the case of weather cancellations and so forth. But, on the ground, I don’t think anyone can guarantee “You’ll get within X yards of Y bears.” As it was, I’d say we approached this bear within 40 yards:

And the Momma and her cubs within 60 yards:

We flew to Hallo Bay, the site where the Discovery Channel’s “Great Bear Stakeout” was filmed. It’s apparently within a few bays of where Timothy Treadwell of “Grizzly Man” was killed. So, as far as locations go, this is the right place.

We visited in late May, and were a little concerned about whether the bears would have come down yet, but as you can see, we had no problem approaching two on the ground. From the plane we spotted another bear, a large male, that we could not find in the mist and not seeing a dominant male was the only “disappointment” of the day. On our return flight we flew over another bay and spotted four bears.

Our pilot and guide was Jarrod, who was great. He’s a young guy, but flies delivery and mail into the Alaskan interior in Winter, so extremely competent. He was very knowledgeable about the bears and their biology but it was his enthusiasm that really set him apart. Imagine flying and walking around with a happy Edward Norton and you’ve pretty much got the picture.

We had excellent flying weather (we had zero turbulence, which I have to think was unusual, given the mountains) and the flight-seeing was great. We flew over snow-covered volcanoes with lava-heated lakes at their peaks and steam coming from vents and spilling down their sides, over glaciers spotted with brilliant azure melt-ponds, and saw a lone wolf trotting along a driftwood-covered beach.

The plane was tight, naturally, but heated and everyone had a window (1 in the co-pilot seat, and then 2 rows of side-by-side). There’s a short but thorough safety briefing as well as a briefing on the protocol for hiking with the bears. Everyone is given a pair of hip waders and almost all the time on the ground is spent walking over mudflats, which is very easy. The hardest part is that, when viewing the bears, you kneel for long periods of time. The mud’s soft, but you get pretty stiff!

The benefit is that the bears really, really don’t seem to worry about you. With both adult bears we saw them take notice of us, and I’d say that the mother avoided us initially (she took her cubs into some brush) but once they started feeding (the mother on clams, the other on lichen) they hardly glanced at us. We were close enough to hear the scraping of their claws and not just the squabbling of the cubs, but their growling complaints that it was time to be nursed.

I honestly have no idea how long we were on the ground — a few hours anyway — and probably 80% of the time we were viewing bears.

The thing that will either work for or against you is the environment: if you’re going to be disappointed by anything but highlight-reel footage of bears battling on two legs, maybe you’ll be disappointed. If it’s enough for you to closely watch magnificent animals in a magnificent setting, it may be the highlight of your trip.

Can’t Alert Health Insurance to Possible Fraud

The other day I’m doing the bills and I get one of those healthcare “This is not a bill. It describes services.” things. You know, the sort of things that 90% of the world throws out without reviewing. But I look at it and check with my wife if she went to the dentist that day. “No! Absolutely not.” I Google the doctor and they’re in Florida, 6000 miles from where we live.

Now the worrisome thing is — this is billed to my wife, associated with my healthcare account, etc. — so there’s the hint of identity theft or fraud.

So now Tina’s been on the phone with the health insurance company for 45 minutes and they say “We can’t take any steps.” They can’t take any steps about the potential fraud we’re alerting them to. So now Tina calls the phone number I Googled up for the dentist and is talking to them, and probably they’re fine people but if they aren’t, WTF?

Review “The Wasp Factory”

The Wasp FactoryThe Wasp Factory by Iain Banks
My rating: 4 of 5 stars

Very well written. First-person account of a psychopath or maybe a sociopath living deep inside a metaphor in Scotland. Very unsettling, with a narrator who’s clearly unreliable, so one is always wondering if incidents or even entire characters are imaginary. Although certain twists were heavily foreshadowed, the denoument was still quite tense. My only qualm is that I think the final few pages spelled out too much — it would have been more haunting if the narrator didnt become suddenly insightful and deconstruct the metaphor.

Havent been so compelled to turn pages in a while.

View all my reviews

via Goodreads | Larry Obrien Kailua Kona, HIs review of The Wasp Factory.