canvas手绘正五边形

2019-11-26 11:09:22

参考地址 canvas手绘正五边形

一、基本用法:

alertShow(param: any, $index: any) {

        let $log = this.$log;

        let $scope = this.$scope;

        if (param !== $scope.lastObj) {

            param.show = true;

            if ($scope.lastObj !== null) {

                $scope.lastObj.show = false;

            }

            $scope.lastObj = param;

            $scope.radarAlert = true;

            if ($index === 0) {

                $(".radarChart_alert").css({left: $scope.arr[$index].x + 100 + "px", top: $scope.arr[$index].y + "px"});

            } else {

                $(".radarChart_alert").css({left: $scope.arr[$index].x, top: $scope.arr[$index].y + 40 + "px"});

            }

        }

    }

drawRadarChart() {

    $scope.radarChartCategroy = [

            {name1: "词汇短语", name2: "排名前34%", show: false},

            {name1: "口语运用", name2: "排名前34%", show: false},

            {name1: "听力理解", name2: "排名前34%", show: false},

            {name1: "阅读理解", name2: "排名前34%", show: false},

            {name1: "语法句法", name2: "排名前34%", show: false}

        ];

        let $scope = this.$scope;

        let width: any, long: any, samll: any, big: any;

        getWidth();

        function getWidth() {

            width = $(".nav").width();

            $(".radarChart_div").height(width);

            $(".nav").height(width);

            $("#radarChart").attr({width: width, height: width});

            long = width / 2;

            samll = (width / 2) * Math.tan(36 * Math.PI / 180);

            big = (width / 2) / Math.cos(36 * Math.PI / 180);

            window.requestAnimationFrame(draw);

            let radarBtnWidth = $(".radarChart_select").width();

            let radarBtnHeight = $(".radarChart_select").height();

            $scope.arr = [

                {x: long - radarBtnWidth / 2, y: 5 - radarBtnHeight - 15},

                {x: -radarBtnWidth - 5, y: samll + 5 - radarBtnHeight / 2},

                {x: big * Math.sin(18 * Math.PI / 180) - radarBtnWidth * 2 / 3, y: big * Math.cos(18 * Math.PI / 180) + samll + radarBtnHeight / 2},

                {x: big * Math.sin(18 * Math.PI / 180) + big - radarBtnWidth / 3, y: big * Math.cos(18 * Math.PI / 180) + samll + radarBtnHeight / 2},

                {x: 2 * long + 5, y: samll + 5 - radarBtnHeight / 2}

            ]

            for (let i = 0; i < $scope.arr.length; i++) {

                $(".radarChart_select").eq(i).css({left: $scope.arr[i].x + "px", top: $scope.arr[i].y + "px"});

            }

        }

        function draw() {

            let canvas = document.getElementById("radarChart");

            if (canvas.getContext) {

                var ctx = canvas.getContext("2d");

                ctx.clearRect(0, 0, width, width);

                ctx.beginPath();

                ctx.lineWidth = 1;

                ctx.lineJoin = "miter";

                ctx.strokeStyle = "rgba(255,255,255,.5)";

                ctx.moveTo(long, 5);

                ctx.lineTo(0, samll + 5);

                ctx.lineTo(big * Math.sin(18 * Math.PI / 180), big * Math.cos(18 * Math.PI / 180) + samll + 5);

                ctx.lineTo(big * Math.sin(18 * Math.PI / 180) + big, big * Math.cos(18 * Math.PI / 180) + samll + 5);

                ctx.lineTo(2 * long, samll + 5);

                ctx.lineTo(long, 5);

                ctx.moveTo(long, long / Math.sin(72 * Math.PI / 180));

                ctx.lineTo(long, 5);

                ctx.moveTo(long, long / Math.sin(72 * Math.PI / 180));

                ctx.lineTo(0, samll + 5);

                ctx.moveTo(long, long / Math.sin(72 * Math.PI / 180));

                ctx.lineTo(big * Math.sin(18 * Math.PI / 180), big * Math.cos(18 * Math.PI / 180) + samll + 5);

                ctx.moveTo(long, long / Math.sin(72 * Math.PI / 180));

                ctx.lineTo(big * Math.sin(18 * Math.PI / 180) + big, big * Math.cos(18 * Math.PI / 180) + samll + 5);

                ctx.moveTo(long, long / Math.sin(72 * Math.PI / 180));

                ctx.lineTo(2 * long, samll + 5);

                ctx.stroke();

                ctx.save();

                ctx.beginPath();

                ctx.fillStyle = "rgba(255,255,255,.5)";

                ctx.moveTo(long, long / Math.sin(72 * Math.PI / 180) - $scope.num + 5);

                ctx.lineTo(long - $scope.num * Math.sin(72 * Math.PI / 180), long / Math.sin(72 * Math.PI / 180) - $scope.num * Math.cos(72 * Math.PI / 180) + 5);

                ctx.lineTo(long - $scope.num * Math.sin(36 * Math.PI / 180), long / Math.sin(72 * Math.PI / 180) + $scope.num * Math.cos(36 * Math.PI / 180) + 5);

                ctx.lineTo(long + $scope.num * Math.sin(36 * Math.PI / 180), long / Math.sin(72 * Math.PI / 180) + $scope.num * Math.cos(36 * Math.PI / 180) + 5);

                ctx.lineTo(long + $scope.num * Math.sin(72 * Math.PI / 180), long / Math.sin(72 * Math.PI / 180) - $scope.num * Math.cos(72 * Math.PI / 180) + 5);

//                ctx.lineTo(long, long / Math.sin(72 * Math.PI / 180) - $scope.num + 5);

                ctx.fill();

                ctx.save();

                ctx.restore();

                if ($scope.time2 < 60) {

                    window.requestAnimationFrame(draw);

                    $scope.num = $scope.num + long / 60;

                    $scope.time2 = $scope.time2 + 1;

                }

            }

        }

    }

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

            <div>

                <div class="radarChart_div"></div>

                <div class="nav">

                    <canvas id="radarChart"></canvas>

                    <div class="radarChart_select" ng-repeat="item in radarChartCategroy" ng-click="events.alertShow(item, $index)"

                         ng-class="{'radarChart_select_true':item.show,'radarChart_select_flase':!item.show}">

                        <div>{{item.name1}}</div>

                        <div>{{item.name2}}</div>

                    </div>

                    <div class="radarChart_alert" ng-style="radarAlert ? {'display': 'flex'} : {'display': 'none'}">

                        <div>213道</div>

                        <div>72%</div>

                        <div>正确答题</div>

                        <div>正确率</div>

                    </div>

                </div>

                <div class="radarChart_div"></div>              

            </div>



  • 2019-10-19 13:37:44

    v-model里使用过滤器

    档所述过滤器只能用在v-bind指令和{{}}表达式中,v-model中使用过滤器是一种思维误区。 因为v-model里实现数据显示和存储格式的转换应该是双向的。如下例:

  • 2019-10-19 16:35:45

    Vue.directive使用注意

    首先,Vue.directive要在实例初始化之前,不然会报错,还有,定义的指令不支持驼峰式写法,也会报下面同样的错,虽然在源码中没有找到在哪里统一处理大小写,但是在有关directive的方法中捕捉到的指令命名统一变为小写,所以,还是用'-'或者'_'分割吧。

  • 2019-10-21 08:39:54

    vue slot用法以及使用介绍

    通过上面的内容可以知道,在slot组件中引入了slot的子组件,而且又在子组件标签内添加了新的标签内容,但页面上并没有将子组件标签内的标签内容显示出来,

  • 2019-10-21 15:06:27

    yarn详细入门教程

    Yarn 是 Facebook, Google, Exponent 和 Tilde 开发的一款新的 JavaScript 包管理工具。就像我们可以从官方文档了解那样,它的目的是解决这些团队使用 npm 面临的少数问题,即:

  • 2019-10-23 10:20:48

    php 去掉 头尾 空格 2种方法

    看似很简单的问题,其实还是有点坑的,首先这里&nbsp;空格转义,不是字符串,直接用trim()是去不掉。

  • 2019-10-23 23:25:22

    PostMapping,GetMapping不固定路径的写法

    PostMapping中的value属性是数组,所以可以定义多个路径,required属性默认是true,不必再写required=true,默认表示该参数是必须要有的,如果写required=false,表示该参数是可选的,可有可无。

  • 2019-10-24 01:14:29

    通过属性搜索商品mysql设计

    属性是可以动态扩展的,问题:属性是搜索条件 问:请展示出 材质为塑料 防水为YES,颜色为绿色的商品详细信息,按照sort_filed排序