绘制移动正弦波抗锯齿 [英] Drawing a moving sine wave anti-aliased

查看:100
本文介绍了绘制移动正弦波抗锯齿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以一种清晰和抗锯齿的方式绘制一个具有可变频率和可变幅度的移动正弦波。

I want to draw a moving sine wave with variable frequency and variable amplitude in a crisp and anti-aliased way. How is this possible?

推荐答案

好吧,我在UIView drawrect方法中实现了正弦波,如下所示:

Well, I implemented sine wave into the UIView drawrect method as follows :

 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作为控制句柄。试试你可能喜欢它。

Here x would be the width of each sine wave, while y is the height of the frame. This would draw number of sine waves to fit in the whole UIViewFrame. It would produce crisp looking sine wave and yc being control handle. Try it you might like it.

如果宽度ie。 x类似于帧的宽度,则将产生单个正弦波。

If the width ie. x is similar to the width of the frame then a single sine wave will be produced.

完整正弦波数=(帧宽度)/('x'每个正弦波的宽度)

Number of complete sine wave = (width of frame) / ('x' width of each sine wave)

这篇关于绘制移动正弦波抗锯齿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