0

我制作了一个 iOS 程序,允许用户用手指在屏幕上画一条线。我使用了 touchesBegan、touchesMoved 和 touchesEnded 方法,同时创建了一个 CGContext 并以这种方式画线。我希望线条看起来像是斜切到屏幕上,几乎就像是雕刻出来的一样。这怎么可能?

4

1 回答 1

0

You can achieve a simple bevel by stroking your lines three times:

  1. first, with a color brighter than the background at points p(x-1, y-1) relative to the actual line
  2. then, your line color at the actual line position, points p(x, y)
  3. then, brighter than the line color, but darker than the background at p(x+1, y+1)

You can think of this as a light shining onto your lines from above and to the left, making the lower coordinates brighter, passing over the bevel and having a little shadow cast on the higher coordinates.

Once you get the hang of thinking through the pseudo-3D geometry this way, you can create prettier bevels, including details inside the line. Those will take more strokes.

于 2012-04-05T00:03:29.780 回答