波形图

#import "Wave.h"


static BOOL layer = YES;


@interface Wave()


@property UIBezierPath* aPath;

@property CAShapeLayer *pathLayer;




@end


static NSInteger numhorizontal;


static NSUInteger numVertical;


@implementation Wave

-(instancetype)initWithFrame:(CGRect)frame{

    

    

    if (self = [super initWithFrame:frame]) {

        self.backgroundColor = [UIColor whiteColor];

        self.width =frame.size.width;

        self.height = frame.size.height;

        _pointArray = [NSMutableArray array];

        self.aPath = [UIBezierPath bezierPath];

        self.pathLayer = [CAShapeLayer layer];

        

        

        numhorizontal = 8;

        numVertical = 6;

    }

    

    return self;

}

/**

 *  画背景

 */

-(void)drawBackground{

    float  horizontalSpacing = self.height/numhorizontal;

    float  verticalSpacing = self.width/numVertical;


    

    CGContextRef context = UIGraphicsGetCurrentContext();

    

    

    for (int a=0; a<=numhorizontal; a++) {

        if (a==numhorizontal/2) {

            CGContextBeginPath(context);

            CGContextMoveToPoint(context, 0., a*horizontalSpacing);

            CGContextAddLineToPoint(context, self.width, a*horizontalSpacing);

            //    CGContextSetRGBStrokeColor(currentContext,

            //                                   192/255.0, 192/255.0,192/255.0, 1.0);

            [[UIColor redColor] set];

            CGContextStrokePath(context);

        }else{

            CGContextBeginPath(context);

            CGContextMoveToPoint(context, 0., a*horizontalSpacing);

            CGContextAddLineToPoint(context, self.width, a*horizontalSpacing);

            //    CGContextSetRGBStrokeColor(currentContext,

            //                                   192/255.0, 192/255.0,192/255.0, 1.0);

            [[UIColor grayColor] set];

            CGContextStrokePath(context);

            

        }

        

        

        

    }

    for (int a=0; a<=numVertical; a++) {

        

        CGContextBeginPath(context);

        CGContextMoveToPoint(context, a*verticalSpacing, 0);

        CGContextAddLineToPoint(context,a*verticalSpacing, self.height);

        //    CGContextSetRGBStrokeColor(currentContext,

        //                                   192/255.0, 192/255.0,192/255.0, 1.0);

        [[UIColor grayColor] set];

        CGContextStrokePath(context);

    }

    


    

}


// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

    

    [self drawBackground];

//        UIColor *color = [UIColor redColor];

//    [color set];  //设置线条颜色

    

//    UIBezierPath* aPath = [UIBezierPath bezierPath];

//    aPath.lineWidth = 5.0;

//    

//    aPath.lineCapStyle = kCGLineCapRound;  //线条拐角

//    aPath.lineJoinStyle = kCGLineCapRound;  //终点处理

//    

//    // Set the starting point of the shape.

//    [aPath moveToPoint:CGPointMake(100.0, 0.0)];

//    

//    // Draw the lines

//    [aPath addLineToPoint:CGPointMake(200.0, 40.0)];

//    [aPath addLineToPoint:CGPointMake(160, 140)];

//    [aPath addLineToPoint:CGPointMake(40.0, 140)];

//    [aPath addLineToPoint:CGPointMake(0.0, 40.0)];

//    [aPath closePath]; //第五条线通过调用closePath方法得到的

//    

//    [aPath stroke]; //Draws line 根据坐标点连线

    

    UIColor *color = [UIColor grayColor];

    [color set];  //设置线条颜色

    



    [self.aPath removeAllPoints];


    self.aPath.lineWidth = 1;

    self.aPath.lineCapStyle = kCGLineCapRound//线条拐角

    self.aPath.lineJoinStyle = kCGLineCapRound//终点处理

    float num = self.width/10;

    int ponit = num/3;

    float cont = 0.0;

    

    for (int a=0; a<=10; a++) {

        

      cont  = (a+1)*num;

        

        int ard = arc4random()%50+200;

        

        int are = arc4random()%50+200;

        

        [self.aPath moveToPoint:CGPointMake(a*num, self.height/2)];

        

        [self.aPath addCurveToPoint:CGPointMake(cont, self.height/2) controlPoint1:CGPointMake(cont-2*ponit, self.height/2-ard) controlPoint2:CGPointMake(cont-ponit, self.height/2+are)];

        

//        [aPath stroke];

        

        

    }

    


    self.pathLayer.frame = self.bounds;

    self.pathLayer.path = self.aPath.CGPath;

  

    self.pathLayer.strokeColor = [[UIColor grayColor] CGColor];



    

    self.pathLayer.fillColor = nil;

    self.pathLayer.lineWidth = 1.0f;

    self.pathLayer.lineJoin = kCALineJoinBevel;

    

    [self.layer addSublayer:self.pathLayer];

    

    CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];

    pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];

    pathAnimation.duration = 2.0;

    pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];

    pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];

    [self.pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"];


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
LabVIEW是一种图形化编程语言,用于控制和测量系统。它提供了许多功能强大的工具和函数,用于创建各种应用程序,包括绘制波形图。 在LabVIEW中,波形图是一种用于显示和分析数据的图形控件。它可以用于显示模拟信号、传感器数据、实验结果等。以下是使用LabVIEW创建和显示波形图的步骤: 1. 创建波形图控件:在LabVIEW的界面中,可以通过拖拽和放置的方式创建一个波形图控件。可以在Front Panel窗口中找到波形图控件,并将其放置在适当的位置。 2. 连接数据源:将需要显示的数据源连接到波形图控件。可以使用各种数据源,例如传感器、模拟信号输入、文件读取等。通过将数据源与波形图控件连接,可以将数据传输到波形图中进行显示。 3. 配置波形图属性:可以通过右键单击波形图控件并选择属性来配置波形图的各种属性,例如坐标轴范围、颜色、线型等。根据需要,可以自定义波形图的外观和行为。 4. 更新数据:在程序运行时,可以通过更新数据源来更新波形图中显示的数据。可以使用LabVIEW的数据处理功能对数据进行处理和分析,并将结果传输到波形图中进行实时显示。 5. 运行程序:在LabVIEW中,可以通过点击运行按钮来执行程序。程序将根据设定的逻辑和数据源更新波形图,并实时显示数据。 以下是一个简单的LabVIEW程序示例,用于创建和显示波形图: ```labview 1. 创建一个波形图控件,并将其放置在Front Panel窗口中。 2. 连接数据源,例如模拟信号输入或传感器数据。 3. 配置波形图属性,例如坐标轴范围和颜色。 4. 在程序中使用数据处理功能,例如滤波或计算。 5. 将处理后的数据传输到波形图控件中,实时显示数据。 6. 点击运行按钮,执行程序并观察波形图的实时更新。 ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值