当前位置:首页 > 代码 > 正文

漂亮的时钟(有代码可直接复制)(代码时钟怎么做)

admin 发布:2022-12-19 23:16 115


今天给各位分享漂亮的时钟(有代码可直接复制)的知识,其中也会对代码时钟怎么做进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

问个难的~如何制作透明时钟

用VB嘛。。是好难啊。。

不过还好。。。出来了。。透明的时英钟

代码如下,直接复制就可以了。

'/////////////////////////////////

'小闹钟示例

'

'在窗体中添加一个timer控件,将interval设为1000以下。

'////////////////////////////////

option explicit

const pi = 3.1415926

dim basex as integer, basey as integer, r as integer

dim r1 as integer, r2 as integer, r3 as integer

private sub form_load()

me.scalemode = 3

me.autoredraw = true

if me.width 3000 then me.width = 3000

if me.height 3000 then me.height = 3000

end sub

private sub init()

dim i as integer

basex = me.scalewidth / 2

basey = me.scaleheight / 2

r = iif(basex basey, basey * 0.8, basey * 0.8)

r1 = r * 0.2

r2 = r * 0.1

r3 = r * 0.05

for i = 0 to 360 step 6

if i mod 30 = 0 then '时

me.drawwidth = 2

drawline basex + (r - 3) * sin(i * pi / 180), basey - (r - 3) * cos(i * pi / 180), basex + (r - 8) * sin(i * pi / 180), basey - (r - 8) * cos(i * pi / 180), 3

else '分

me.drawwidth = 2

me.pset (basex + (r - 3) * sin(i * pi / 180), basey - (r - 3) * cos(i * pi / 180))

end if

next

me.drawwidth = 1

me.circle (basex, basey), r

end sub

'绘制指针

private sub drawclock()

dim second as integer

dim minute as integer

dim hours as integer

second = datepart("s", time)

minute = datepart("n", time)

hours = datepart("h", time)

if hours 12 then

hours = hours - 12

end if

me.drawwidth = 1

me.circle (basex, basey), 4

drawline basex - r1 * sin(second * pi / 30), basey + r1 * cos(second * pi / 30), basex + (r - 10) * sin(second * pi / 30), basey - (r - 10) * cos(second * pi / 30), 0

drawline basex - r2 * sin(minute * pi / 30), basey + r2 * cos(minute * pi / 30), basex + r * 0.8 * sin(minute * pi / 30), basey - r * 0.8 * cos(minute * pi / 30), 1

drawline basex - r3 * sin((hours + minute / 60) * pi / 6), basey + r3 * cos((hours + minute / 60) * pi / 6), basex + r * 0.6 * sin((hours + minute / 60) * pi / 6), basey - r * 0.6 * cos((hours + minute / 60) * pi / 6), 2

end sub

'画线函数

private sub drawline(x1 as integer, y1 as integer, x2 as integer, y2 as integer, flag as integer)

static oldsx1 as integer, oldsx2 as integer, oldsy1 as integer, oldsy2 as integer

static oldmx1 as integer, oldmx2 as integer, oldmy1 as integer, oldmy2 as integer

static oldhx1 as integer, oldhx2 as integer, oldhy1 as integer, oldhy2 as integer

select case flag

case 0

me.drawwidth = 1

me.line (oldsx1, oldsy1)-(oldsx2, oldsy2), me.backcolor

me.line (x1, y1)-(x2, y2)

oldsx1 = x1

oldsx2 = x2

oldsy1 = y1

oldsy2 = y2

case 1

me.drawwidth = 2

me.line (oldmx1, oldmy1)-(oldmx2, oldmy2), me.backcolor

me.line (x1, y1)-(x2, y2)

oldmx1 = x1

oldmx2 = x2

oldmy1 = y1

oldmy2 = y2

case 2

me.drawwidth = 3

me.line (oldhx1, oldhy1)-(oldhx2, oldhy2), me.backcolor

me.line (x1, y1)-(x2, y2)

oldhx1 = x1

oldhx2 = x2

oldhy1 = y1

oldhy2 = y2

case else

me.line (x1, y1)-(x2, y2)

end select

end sub

private sub form_resize()

me.cls

call init

end sub

private sub timer1_timer()

call drawclock

end sub

要个简单一点的小时钟代码~

这个是文字时钟代码:

script

var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")

var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")

