Skip to content

Commit 4e34941

Browse files
committed
Add ajiDate
1 parent a5cc240 commit 4e34941

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed

example/clock/main.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
function loop() {
2-
const date = new Date();
32
ajiSetLineCap("round");
43
ajiFillRect(0, 0, AJIPACK_WIDTH, AJIPACK_HEIGHT, "#ffffcc");
54
ajiFillCircle(
@@ -22,12 +21,12 @@ function loop() {
2221
AJIPACK_WIDTH / 2 +
2322
50 *
2423
Math.sin(
25-
(date.getHours() * Math.PI) / 6 + (date.getMinutes() * Math.PI) / 360
24+
(ajiGetHours() * Math.PI) / 6 + (ajiGetMinutes() * Math.PI) / 360
2625
),
2726
AJIPACK_HEIGHT / 2 -
2827
50 *
2928
Math.cos(
30-
(date.getHours() * Math.PI) / 6 + (date.getMinutes() * Math.PI) / 360
29+
(ajiGetHours() * Math.PI) / 6 + (ajiGetMinutes() * Math.PI) / 360
3130
),
3231
"#0000cc",
3332
12
@@ -38,28 +37,26 @@ function loop() {
3837
AJIPACK_WIDTH / 2 +
3938
80 *
4039
Math.sin(
41-
(date.getMinutes() * Math.PI) / 30 +
42-
(date.getSeconds() * Math.PI) / 1800
40+
(ajiGetMinutes() * Math.PI) / 30 + (ajiGetSeconds() * Math.PI) / 1800
4341
),
4442
AJIPACK_HEIGHT / 2 -
4543
80 *
4644
Math.cos(
47-
(date.getMinutes() * Math.PI) / 30 +
48-
(date.getSeconds() * Math.PI) / 1800
45+
(ajiGetMinutes() * Math.PI) / 30 + (ajiGetSeconds() * Math.PI) / 1800
4946
),
5047
"#0000cc",
5148
6
5249
);
5350
ajiLine(
5451
AJIPACK_WIDTH / 2,
5552
AJIPACK_HEIGHT / 2,
56-
AJIPACK_WIDTH / 2 + 90 * Math.sin((date.getSeconds() * Math.PI) / 30),
57-
AJIPACK_HEIGHT / 2 - 90 * Math.cos((date.getSeconds() * Math.PI) / 30),
53+
AJIPACK_WIDTH / 2 + 90 * Math.sin((ajiGetSeconds() * Math.PI) / 30),
54+
AJIPACK_HEIGHT / 2 - 90 * Math.cos((ajiGetSeconds() * Math.PI) / 30),
5855
"#ff0000",
5956
2
6057
);
6158
ajiSetFont("14px sans-serif");
6259
ajiSetFillColor("black");
63-
ajiDrawAlignText(date.toLocaleDateString(), 0, 180, AJIPACK_WIDTH, "center");
64-
ajiDrawAlignText(date.toLocaleTimeString(), 0, 200, AJIPACK_WIDTH, "center");
60+
ajiDrawAlignText(ajiGetDateString(), 0, 180, AJIPACK_WIDTH, "center");
61+
ajiDrawAlignText(ajiGetTimeString(), 0, 200, AJIPACK_WIDTH, "center");
6562
}

player.js

+50
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Licensed under the MIT License
77
const AJIPACK_WIDTH = 320;
88
const AJIPACK_HEIGHT = 240;
99
const AJIPACK_FPS = 33.0;
10+
let ajiDate = new Date();
1011
let ajiDrawTime = Date.now();
1112
let ajiCanvas, ajiContext, ajiVideo;
1213
let ajiBG = [new Image(), new Image(), new Image(), new Image()];
@@ -44,6 +45,7 @@ function ajiInit() {
4445
}
4546

4647
function ajiMain() {
48+
ajiDate = new Date();
4749
const ajiNowTime = Date.now();
4850
if (ajiNowTime - ajiDrawTime >= 1000 / AJIPACK_FPS) {
4951
ajiDrawTime = ajiNowTime;
@@ -155,6 +157,8 @@ function ajiDrawAlignText(text, x, y, w, align) {
155157
}
156158
}
157159

160+
// BG
161+
158162
async function ajiSetBG(id, src) {
159163
if (ajiExistData(src) == true) {
160164
await new Promise((resolve, reject) => {
@@ -179,6 +183,8 @@ async function ajiAddSprite(id, src) {
179183
}
180184
}
181185

186+
// Sprite
187+
182188
function ajiGetSprite(id) {
183189
for (let i = 0; i < ajiSprite.length; i++) {
184190
if (ajiSprite[i].id == id) {
@@ -233,6 +239,8 @@ function ajiDrawSpriteZoom(id, x, y, w, h) {
233239
}
234240
}
235241

242+
// Audio
243+
236244
async function ajiAddAudio(id, src) {
237245
if (ajiExistAudio(id) == false) {
238246
ajiAudio.push({
@@ -297,6 +305,8 @@ function ajiStopAudio(id) {
297305
ajiAudio[ajiFindAudioNumber(id)].source.stop();
298306
}
299307

308+
// Video
309+
300310
async function ajiLoadVideo(src) {
301311
if (ajiExistData(src) == true) {
302312
await new Promise((resolve, reject) => {
@@ -331,6 +341,8 @@ function ajiSetVideoCurrentTime(time) {
331341
ajiVideo.currentTime = time;
332342
}
333343

344+
// Mouse
345+
334346
function ajiMouseX() {
335347
return ajiMouse.x;
336348
}
@@ -357,3 +369,41 @@ function ajiClick() {
357369
return false;
358370
}
359371
}
372+
373+
// Date & Time
374+
375+
function ajiGetYear() {
376+
return ajiDate.getFullYear();
377+
}
378+
379+
function ajiGetMonth() {
380+
return ajiDate.getMonth() + 1;
381+
}
382+
383+
function ajiGetDate() {
384+
return ajiDate.getDate();
385+
}
386+
387+
function ajiGetDay() {
388+
return ajiDate.getDay();
389+
}
390+
391+
function ajiGetHours() {
392+
return ajiDate.getHours();
393+
}
394+
395+
function ajiGetMinutes() {
396+
return ajiDate.getMinutes();
397+
}
398+
399+
function ajiGetSeconds() {
400+
return ajiDate.getSeconds();
401+
}
402+
403+
function ajiGetDateString() {
404+
return ajiDate.toLocaleDateString();
405+
}
406+
407+
function ajiGetTimeString() {
408+
return ajiDate.toLocaleTimeString();
409+
}

0 commit comments

Comments
 (0)