改进后的时钟

  

flash9中的实例时钟,针对类文件进行了改进,加入了表盘的细分和中文显示时间

主要修改了AnalogClockFace类,修改后的代码如下:

package com.example.programmingas3.clock{
 import flash.display.Shape;
 import flash.display.Sprite;
 import flash.display.StageAlign;
 import flash.display.StageScaleMode;
 import flash.text.StaticText;
 import flash.events.*;
 import flash.text.TextField;
 import flash.text.TextFormat;

 /**
  * Displays a round clock face with an hour hand, a minute hand, and a second hand.
  */
 public class AnalogClockFace extends Sprite {
  /**
   * The desired width of this component, as opposed to the .width
   * property which represents tha actual width.
   */
  public var w:uint = 200;

  /**
   * The desired height of this component, as opposed to the .height
   * property which represents tha actual height.
   */
  public var h:uint = 200;

  /**
       * The radius from the center of the clock to the
       * outer edge of the circular face outline.
       */
  public var radius:uint;

  /**
           * The coordinates of the center of the face.
           */
  public var centerX:int;
  public var centerY:int;

  /**
           * The three hands of the clock.
           */
  public var hourHand:Shape;
  public var minuteHand:Shape;
  public var secondHand:Shape;

  /**
           * The colors of the background and each hand.
           * These could be set using parameters or
           * styles in the future.
           */
  public var bgColor:uint = 0xEEEEFF;
  public var hourHandColor:uint = 0x003366;
  public var minuteHandColor:uint = 0x000099;
  public var secondHandColor:uint = 0xCC0033;
  public var x0:uint;
  public var y0:uint;
  public var x1:uint;
  public var y1:uint;
  public var txt:TextField;
  /**
           * Stores a snapshot of the current time, so it
           * doesn't change while in the middle of drawing the
           * three hands.
           */
  public var currentTime:Date;

  /**
           * Contructs a new clock face. The width and
           * height will be equal.
           */
  public function AnalogClockFace(w:uint) {
   this.w = w;
   this.h = w;

   // Rounds to the nearest pixel
   this.radius = Math.round(this.w / 2);

   // The face is always square now, so the
   // distance to the center is the same
   // horizontally and vertically
   this.centerX = this.radius;
   this.centerY = this.radius;
  }
  /**
           * Creates the outline, hour labels, and clock hands.
           */
  public function init():void {
   // draws the circular clock outline
   drawBorder();

   // draws the hour numbers
   drawLabels();

   // creates the three clock hands
   createHands();
   Drawlss();
   CreatTxt();
  }
  /**
          * Draws a circular border.
          */
  public function drawBorder():void {
   graphics.lineStyle(0.5, 0x999999);
   graphics.beginFill(bgColor);
   graphics.drawCircle(centerX, centerY, radius);
   graphics.endFill();
  }
  /**
     * Puts numeric labels at the hour points.
     */
  public function drawLabels():void {
   for (var i:Number = 1; i <= 12; i++) {
    // Creates a new TextField showing the hour number
    var label:TextField = new TextField();
    label.text = i.toString();

    // Places hour labels around the clock face.
    // The sin() and cos() functions both operate on angles in radians.
    var angleInRadians:Number = i * 30 * (Math.PI/180);
    // Place the label using the sin() and cos() functions to get the x,y coordinates.
    // The multiplier value of 0.9 puts the labels inside the outline of the clock face.
    // The integer value at the end of the equation adjusts the label position,
    // since the x,y coordinate is in the upper left corner.
    label.x = centerX + (0.9 * radius * Math.sin( angleInRadians )) - 5;
    label.y = centerY - (0.9 * radius * Math.cos( angleInRadians )) - 9;

    // Formats the label text.
    var tf:TextFormat = new TextFormat();
    tf.font = "Arial";
    tf.bold = "true";
    tf.size = 12;
    label.setTextFormat(tf);

    // Adds the label to the clock face display list.
    addChild(label);
   }
  }
  public function Drawlss() {
   for (var i:Number=0; i<=60; i++) {
    var lshape:Shape=new Shape();
    //trace(i)
    Drawls(lshape,i*6,0x000000,1);
    addChild(lshape);
   }
  }
  public function Drawls(hand:Shape, rot:uint, color:uint, thickness:Number):void {
   var angleInRadians:Number = rot * (Math.PI/180);
   x1 = centerX + (radius * Math.sin( angleInRadians ));
   y1 = centerY - (radius * Math.cos( angleInRadians ));
   if (rot%30==0) {

    x0 = centerX + (0.95 * radius * Math.sin( angleInRadians ));
    y0 = centerY - (0.95 * radius * Math.cos( angleInRadians ));
   } else {
    x0 = centerX + (0.97 * radius * Math.sin( angleInRadians ));
    y0 = centerY - (0.97 * radius * Math.cos( angleInRadians ));
   }
   hand.graphics.lineStyle(thickness, color);
   hand.graphics.moveTo(x0,y0);
   hand.graphics.lineTo(x1,y1);
  }
  /**
          * Creates hour, minute, and second hands using the 2D drawing API.
          */
  public function createHands():void {
   // Uses a Shape since it's the simplest component that supports
   // the 2D drawing API.
   var hourHandShape:Shape = new Shape();
   drawHand(hourHandShape, Math.round(radius * 0.5), hourHandColor, 3.0);
   this.hourHand = Shape(addChild(hourHandShape));
   this.hourHand.x = centerX;
   this.hourHand.y = centerY;

   var minuteHandShape:Shape = new Shape();
   drawHand(minuteHandShape, Math.round(radius * 0.8), minuteHandColor, 2.0);
   this.minuteHand = Shape(addChild(minuteHandShape));
   this.minuteHand.x = centerX;
   this.minuteHand.y = centerY;

   var secondHandShape:Shape = new Shape();
   drawHand(secondHandShape, Math.round(radius * 0.9), secondHandColor, 0.5);
   this.secondHand = Shape(addChild(secondHandShape));
   this.secondHand.x = centerX;
   this.secondHand.y = centerY;
  }
  /**
          * Draws a clock hand with a given size, color, and thickness.
          */
  public function drawHand(hand:Shape, distance:uint, color:uint, thickness:Number):void {
   hand.graphics.lineStyle(thickness, color);
   hand.graphics.moveTo(0, distance);
   hand.graphics.lineTo(0, 0);
  }
  /**
          * Called by the parent container when the display is being drawn.
          */
  public function draw():void {
   // Stores the current date and time in an instance variable
   currentTime = new Date();
   showTime(currentTime);
   showT(currentTime);
  }
  public function CreatTxt():void {
   txt= new TextField();
   txt.width=300;
   //label.text =;
   txt.x = centerX -radius;
   txt.y = centerY -radius-20;
   addChild(txt);
   }
  public function showT(time:Date) {
   var seconds:uint = time.getSeconds();
   var minutes:uint = time.getMinutes();
   var hours:uint = time.getHours();
   var year:uint=time.getFullYear();
   var month:uint=time.getMonth()+1;
   var date:uint=time.getDate();
   this.txt.text="现在时间是:"+year+"年"+month+"月"+date+"日"+hours+"时"+minutes+"分"+seconds+"秒" ;
   //setTxt(datetxt)
  }
  /**
           * Displays the given Date/Time in that good old analog clock style.
           */

  public function showTime(time:Date):void {
   // Gets the time values
   var seconds:uint = time.getSeconds();
   var minutes:uint = time.getMinutes();
   var hours:uint = time.getHours();
   // Multiplies by 6 to get degrees
   this.secondHand.rotation = 180 + (seconds * 6);
   this.minuteHand.rotation = 180 + (minutes * 6);

   // Multiplies by 30 to get basic degrees, and then
   // adds up to 29.5 degrees (59 * 0.5) to account
   // for the minutes
   this.hourHand.rotation = 180 + (hours * 30) + (minutes * 0.5);
  }
 }
}