function getthedate(){

var mydate=new Date()

var year=mydate.getYear()

if (year 1000)

year+=1900

var day=mydate.getDay()

var month=mydate.getMonth()

var daym=mydate.getDate()

if (daym10)

daym="0"+daym

var hours=mydate.getHours()

var minutes=mydate.getMinutes()

var seconds=mydate.getSeconds()

var dn="AM"

if (hours=12)

dn="PM"

if (hours12){

hours=hours-12

}

if (hours==0)

hours=12

if (minutes=9)

minutes="0"+minutes

if (seconds=9)

seconds="0"+seconds

//change font size here

var cdate="smallfont color='000000' face='Arial'b"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn

+"/b/font/small"

if (document.all)

document.all.clock.innerHTML=cdate

else

document.write(cdate)

}

if (!document.all)

getthedate()

function goforit(){

if (document.all)

setInterval("getthedate()",1000)

}

/script

body onload="goforit()"

span id="clock"/span

用Flash制作精巧的时钟

时钟是日常生活中必备的物品,有了它我们才可以有计划的进行学习和工作.这次我们用Flash来制作一个精美的小时钟,你可以把它拖到电脑屏幕的一角,使工作中的你可以方便的查看当前时间和日期.

本实例最终效果如图1所示;

图1

时钟的最终效果

1.首先启动Flash,新建一个影片,设置影片舞台大小为270px*320px(单位为象素),背景颜色为灰色,颜色代码为#CCCCCC.

2.首先制作时钟里的时针.新建一个影片剪辑元件,命名为hours,进入元件的编辑区后,使用矩形工具绘制一个细长的无边框的矩形,填充色为灰色,颜色代码为#999999,如图2所示;

图2

制作时针

3.然后制作时钟里的分针.新建一个影片剪辑元件,命名为minutes,进入元件的编辑区后,使用矩形工具绘制一个细长的无边框的矩形,填充色为深灰色,颜色代码为#666666,如图3所示;

图3

制作分针

4.最后制作时钟里的秒针.新建一个影片剪辑元件,命名为seconds,进入元件的编辑区后,使用矩形工具绘制一个细长的无边框的矩形,填充色为红色,颜色代码为#FF0000,如图4所示;

图4

制作秒针

5.新建一个图形元件,命名为outeregde,进入元件的编辑区后,使用前面实例中介绍的方法制作一个圆环,填充色为灰色,颜色代码为#999999,用作时钟的边框,如图5所示;

图5

制作时钟的边框

6.回到主场景中,将影片默认的图层Layer1重命名为outeredge,然后将元件outeregde拖到舞台上,调整其位置到舞台的中央.

7.新建一个图层numbers,使用文本工具分别输入从1到12这12个数字,并绕着时钟边框排列其位置,如图6所示;

图6

添加时间数字

8.新建一个图层clockhands,分别将元件Hours,

minutes和Seconds拖到场景中,然后使用椭圆工具绘制一个黑色无边框的正圆,将其放置在表盘的中心,然后分别将时针,分针和秒针放到表盘的中心,使三个表针的下部和中心位置对齐,如图7所示;

图7

在表盘中添加表针

9.添加图层pagetitle,使用工具分别绘制一个静态文本框和一个动态文本框,在静态文本框中输入时钟的标签:flash时钟,设置动态文本框的文本变量名为time,用来动态显示年,月,日和星期.

10.最后添加一个图层命名为Action,设置控制时钟运行的Action脚本.

在第1帧添加如下Action:

time

=

new

Date();//定义time为Date日期对象

hours

=

time.getHours();//取得当前系统的小时,并赋给变量hours

minutes

=

time.getMinutes();//取得当前系统的分钟,并赋给变量minutes

seconds

=

time.getSeconds();//取得当前系统的秒钟,并赋给变量seconds

if

(hours12)

{

hours

=

hours-12;

}

if

(hours1)

{

hours

=

12;

}

hours

=

hours*30+int(minutes/2);

minutes

=

minutes*6+int(seconds/10);

seconds

=

seconds*6;

在第2帧添加如下Action:

gotoAndPlay(1);

11.最后一步是给三个表针添加各自的Action,使其可以按照自己的规律进行旋转

给时针添加如下Action:

onClipEvent

(enterFrame)

{

setProperty(this,

_rotation,

_root.hours);

}

给分针添加如下Action;

onClipEvent

(enterFrame)

{

setProperty(this,

_rotation,

_root.minutes);

}

给秒针添加如下Action:

onClipEvent

(enterFrame)

{

setProperty(this,

_rotation,

_root.seconds);

}

漂亮的时钟(有代码可直接复制)的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于代码时钟怎么做、漂亮的时钟(有代码可直接复制)的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/29654.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载