{"id":199,"date":"2009-02-23T00:00:39","date_gmt":"2009-02-23T07:00:39","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=835"},"modified":"2009-02-23T00:00:39","modified_gmt":"2009-02-23T07:00:39","slug":"24hr-clock","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=199","title":{"rendered":"24hr Clock"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar clock:Sprite = Sprite(addChild(new Sprite()));\r\nclock.x = clock.y = 150;\r\n\r\nvar bg:Shape = Shape(clock.addChild(new Shape()));\r\nwith (bg.graphics) lineStyle(2, 0x666666), beginFill(0xEFEFEF), drawCircle(0,0,110);\r\n\r\nvar hHand:Shape = clockHand(6, 50);\r\nvar mHand:Shape = clockHand(2, 80);\r\nvar sHand:Shape = clockHand(1, 90);\r\n\r\nvar center:Shape = Shape(clock.addChild(new Shape()));\r\nwith (center.graphics) beginFill(0x000000), drawCircle(0,0,5);\r\n\r\nvar hInc:Number = 360\/24;\r\nvar msInc:Number = 360\/60 ;\r\nvar nOff:Number = 6;\r\nvar verdana:TextFormat = new TextFormat(&quot;Verdana&quot;, 8);\r\n\/\/ add numbers to clock\r\nfor (var i:int = 0; i&lt;24; i++){\r\n\t var ang:Number = (i * hInc - 90) * Math.PI\/180;\r\n\t createNumber(70,ang, i.toString());\r\n\t var ms:Number = i * 2.5;\r\n\t if (ms % 5 == 0){\r\n\t\tcreateNumber(95, ang, ms.toString());\r\n\t }\r\n}\r\n \r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\r\n\tvar date:Date = new Date();\r\n\thHand.rotation =  hInc * date.getHours();\r\n\tmHand.rotation =  msInc * date.getMinutes();\r\n\tsHand.rotation =  msInc * date.getSeconds();\r\n}\r\n\r\nfunction clockHand(thickness:Number, leng:Number):Shape{\r\n\tvar hand:Shape = Shape(clock.addChild(new Shape()));\r\n\twith (hand.graphics) {\r\n\t\tlineStyle(thickness, 0x000000, 1, true, LineScaleMode.NORMAL, CapsStyle.SQUARE);\r\n\t\tlineTo(0,-leng);\r\n\t}\r\n\treturn hand;\r\n}\r\n\r\nfunction createNumber(radius:Number, theta:Number, str:String):void{\r\n    var t:TextField = TextField(clock.addChild(new TextField()));\r\n\twith (t) defaultTextFormat = verdana, t.autoSize = &quot;left&quot;;\r\n\tt.text = str;\r\n\tt.x = radius * Math.cos(theta) - nOff;\r\n\tt.y = radius* Math.sin(theta) - nOff;\r\n}\r\n<\/pre>\n<p>I was watching a movie the other day and I saw a 24 hour clock in the background of one of the shots. After the movie I coded this snippet. It draws a very basic clock with an hour hand that takes 24 hours to go full circle&#8230;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/clock.jpg\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>var clock:Sprite = Sprite(addChild(new Sprite())); clock.x = clock.y = 150; var bg:Shape = Shape(clock.addChild(new Shape())); with (bg.graphics) lineStyle(2, 0x666666), beginFill(0xEFEFEF), drawCircle(0,0,110); var hHand:Shape = clockHand(6, 50); var mHand:Shape = clockHand(2, 80); var sHand:Shape = clockHand(1, 90); var center:Shape = Shape(clock.addChild(new Shape())); with (center.graphics) beginFill(0x000000), drawCircle(0,0,5); var hInc:Number = 360\/24; var msInc:Number = 360\/60 ; var [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[94],"tags":[3,4],"class_list":["post-199","post","type-post","status-publish","format-standard","hentry","category-misc","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/199","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=199"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/199\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}