时间: 2024-10-31 10:34:59

改进后的时钟的相关文章

谷歌终于发布了改进后的顶部导航条

经过了至少一年半的测试,谷歌终于发布了改进后的顶部导航条,该产品在谷歌的大多数产品中都存在.新的导航条更多的是感官上的改进.然而比工具条本身更重要的是它与传言中的,即将发布的社交网络"layer"相连接,谷歌正致力于将所有产品集成在layer中.虽然该导航条的发布不算重大事件,但大多数用户已经在谷歌的产品中体验到了该导航条,例如网络搜索,Gmail等.不可否认的是,新导航条与旧产品相比更加完善,它看起来更像是菜单按钮.另一个改进是使用设置按钮取代了一些连接,它允许用户访问其账户设置以及

菜鸟学算法----改进后的欧几里得算法

对于正整数 a和b  利用欧几里得算法可以得出 一个最大公因数 ,  改进后的算法满足  最大公因数 q=xa+yb   ; 那么我们如何求出 a和b呢 . 书上是这么写的 那么我们用代码把他实现出来, 向大家推荐一本书<The Art Of Computer.Programmer>   第一篇的数学部分   真心的枯燥 我选择的方式 是 适当的囫囵吞枣 对于这一样 ,但是对于其中讲述的算法 还是要仔细的去看滴 .   对于算法的分析  我直接上原书图 #include "stdaf

