// clock // created using proce55ing application | www.proce55ing.net // copyright© www.uncontrol.com | mannytan@uncontrol.com package { import flash.system.Security; import frocessing.display.F5MovieClip3D; import frocessing.text.IFont; [SWF(width="480", height="480", backgroundColor="0xffffff", frameRate="30")] /** * uncontrol's Clock (port to frocessing) * @author civet */ public class Clock extends F5MovieClip3D { private static const PATH:String = "http://dreamana.com/" public function Clock() { Security.loadPolicyFile(PATH + "crossdomain.xml"); } // ************************************************************************ // initialize // ************************************************************************ public static const WIDTH:int = 480; public static const HEIGHT:int = 480; public var mouseStatus:Boolean = false; public var priorMouseStatus:Boolean = false; public var px:int, py:int, pz:int; public var i:int, j:int, k:int; public var counter:Number=1; public var time:String,s_hour:String,s_min:String, s_sec:String; public var pos_x:Number, pos_y:Number; public var radius:Number; public var SECOND_INC:Number = .0166; // 1/60 public var MINUTE_INC:Number = .0166; // 1/60 public var HOUR_INC:Number = .0833; // 1/12 public var current_sec:Number, current_min:Number, current_hr:Number; public var radian_percentage:Number; // ************************************************************************ // set up // ************************************************************************ public function setup():void { size(WIDTH, HEIGHT); background(255); //hint(SMOOTH_IMAGES); var ocr:IFont = loadFont(PATH + "lab/frocessing/" + "ocr-b.vlw"); textFont(ocr, 12); ellipseMode(CENTER); rectMode(CENTER); } // ************************************************************************ // listeners // ************************************************************************ public function mousePressed():void { mouseStatus = true; } public function mouseReleased():void { mouseStatus = false; } public function draw():void { //translate(width/2, height/2); translate(WIDTH*.5, HEIGHT*.5); radian_percentage = ((mouseY+.0001)*.0025); rotateX(TWO_PI * radian_percentage * -1); // -------------------------------------------- // analog marks numbers // -------------------------------------------- pushMatrix(); rotateX(TWO_PI*(.25)); for (i=1;i<=12;i++) { pushMatrix(); if (i==12) { noStroke(); fill(255,102,0); } else { noStroke(); //fill(0,0,0,75); fill(0,0,0,0.75); } rotateZ(TWO_PI*((i)*HOUR_INC)); if (i<10) { /* ads a zero */ text("0"+i, -5, -145); } else { text(""+i, -5, -145); } //rect(0,145,4,10); popMatrix(); } popMatrix(); // -------------------------------------------- // digital marks colon symbols // -------------------------------------------- pushMatrix(); translate(cos(2*TWO_PI*radian_percentage)*7+7,0); rotateX(TWO_PI*( radian_percentage )); text(":", 0, 0); popMatrix(); pushMatrix(); translate(cos(2*TWO_PI*radian_percentage)*-7+2,0); rotateX(TWO_PI*( radian_percentage )); text(":", 0, 0); popMatrix(); pushMatrix(); // -------------------------------------------- // second // -------------------------------------------- current_sec = second(); radius = 120; translate(cos(2*TWO_PI*radian_percentage)*10+10,0); rotateY(TWO_PI*(( (45) + current_sec )*SECOND_INC)*-1); // draw shaded circle noStroke(); // draw numbers for (i=0; i<=59;i++) { pushMatrix(); translate(radius,0); rotateZ(TWO_PI*(( (30-i) + current_sec )*SECOND_INC)*-1); translate(radius,0); rotateZ(TWO_PI*(( (30-i) + current_sec )*SECOND_INC)); rotateY(TWO_PI*(( (45) + current_sec )*SECOND_INC)); rotateX(TWO_PI*( radian_percentage )); if (i==current_sec) { /* highlights current time */ fill(255,102,0); } else { //fill(0,0,0,50); fill(0,0,0,0.5); } if (i<10) { /* ads a zero */ text("0"+i, 0, 0); } else { text(""+i, 0, 0); } popMatrix(); } popMatrix(); // -------------------------------------------- // minute // -------------------------------------------- current_min = minute() + (second()*SECOND_INC); radius = 100; pushMatrix(); translate(0,0); rotateY(TWO_PI*(( (45) + current_min )*MINUTE_INC)*-1); // draw shaded circle noStroke(); // draw numbers for (i=0; i<=59;i++) { pushMatrix(); translate(radius,0); rotateZ(TWO_PI*(( (30-i) + int(current_min) )*MINUTE_INC)*-1); translate(radius,0); rotateZ(TWO_PI*(( (30-i) + int(current_min) )*MINUTE_INC)); rotateY(TWO_PI*(( (45) + current_min )*MINUTE_INC)); rotateX(TWO_PI*( radian_percentage )); if (i==int(current_min)) { /* highlights current time */ fill(255,102,0); } else { //fill(0,0,0,50); fill(0,0,0,0.5); } if (i<10) { /* ads a zero */ text("0"+i, 0, 0); } else { text(""+i, 0, 0); } popMatrix(); } popMatrix(); // -------------------------------------------- // hour // -------------------------------------------- current_hr = hour()%12 + (minute()*MINUTE_INC); radius = 40; pushMatrix(); translate(cos(2*TWO_PI*radian_percentage)*-10-10,0); rotateY(TWO_PI*(( (9) + current_hr )*HOUR_INC)*-1); // draw shaded circle noStroke(); // draw numbers for (i=0; i<=11;i++) { pushMatrix(); translate(radius,0); rotateZ(TWO_PI*(( (6-i) + int(current_hr) )*HOUR_INC)*-1); translate(radius,0); rotateZ(TWO_PI*(( (6-i) + int(current_hr) )*HOUR_INC)); rotateY(TWO_PI*(( (9) + current_hr )*HOUR_INC)); rotateX(TWO_PI*( radian_percentage )); if (i==int(current_hr)) { /* highlights current time */ fill(255,102,0); } else { //fill(0,0,0,50); fill(0,0,0,0.5); } if (i==0) { /* ads a zero */ text("12", 0, 0); } else if (i<10) { text("0"+i, 0, 0); } else { text(""+i, 0, 0); } popMatrix(); } popMatrix(); // ************************************************************************ // mouse press initializer // ************************************************************************ if (mouseStatus == true && priorMouseStatus == false) { priorMouseStatus = true; // ************************************************************************ // mouse press looper // ************************************************************************ } else if (mouseStatus == true && priorMouseStatus == true) { priorMouseStatus = true; // ************************************************************************ // mouse release initializer // ************************************************************************ } else if (mouseStatus == false && priorMouseStatus == true) { priorMouseStatus = false; // ************************************************************************ // mouse release looper // ************************************************************************ } else if (mouseStatus == false && priorMouseStatus == false) { priorMouseStatus = false; } } } } Uncontrol's Clock 移植版