我要绘制在一个清晰和消除锯齿方式可变频率和可变幅度的移动正弦波。这怎么可能?绘制移动正弦波抗锯齿
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. Font.createFont +抗锯齿
- 4. 强制抗锯齿EMF
- 5. 抗锯齿算法
- 6. 识别常见的周期性波形(正方形,正弦波,锯齿波,......)
- 7. 绘制正弦波,WPF
- 8. 强制Java2D子像素抗锯齿
- 9. 关于Skia的抗锯齿
- 10. 呈现抗锯齿螺旋
- 11. ggplot导出的抗锯齿
- 12. CAShapeLayer禁用抗锯齿
- 13. UIImage ScaleToFit禁用抗锯齿?
- 14. 抗锯齿的JWindow(形状)
- 15. Imagemagick抗锯齿文字
- 16. CALayer的抗锯齿图纸
- 17. 正弦波绘图
- 18. 在SurfaceView上绘制缩放的位图 - 无抗锯齿
- 19. 用于绘制粗抗锯齿线的算法
- 20. QPainter :: rotate禁用绘制文本的抗锯齿
- 21. 以快速方式绘制抗锯齿线
- 22. 如何绘制锯齿线?
- 23. 用同步滤波器抗锯齿图像的算法
- 24. 绘制正弦波的集合
- 25. Android java:绘制正弦波形图
- 26. 在iOS上绘制正弦波
- 27. 使用opencv绘制正弦波
- 28. 生成正弦波,方波,三角波,锯齿波的音频使用Android的AudioTrack类
- 29. AS3 Tweener抗锯齿和alpha问题
- 30. 如何使用抗锯齿输出GraphicsRow?
它不移动正弦波 – AndrewK 2015-05-07 22:29:46