改进后的《自动显示天气预报》小程序(Linux和Windows环境都可以)

window|程序|天气预报|显示 这次改进,主要是增加了图象的获取,并提供了一个比较完整的获取远端文件的函数.具体代码如下:<?$fcont=file("http://www.bjmb.gov.cn/today.asp");$arr=array();for($i=0;$i<count($fcont);$i++){    $tmp=$fcont[$i];    $tmp=ereg_replace("<br>"," ",$t

改进后的ASP公共翻页模块

翻页 用DWMX2004的插件包可以实现ASP的各种分页功能,但是那些代码实在有点恐怖,我们在实际的项目开发中,有没有更简单的方法实现"一劳永逸"呢?答案是肯定的. 我们需要的功能: 1.调用该模块时,只需要传递记录集和每页显示的记录的条数:2.可以点击链接进行翻页,也可以直接输入页码,回车后翻页:3.不要考虑文件名,程序的每次翻页都能在当前页面. 具体编写内容 大家可以把翻页的链接做成图片按钮,这样的话也面就更加美观了. 调用方法:1.在程序开始或要使用翻页的地方包含翻页模块文件:2

改进后的日志类CLogger

在原有的基础上增加了module_name,表示模块名,当一个系统由多模块组成时,输出的日志将更加清晰,使用方法,以MOOON-agent中的为例: /** 不要修改下面的常量值,而应当通过对应的方法去修改 * 这些常量值主要是方便多模块共享,故放在这个公有头文件当中 */enum{ LOG_LINE_SIZE_MIN = 256, /** 日志行最小长度 */ LOG_LINE_SIZE_MAX = 32768, /** 日志行最大长度(32K) ,最大不能超过64K,因为使用2字节无符号整数

改进后的Java英文字母打字游戏

//以下代码在JDK1.4下通过 //编译:javac MyPanel.java //运行:java MyPanel //Made By Qiukai //注意:启动后,在窗口中点鼠标反键选择开始游戏进行 import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; public class MyPanel extends JFrame { public int FPS; public

继百度针对链接算法改进后,外链我们该怎么做

中介交易 SEO诊断 淘宝客 云主机 技术大厅 发现很多朋友经常在问,我的网站如何去做外链那.做外链应该注意什么问题.随着搜索引擎的算法调整,原来互联网上存在的大量的那些如何发外链的方式都已经无法去运营了.那么到底下一步到底该怎么去制造高质量的外链.首先我们先去关注一下搜索引擎对于我们外链是怎么要求的. 大家可以去看看这篇文章 "百度站长平台发布外链方面公http://zhanzhang.baidu.com/wiki/160"那么其中规定了很多方面.例如: 1.垃圾外链 .2.作弊外链

英特尔正瞄准迅速发展的平板电脑市场,按计划推出改进后的芯片平台

截止目前,英特尔在平板电脑市场上一直落后于关注廉价低功耗处理器的竞争对手.英特尔营销主管阿尼尔·南杜里(Anil Nanduri)表示,这款代号为橡树路(Oak Trail)并定于2011年年初开始出货的芯片,相对竞争产品大幅提高了能耗效率,并保留了自己的特色功能.他在接受路透社采访时称:"平板电脑能耗最大的部分是显示面板.在闲置情况下,我们比任何其他解决方案都有竞争力".他表示,新处理器可让用户浏览网页或观看视频,而电池可连续使用12小时不充电.自从苹果在1月份推出iPad平板电脑后

经过了至少一年半的测试,谷歌终于发布了改进后的顶部导航条

该产品在谷歌的大多数产品中都存在.新的导航条更多的是感官上的改进.然而比工具条本身更重要的是它与传言中的,即将发布的社交网络"layer"相连接,谷歌正致力于将所有产品集成在layer中.虽然该导航条的发布不算重大事件,但大多数用户已经在谷歌的产品中体验到了该导航条,例如网络搜索,Gmail等.不可否认的是,新导航条与旧产品相比更加完善,它看起来更像是菜单按钮.另一个改进是使用设置按钮取代了一些连接,它允许用户访问其账户设置以及配置选项.另外,邮件地址已经被账户名称取代.同步登录账户之