我要繪製在一個清晰和消除鋸齒方式可變頻率和可變幅度的移動正弦波。這怎麼可能?繪製移動正弦波抗鋸齒
6
A
回答
11
好,我實現正弦波入的UIView的drawRect方法如下:
float x=75;
float yc=50;
float w=0;
while (w<=rect.frame.size.width) {
CGPathMoveToPoint(path, nil, w,y/2);
CGPathAddQuadCurveToPoint(path, nil, w+x/4, -yc,w+ x/2, y/2);
CGPathMoveToPoint(path, nil, w+x/2,y/2);
CGPathAddQuadCurveToPoint(path, nil, w+3*x/4, y+yc, w+x, y/2);
CGContextAddPath(context, path);
CGContextDrawPath(context, kCGPathStroke);
w+=x;
}
在此,x是每個正弦波的寬度,而y是所述框架的高度。這將繪製數量的正弦波以適應整個UIViewFrame。它會產生清脆的正弦波,並且yc是控制手柄。嘗試一下,你可能會喜歡它。
如果寬度ie。 x與框架的寬度相似,則會產生單個正弦波。完整的正弦波的
數=(幀的寬度)/(「x」的每個正弦波的寬度)
1
製成的GeneratorOfOne的版本更完整,並迅速版本。這一個也用選定的顏色填充波浪的底部:
class WaveView: UIView {
private var maskPath: UIBezierPath!
@IBInspectable var fillColor: UIColor = UIColor.blueColor()
@IBInspectable var cycles: CGFloat = 7
override func drawRect(rect: CGRect) {
var w: CGFloat = 0 // Starting position
let width = rect.width
let y: CGFloat = rect.height
let yc: CGFloat = rect.height/2
let x = width/cycles
let context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, UIColor.greenColor().CGColor);
let path = CGPathCreateMutable();
CGPathMoveToPoint(path, nil, 0, 0)
while (w<=rect.width) {
CGPathMoveToPoint(path, nil, w,y/2);
CGPathAddQuadCurveToPoint(path, nil, w+x/4, -yc, (w+x/2), y/2);
CGPathMoveToPoint(path, nil, w+x/2,y/2);
CGPathAddQuadCurveToPoint(path, nil, w+3*x/4, y+yc, w+x, y/2);
w+=x;
}
CGPathAddLineToPoint(path, nil, rect.width, rect.height)
CGPathAddLineToPoint(path, nil, 0, rect.height)
CGPathAddLineToPoint(path, nil, 0, y/2);
CGPathCloseSubpath(path)
maskPath = UIBezierPath(CGPath: path)
maskPath.lineCapStyle = CGLineCap.Square
maskPath.lineJoinStyle = CGLineJoin.Miter
CGContextAddPath(context, path);
CGContextSetFillColorWithColor(context, fillColor.CGColor)
CGContextFillPath(context)
}
}
相關問題
- 1. 繪製emf抗鋸齒
- 2. Pyglet OpenGL繪圖抗鋸齒
- 3. 在CCRenderTexture中繪製抗鋸齒圓圈
- 4. Font.createFont +抗鋸齒
- 5. 強制抗鋸齒EMF
- 6. 抗鋸齒上CAShapeLayers
- 7. iOS - CAShapeLayer抗鋸齒?
- 8. 抗鋸齒與GL_TRIANGLE_FAN
- 9. 抗鋸齒算法
- 10. 識別常見的週期性波形(正方形,正弦波,鋸齒波,......)
- 11. 繪製正弦波,WPF
- 12. 強制Java2D子像素抗鋸齒
- 13. 關於Skia的抗鋸齒
- 14. ILNumerics中的抗鋸齒
- 15. 抗鋸齒的JWindow(形狀)
- 16. Cocos2d HTML5關閉抗鋸齒
- 17. 抗鋸齒像素渲染
- 18. CAShapeLayer禁用抗鋸齒
- 19. CALayer的抗鋸齒圖紙
- 20. Imagemagick抗鋸齒文字
- 21. ggplot導出的抗鋸齒
- 22. 呈現抗鋸齒螺旋
- 23. 在SurfaceView上繪製縮放的位圖 - 無抗鋸齒
- 24. QPainter :: rotate禁用繪製文本的抗鋸齒
- 25. Delphi - Graphics32,繪製抗鋸齒圓角矩形
- 26. 以快速方式繪製抗鋸齒線
- 27. 用於繪製粗抗鋸齒線的算法
- 28. 繪製抗鋸齒的形狀和在Java中
- 29. 使用着色器繪製抗鋸齒圓圈
- 30. 繪製抗鋸齒文本圖像像圖形軟件
它不移動正弦波 – AndrewK 2015-05-07 22:29:46