`

SSD04 Exercise08 个人解答

阅读更多

 

Programming: Drawing

Description

This assignment requires you to complete the dynamic drawing components of the Date/Time Control Panel from the previous two programming assignments.  In particular, you will be moving the map found in the "Time Zone" tab when the time zone changes and will be drawing a clock face corresponding to the time setting.

Recall that the image used for displaying the map (in a PictureBox control) has been prepared with one pixel corresponding to each degree of longitude and has been drawn long enough to be displayed at any setting from 0 to 360 degrees.  Each time the time zone is changed, you should redraw the PictureBox control containing the map to indicate the approximate position of the time zone on the globe.  This can be done by converting the number of minutes offset from GMT into degrees of rotation of the earth.  Recall that 24 hours (= 1440 minutes) of offset corresponds to 360 degrees and that the map image has been drawn with one pixel for each degree.   Finally, note that the map image has been prepared so that displaying its left edge at 0 corresponds to centering the image at 0 degrees (= GMT - 12 hours).

You should assign the map image (see the resources below) to the Image property of the PictureBox control using the Properties editor in Visual Basic.  This will allow you to access the image easily when it needs to be redrawn in a new position.  Each time the time zone offset changes you should redraw the Image in the PictureBox control.  This can be done by first computing a drawing offset for the image.  To do this, first compute a rotation from the GMT offset, and then convert that rotation into pixels.  A rotation of N degrees corresponds to an offset of -N pixels indicating that the left edge of the image appears N pixel to the left of the PictureBox origin.  Once a drawing offset has been computed the actual map image may be drawn using the Graphics DrawImage routine.  If the PictureBox is called mapPicture and the computed offset is screenOffset , then drawing would be done with the statement:

e.Graphics.DrawImage(mapPicture.Image, screenOffset, 0)

The second portion of this assignment is to draw a clock face in the PictureBox found on the "Date & Time" tab.  As shown below, this clock face should reflect the current time setting.  Consequently, it should be redrawn whenever the hour, minute, or second setting changes.


In drawing the clock face, you may find the following Graphics methods to be useful:

  • DrawLine
  • FillPolygon
  • FillEllipse

Finally, the routines clockX() and clockY()( which are provided in the resources section below) may be useful.  These routines compute the x and y positions of a point on the clock face at a given minute and at a given distance from the center of the clock (assuming that the center of the clock is at location 0,0).  The following example code draws a small black circle at the 35-minute position of a clock centered in a PictureBox given as a parameter.

Public Sub drawDotAt35Minutes(ByVal onObj As PictureBox, ByVal e as Windows.Forms.PaintEventArgs)
    Const clockInset As Integer = 100         ' distance from clock edge to box edge
    Const dotRadius As Integer = 15           ' size of the dot
    Dim smallDim As Integer                   ' smaller of width and height of box
    Dim clockRadius As Integer                ' radius of the clock
    Dim centerX As Integer                    ' x for center of the clock
    Dim centerY As Integer                    ' y for center of the clock
    Dim x As Integer                          ' x position of dot
    Dim y As Integer                          ' y position of dot
    Dim brush As new SolidBrush(Color.Black)  'brush

    ' calculate the center of the clock and its radius so it fits in the box
    centerX = onObj.Width / 2
    centerY = onObj.Height / 2
    smallDim = onObj.Width
    If (onObj.Height < smallDim) Then
        smallDim = onObj.Height

    End If
    clockRadius = smallDim / 2 - clockInset

    ' calculate the position of the dot
    x = centerX + clockX(35, clockRadius - dotRadius)
    y = centerY + clockY(35, clockRadius - dotRadius)

    ' draw a filled black circle
    e.Graphics.FillEllipse(brush, x, y, dotRadius, dotRadius)

End Sub

Resources

  • Map image


This image is scaled with each pixel corresponding to one degree of longitude.  You can download the image here: time_zone_map.gif

  • Clock drawing helper routines

The following routines compute the x and y positions of a point on a clock face, assuming that the clock is centered at 0,0.  They each take a minute value to define a location along the clock, as well as a radius that defines how far away from the center of the clock the point should be.

Public Function clockDrawX(minuteVal As Integer, radius As Integer)
    Const PI As Double = 3.14159265
    Dim angle As Double

    angle = (PI * 2 * minuteVal) / 60 - PI / 2
    Return CInt(radius * Cos(angle))
End Function

Public Function clockDrawY(minuteVal As Integer, radius As Integer)
    Dim angle As Double
    Dim PI As Double
    PI = 3.14159265

    angle = (PI * 2 * minuteVal) / 60 - PI / 2
    Return CInt(radius * Sin(angle))
End Function

  • Sample Solution

An executable like the application you are asked to create, click Ex8.zip

.

Submission

Submit the following files:

  • A project archive named Exercise8.zip
  • 大小: 10.6 KB
  • 大小: 41.2 KB
  • ex8.zip (65.8 KB)
  • 下载次数: 12
分享到:
评论
1 楼 qianjigui 2009-02-08  
Feedback for Exercise 8 (v2.0)
Total Score: 93/100

    * Elements
      Score: 60/60

    * Functions
      Score: 23/30

          o NewFunctions
            Score: 15/20

                + Redrawing of the Clock Face
                  Score: 5/10
                  This function is flawed in some minor way. -5

                + Movement of Time-Zone Map
                  Score: 10/10

          o PriorFunctions
            Score: 8/10

                + Calendar control update
                  Score: 1/2
                  This function is flawed in some minor way. -1

                + Seconds range restriction
                  Score: 1/2
                  This function is flawed in some minor way. -1

                + Minutes range restriction
                  Score: 2/2

                + Hours range restriction
                  Score: 2/2

                + AM/PM radio buttons
                  Score: 2/2

                + Time Zone ComboBox
                  Score: 2/2

                + Daylight Saving CheckBox disabling
                  Score: 2/2

                + OK button
                  Score: 2/2

                + Cancel button
                  Score: 2/2

                + Apply button
                  Score: 2/2

                + Settings report
                  Score: 2/2

    * GeneralIssues
      Score: 10/10

相关推荐

    SSD04 Exercise04 个人解答

    【标题】"SSD04 Exercise04 个人解答"主要涵盖了两个关键知识点:源码理解和工具使用。在这个练习中,作者分享了他们对于特定编程问题的解决方案,可能涉及编程语言的深入理解、代码调试技巧以及如何有效地利用开发...

    SSD04 Exercise06 个人解答

    标题“SSD04 Exercise06 个人解答”暗示了一个编程练习或项目,其中涉及到对Microsoft Calendar Control 10.0的使用。这个控制组件通常用于Windows应用程序开发,特别是使用Visual Basic 6 (VB6) 或其他支持ActiveX...

    SSD04 Exercise03 个人解答

    【标题】"SSD04 Exercise03 个人解答"主要涵盖了两个关键概念:源码分析和工具使用。这可能是某个课程或项目中的一个练习,其中"SSD04"可能代表课程编号或者阶段,而"Exercise03"则指示这是第三次实践任务。解答者...

    SSD06 Exercise04 个人解答

    标题 "SSD06 Exercise04 个人解答" 暗示这可能是一个关于软件开发或编程练习的解答,特别是涉及到性能分析或者优化的环节。描述中的 "NULL" 没有提供额外的信息,但我们可以从标签 "源码" 和 "工具" 中推测,这个...

    SSD04 Exercise01 个人解答

    这是我的解答 博文链接:https://qianjigui.iteye.com/blog/248917

    SSD06 Exercise02 个人解答

    【标题】"SSD06 Exercise02 个人解答"主要涵盖了两个关键概念:源码分析和工具使用。这可能是某个课程或项目练习的一部分,其中作者Qianjigui分享了他在解决特定编程问题或实现某功能时的经验和理解。 在源码分析...

    SSD06 Exercise05 个人解答

    【标题】"SSD06 Exercise05 个人解答"主要涵盖了两个关键知识点:源码分析和工具使用。在这个练习中,作者分享了他对某个特定编程问题或项目的解答,这通常涉及深入理解代码的运作机制,包括算法、数据结构以及编程...

    SSD04 Exercise05 个人解答

    综上所述,SSD04 Exercise05 个人解答不仅仅是完成了一个具体的编程练习,更重要的是,通过这个过程,我学习到了如何有效地阅读和分析源码,如何深入理解编程语言特性和算法的运作,以及如何熟练运用开发工具来提升...

    SSD06 Exercise03 个人解答

    标题“SSD06 Exercise03 个人解答”暗示了一个编程练习或课程作业,其中可能涉及 SSD(固态存储)相关的技术,而 Exercise03 可能是该系列练习中的第三个部分。描述提到的“Ubuntu8.04+Gcc+Gdb”是一个古老的Linux...

    SSD06 Exercise01 个人解答

    NULL 博文链接:https://qianjigui.iteye.com/blog/256678

    SSD04 Exercise02 个人解答

    我的解答 博文链接:https://qianjigui.iteye.com/blog/248918

Global site tag (gtag.js) - Google Analytics