Skip to content

Instantly share code, notes, and snippets.

@beautyfree
Created February 14, 2018 23:55
Show Gist options
  • Save beautyfree/2756718187c656e36e7b3fe42d608894 to your computer and use it in GitHub Desktop.
Save beautyfree/2756718187c656e36e7b3fe42d608894 to your computer and use it in GitHub Desktop.
const fs = require('fs')
const path = require('path')
const { createCanvas, loadImage } = require('canvas')
const canvas = createCanvas(640, 1136)
const ctx = canvas.getContext('2d')
//ctx.fillStyle = 'rgba(235,133,190,1)'
ctx.fillStyle = 'rgba(242,228,231,1)'
ctx.fillRect(0, 0, 640, 1136)
const format = (num) => num.toString().padStart(2,'0')
const time = (hour, second, debug='') => {
if (second < 0) {
second = 60+second
} else if(second >= 60) {
second = second-60
}
return `${format(hour)}:${format(second)}${debug}`
}
const loopthrow = (bday, bmonth, h, s, map) => {
const bsum = bday+bmonth;
const materials = [
[bday, bmonth, bsum],
[bmonth, bday, bsum],
[bsum, bday, bmonth]
]
materials.forEach((material) => {
let [x, y, z] = material;
let operations = [y, z, 60-x, 60-y, 60-z]
operations.forEach((o) => {
if((h+s)==x) {
map.add(time(h,o-s))
}
if((h-s)==x) {
map.add(time(h,o+s))
}
})
});
}
let your_time = new Set()
const bday = 16;
const bmonth = 6;
for(let t=0; t<24; t++) {
// if(t==bday) {
// your_time.add(time(t,0))
// }
// if(t==bmonth) {
// your_time.add(time(t,0))
// }
// if(t==bday+bmonth) {
// your_time.add(time(t,0))
// }
// if(t==bday) {
// your_time.add(time(t,t))
// }
// if(t==bmonth) {
// your_time.add(time(t,t))
// }
// if(t==bday+bmonth) {
// your_time.add(time(t,t))
// }
for(let n=0; n<=60; n++) {
loopthrow(bday, bmonth, t, n, your_time)
// if((t+n)==bday) {
// your_time.add(time(t,n)) // 00:16 01:15 02:14 03:13
// }
// if((t+n)==bday) {
// your_time.add(time(t,bmonth-n))
// }
// if((t-n)==bday) {
// your_time.add(time(t,bmonth+n))
// }
// if((t+n)==bday) {
// your_time.add(time(t,bsum-n))
// }
// if((t-n)==bday) {
// your_time.add(time(t,bsum+n))
// }
// if((t+n)==bday) {
// your_time.add(time(t,60-bday-n))
// }
// if((t-n)==bday) {
// your_time.add(time(t,60-bday+n))
// }
// if((t+n)==bday) {
// your_time.add(time(t,60-bmonth-n))
// }
// if((t-n)==bday) {
// your_time.add(time(t,60-bmonth+n))
// }
// HARD
// if((t+n)==bday) {
// your_time.add(time(t,60-bsum-n))
// }
// if((t-n)==bday) {
// your_time.add(time(t,60-bsum+n))
// }
// // HARD
// if((t-n)==bmonth) {
// your_time.add(time(t,bday+n))
// }
// if((t+n)==bmonth) {
// your_time.add(time(t,bday-n))
// }
// // HARD
// if((t+n)==bmonth) {
// your_time.add(time(t,bsum-n))
// }
// if((t-n)==bmonth) {
// your_time.add(time(t,bsum+n))
// }
// if((t+n)==bmonth) {
// your_time.add(time(t,60-bday-n))
// }
// if((t-n)==bmonth) {
// your_time.add(time(t,60-bday+n))
// }
// // HARD
// if((t+n)==bmonth) {
// your_time.add(time(t,60-bmonth-n))
// }
// if((t-n)==bmonth) {
// your_time.add(time(t,60-bmonth+n))
// }
// // HARD
// if((t+n)==bmonth) {
// your_time.add(time(t,60-bsum-n))
// }
// if((t-n)==bmonth) {
// your_time.add(time(t,60-bsum+n))
// }
// if((t+n)==bsum) {
// your_time.add(time(t,bday-n))
// }
// if((t-n)==bsum) {
// your_time.add(time(t,bday+n))
// }
// if((t+n)==bsum) {
// your_time.add(time(t,bmonth-n))
// }
// if((t-n)==bsum) {
// your_time.add(time(t,bmonth+n))
// }
// if((t+n)==bsum) {
// your_time.add(time(t,60-bday-n))
// }
// if((t-n)==bsum) {
// your_time.add(time(t,60-bday+n))
// }
// // HARD
// if((t+n)==bsum) {
// your_time.add(time(t,60-bmonth-n))
// }
// if((t-n)==bsum) {
// your_time.add(time(t,60-bmonth+n))
// }
// // HARD
// if((t+n)==bsum) {
// your_time.add(time(t,60-bsum-n))
// }
// if((t-n)==bsum) {
// your_time.add(time(t,60-bsum+n))
// }
// if((t+n)==16) {
// console.log(`%c ${t}:${25-n}`, 'color: green')
// }
// if((t+n)==22) {
// console.log(`%c ${t}:${37-n}`, 'color: pink')
// }
// if((t+n)==25) {
// console.log(`%c ${t}:${48-n}`, 'color: blue')
// }
// if((t-n)==12) {
// console.log(`%c ${t}:${25+n}`, 'color: black')
// }
// // Both
// if((t+n)==16) {
// your_time.add(time(t,27-n))
// }
// if((t+n)==22) {
// your_time.add(time(t,35-n))
// }
// // He
// if((t+n)==27) {
// your_time.add(time(t,52-n))
// }
// if((t-n)==8) {
// your_time.add(time(t,27+n))
// }
}
}
your_time = new Map([...your_time.entries()].sort())
// 640*1136
// 174
// 6 29
ctx.font = '20px Impact'
//ctx.fillStyle = 'rgba(241,82,171,1)'
ctx.fillStyle = 'rgba(219,186,186,1)'
const len = your_time.size
console.log(len)
let row = 1;
let column = 1;
your_time.forEach((value) => {
console.log(value)
ctx.fillText(value, column*70-20, row*33+15)
if(row==33) {
column++;
row=1;
} else {
row++;
}
})
// Write "Awesome!"
// ctx.font = '30px Impact'
// ctx.fillText('Awesome!', 50, 100)
// Draw line under text
// var text = ctx.measureText('Awesome!')
// ctx.strokeStyle = 'rgba(0,0,0,0.5)'
// ctx.beginPath()
// ctx.lineTo(50, 102)
// ctx.lineTo(50 + text.width, 102)
// ctx.stroke()
canvas.createPNGStream({backgroundIndex: 1}).pipe(fs.createWriteStream(path.join(__dirname, 'text.png')))
// // Draw cat with lime helmet
// loadImage('lime-cat.jpg').then((image) => {
// ctx.drawImage(image, 50, 0, 70, 70)
// console.log('<img src="' + canvas.toDataURL() + '" />')
// });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment