zoukankan      html  css  js  c++  java
  • 【WIN10】WIN2D——基本圖形的繪製

    DEMO下載地址:http://yunpan.cn/c3iNuHFFAcr8h (提取码:8e48)

    先看一個截圖:

    繪製了一些基本形狀。

    DEMO的繪製代碼都非常簡單,不想在博客裡細說了,看代碼更為清晰些。

    可能繪製扇形的代碼有些麻煩些。

    微軟是使用鐘錶的轉動方向(順時針)作為弧度運轉方向的,所以角度30度,是會在x座標下的,而不是通常的在x座標上面。

    帖一下畫鐘錶的代碼,是非常簡單的:

            private void clock_Draw(CanvasControl sender, CanvasDrawEventArgs args)
            {
                float radius = (float)sender.ActualWidth / 2 - 4;
                Vector2 center = new Vector2((float)sender.ActualWidth / 2, (float)sender.ActualWidth / 2);
    
                for (int i = 0; i < 60; ++i)
                {
                    int borderSize = 1;
                    Vector2 begin = new Vector2(radius  + center.X - 3, center.Y);
                    Vector2 end = new Vector2(radius + center.X, center.Y);
    
                    if (i % 15 == 0)
                    {
                        borderSize = 4;
                        begin = new Vector2(center.X + radius - 15, center.Y);                    
                    }
                    else if (i % 5 == 0)
                    {
                        borderSize = 2;
                        begin = new Vector2(radius + center.X - 10, center.Y);
                    }
    
                    args.DrawingSession.Transform = Matrix3x2.CreateRotation(TimeValue2Radion(i, 60), center);
                    args.DrawingSession.DrawLine(begin, end, Color.FromArgb(255, 255, 255, 255), borderSize);
                }
    
                args.DrawingSession.DrawCircle(center, radius, Color.FromArgb(255, 255, 255, 255), 2);
    
                // 結點處是圓,指向處為三角
                CanvasStrokeStyle lineStyle = new CanvasStrokeStyle();
                lineStyle.StartCap = CanvasCapStyle.Round;
                lineStyle.EndCap = CanvasCapStyle.Triangle;
    
                // 時針
                float hours = DateTime.Now.Hour % 12 + DateTime.Now.Minute / 60.0f + DateTime.Now.Second / 60.0f / 24.0f; // 12小時制
                float intervalHours = hours - 3.0f; // 3點是0度
                float hourRadian = TimeValue2Radion(intervalHours, 12);
                args.DrawingSession.Transform = Matrix3x2.CreateRotation(hourRadian, center);
                args.DrawingSession.DrawLine(center, new Vector2(center.X + 80, center.Y), Color.FromArgb(255, 255, 255, 255), 5, lineStyle);
    
                // 分針
                float minutes = DateTime.Now.Minute+ DateTime.Now.Second / 60.0f;
                float intervalMinutes = minutes - 15; // 15分钟是0度
                float minuteRadian = TimeValue2Radion(intervalMinutes, 60);
                args.DrawingSession.Transform = Matrix3x2.CreateRotation(minuteRadian, center);
                args.DrawingSession.DrawLine(center, new Vector2(center.X + 100, center.Y), Color.FromArgb(255, 255, 255, 255), 2, lineStyle);
    
                // 秒針
                float seconds = DateTime.Now.Second;
                float intervalSeconds = seconds - 15; // 15秒是0度
                float secondRadian = TimeValue2Radion(intervalSeconds, 60);
                args.DrawingSession.Transform = Matrix3x2.CreateRotation(secondRadian, center);
                args.DrawingSession.DrawLine(center, new Vector2(center.X + 120, center.Y), Color.FromArgb(255, 255, 255, 255));
            }
    
            private float TimeValue2Radion(float intervalTime, int total)
            {
                return intervalTime / total * 360 * (float)Math.PI / 180;
            }

    因為今天只寫了這麼一個例子,就先發一個了。

    後面再一一補上。

  • 相关阅读:
    OpenGL---------BMP文件格式
    OpenGL———混合的基本知识
    OpenGL------显示列表
    OpenGL---------光照的基本知识
    OpenGL学习--------动画制作
    OpenGL------三维变换
    OpenGL学习--------颜色的选择
    OpenGL学习-------点、直线、多边形
    Windows X64汇编入门(1)
    x86 x64下调用约定浅析
  • 原文地址:https://www.cnblogs.com/lin277541/p/5059489.html
Copyright © 2011-2022 走看看