CanvasArtist.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. export var Picture = {}
  2. Picture.Bone = function (ctx, options) {
  3. let width = options.width
  4. let height = options.height
  5. ctx.fillStyle = "white"
  6. ctx.beginPath()
  7. ctx.arc(2 * width / 8, 7 * height / 8, width/16, 0, 2 * Math.PI)
  8. ctx.fill()
  9. ctx.beginPath()
  10. ctx.arc(1 * width / 8, 6 * height / 8, width/16, 0, 2 * Math.PI)
  11. ctx.fill()
  12. ctx.beginPath()
  13. ctx.arc(7 * width / 8, 2 * height / 8, width/16, 0, 2 * Math.PI)
  14. ctx.fill()
  15. ctx.beginPath()
  16. ctx.arc(6 * width / 8, 1 * height / 8, width/16, 0, 2 * Math.PI)
  17. ctx.fill()
  18. ctx.beginPath()
  19. ctx.moveTo(2 * width / 8 - 2, 7 * height / 8)
  20. ctx.lineTo(7 * width / 8 - 2, 2 * height / 8)
  21. ctx.lineTo(6 * width / 8 + 2, 1 * height / 8)
  22. ctx.lineTo(1 * width / 8 + 2, 6 * height / 8)
  23. ctx.closePath()
  24. ctx.fill()
  25. }
  26. Picture.DashHead = function (ctx, options) {
  27. ctx.fillStyle = "#272935"
  28. ctx.beginPath()
  29. ctx.moveTo(-5, -27)
  30. ctx.lineTo(30, -23)
  31. ctx.lineTo(10, 23)
  32. ctx.lineTo(3, 20)
  33. ctx.closePath()
  34. ctx.fill()
  35. ctx.fillStyle = "#31333F"
  36. ctx.beginPath()
  37. ctx.arc(0, 0, 25, 0, 2 * Math.PI)
  38. ctx.fill()
  39. ctx.fillStyle = "black"
  40. ctx.beginPath()
  41. ctx.ellipse(12, -8, 4, 8, 0, 0, 2 * Math.PI)
  42. ctx.fill()
  43. ctx.fillStyle = "white"
  44. ctx.beginPath()
  45. ctx.arc(13, -9, 2, 0, 2 * Math.PI)
  46. ctx.fill()
  47. ctx.fillStyle = "#31333F"
  48. ctx.beginPath()
  49. ctx.moveTo(0, -9)
  50. ctx.lineTo(20, -7)
  51. ctx.lineTo(35, -2)
  52. ctx.arc(35, 8, 10, -Math.PI / 2, Math.PI / 2)
  53. ctx.lineTo(0, 20)
  54. ctx.closePath()
  55. ctx.fill()
  56. ctx.fillStyle = "black"
  57. ctx.beginPath()
  58. ctx.arc(35, 8, 10, -Math.PI / 2, 0)
  59. ctx.lineTo(35, 5)
  60. ctx.closePath()
  61. ctx.fill()
  62. ctx.beginPath()
  63. ctx.ellipse(-4, -8, 4, 8, 0, 0, 2 * Math.PI)
  64. ctx.fill()
  65. ctx.fillStyle = "white"
  66. ctx.beginPath()
  67. ctx.arc(-3, -8, 2, 0, 2 * Math.PI)
  68. ctx.fill()
  69. ctx.fillStyle = "#BC6439"
  70. ctx.beginPath()
  71. ctx.moveTo(20, 9)
  72. ctx.lineTo(40, 10)
  73. ctx.arc(35, 8, 10, Math.PI / 8, Math.PI / 2)
  74. ctx.lineTo(4, 20)
  75. ctx.closePath()
  76. ctx.fill()
  77. ctx.fillStyle = "#3A3C4A"
  78. ctx.beginPath()
  79. ctx.moveTo(-35, -24)
  80. ctx.lineTo(0, -27)
  81. ctx.lineTo(-20, 23)
  82. ctx.lineTo(-27, 20)
  83. ctx.closePath()
  84. ctx.fill()
  85. }
  86. Picture.DogHead1 = function (ctx, options) {
  87. ctx.fillStyle = "#AC5429"
  88. ctx.beginPath()
  89. ctx.moveTo(-5, -27)
  90. ctx.lineTo(30, -23)
  91. ctx.lineTo(10, 23)
  92. ctx.lineTo(3, 20)
  93. ctx.closePath()
  94. ctx.fill()
  95. ctx.fillStyle = "#BC6439"
  96. ctx.beginPath()
  97. ctx.arc(0, 0, 25, 0, 2 * Math.PI)
  98. ctx.fill()
  99. ctx.fillStyle = "black"
  100. ctx.beginPath()
  101. ctx.ellipse(12, -8, 4, 8, 0, 0, 2 * Math.PI)
  102. ctx.fill()
  103. ctx.fillStyle = "white"
  104. ctx.beginPath()
  105. ctx.arc(13, -9, 2, 0, 2 * Math.PI)
  106. ctx.fill()
  107. ctx.fillStyle = "#BC6439"
  108. ctx.beginPath()
  109. ctx.moveTo(0, -9)
  110. ctx.lineTo(10, -7)
  111. ctx.lineTo(25, -2)
  112. ctx.arc(25, 8, 10, -Math.PI / 2, Math.PI / 2)
  113. ctx.lineTo(3, 25)
  114. ctx.closePath()
  115. ctx.fill()
  116. ctx.fillStyle = "black"
  117. ctx.beginPath()
  118. ctx.arc(25, 8, 10, -Math.PI / 2, 0)
  119. ctx.lineTo(25, 5)
  120. ctx.closePath()
  121. ctx.fill()
  122. ctx.beginPath()
  123. ctx.ellipse(-4, -8, 4, 8, 0, 0, 2 * Math.PI)
  124. ctx.fill()
  125. ctx.fillStyle = "white"
  126. ctx.beginPath()
  127. ctx.arc(-3, -8, 2, 0, 2 * Math.PI)
  128. ctx.fill()
  129. ctx.fillStyle = "#CC7449"
  130. ctx.beginPath()
  131. ctx.moveTo(-35, -24)
  132. ctx.lineTo(0, -27)
  133. ctx.lineTo(-20, 23)
  134. ctx.lineTo(-27, 20)
  135. ctx.closePath()
  136. ctx.fill()
  137. }
  138. Picture.DogHead2 = function (ctx, options) {
  139. ctx.fillStyle = "rgb(91, 80, 68)"
  140. ctx.beginPath()
  141. ctx.moveTo(-5, -27)
  142. ctx.lineTo(30, -23)
  143. ctx.lineTo(10, 23)
  144. ctx.lineTo(3, 20)
  145. ctx.closePath()
  146. ctx.fill()
  147. ctx.fillStyle = "rgb(245, 251, 239)"
  148. ctx.beginPath()
  149. ctx.arc(0, 0, 25, 0, 2 * Math.PI)
  150. ctx.fill()
  151. ctx.fillStyle = "black"
  152. ctx.beginPath()
  153. ctx.ellipse(12, -8, 4, 8, 0, 0, 2 * Math.PI)
  154. ctx.fill()
  155. ctx.fillStyle = "white"
  156. ctx.beginPath()
  157. ctx.arc(13, -9, 2, 0, 2 * Math.PI)
  158. ctx.fill()
  159. ctx.fillStyle = "rgb(245, 251, 239)"
  160. ctx.beginPath()
  161. ctx.moveTo(0, -9)
  162. ctx.lineTo(10, -7)
  163. ctx.lineTo(25, -2)
  164. ctx.arc(25, 8, 10, -Math.PI / 2, Math.PI / 2)
  165. ctx.lineTo(3, 25)
  166. ctx.closePath()
  167. ctx.fill()
  168. ctx.fillStyle = "rgb(107, 96, 84)"
  169. ctx.beginPath()
  170. ctx.arc(7, 0, 4, 0, 2 * Math.PI)
  171. ctx.fill()
  172. ctx.fillStyle = "rgb(107, 96, 84)"
  173. ctx.beginPath()
  174. ctx.arc(7, 20, 8, 3 * Math.PI / 4, Math.PI / 12)
  175. ctx.fill()
  176. ctx.fillStyle = "black"
  177. ctx.beginPath()
  178. ctx.arc(25, 8, 10, -Math.PI / 2, 0)
  179. ctx.lineTo(25, 5)
  180. ctx.closePath()
  181. ctx.fill()
  182. ctx.beginPath()
  183. ctx.ellipse(-4, -8, 4, 8, 0, 0, 2 * Math.PI)
  184. ctx.fill()
  185. ctx.fillStyle = "white"
  186. ctx.beginPath()
  187. ctx.arc(-3, -8, 2, 0, 2 * Math.PI)
  188. ctx.fill()
  189. ctx.fillStyle = "rgb(123, 112, 100)"
  190. ctx.beginPath()
  191. ctx.moveTo(-35, -24)
  192. ctx.lineTo(0, -27)
  193. ctx.lineTo(-20, 23)
  194. ctx.lineTo(-27, 20)
  195. ctx.closePath()
  196. ctx.fill()
  197. }
  198. Picture.DirtBlock = function (ctx, options) {
  199. let width = options.width
  200. let height = options.height
  201. ctx.fillStyle = "#823c0a"
  202. ctx.roundRect(0, 0, width, height, 8)
  203. ctx.fill()
  204. ctx.strokeStyle = "#82540a"
  205. ctx.roundRect(0, 0, width - 2, height - 2, 8)
  206. ctx.stroke()
  207. ctx.fillStyle = "#82540a"
  208. ctx.roundRect(3 * width / 8, 2 * height / 8, 2 * width / 8, 1 * height / 8, 8)
  209. ctx.fill()
  210. ctx.fillStyle = "#82540a"
  211. ctx.roundRect(4 * width / 8 + 1, 3 * height / 8 + 1, 2 * width / 8, 1 * height / 8, 8)
  212. ctx.fill()
  213. }
  214. Picture.GrassBlock = function (ctx, options) {
  215. let width = options.width
  216. let height = options.height
  217. Picture.DirtBlock(ctx, { width, height })
  218. ctx.fillStyle = "#167a04"
  219. ctx.roundRect(0, 0, width, height / 6, 8)
  220. ctx.fill()
  221. ctx.fillStyle = "#517a04"
  222. ctx.beginPath()
  223. ctx.moveTo(5 * width / 8, 0)
  224. ctx.lineTo(7 * width / 8, 0)
  225. ctx.lineTo(6 * width / 8, height / 6)
  226. ctx.closePath()
  227. ctx.fill()
  228. ctx.beginPath()
  229. ctx.moveTo(1 * width / 8, 0)
  230. ctx.lineTo(3 * width / 8, 0)
  231. ctx.lineTo(2 * width / 8, height / 6)
  232. ctx.closePath()
  233. ctx.fill()
  234. ctx.beginPath()
  235. ctx.moveTo(3 * width / 8, height / 6)
  236. ctx.lineTo(5 * width / 8, height / 6)
  237. ctx.lineTo(4 * width / 8, 0)
  238. ctx.closePath()
  239. ctx.fill()
  240. ctx.strokeStyle = "#517a04"
  241. ctx.roundRect(0, 0, width, height / 6, 8)
  242. ctx.stroke()
  243. }
  244. Picture.DirtBoneBlock = function (ctx, options) {
  245. let width = options.width
  246. let height = options.height
  247. Picture.DirtBlock(ctx, { width, height })
  248. Picture.Bone(ctx, { width, height })
  249. }
  250. Picture.Cameo = function(ctx, options) {
  251. let width = options.width
  252. var grd = ctx.createLinearGradient(0, 0, 0, 150);
  253. grd.addColorStop(0, "#573815");
  254. grd.addColorStop(1, "#261e15");
  255. ctx.fillStyle = grd
  256. ctx.beginPath()
  257. ctx.ellipse(0,0, width, width * 1.25, 0, 0, 2 * Math.PI)
  258. ctx.fill()
  259. ctx.fillStyle = "#494949"
  260. ctx.beginPath()
  261. ctx.ellipse(0,0, width * 0.9, (width * 1.25)* 0.9, 0, 0, 2 * Math.PI)
  262. ctx.fill()
  263. ctx.save()
  264. ctx.scale(2, 2)
  265. Picture.DashHead(ctx, {})
  266. ctx.restore()
  267. }
  268. Picture.DigPlayer = function(ctx, options) {
  269. ctx.fillStyle = "#3A3C4A"
  270. ctx.beginPath()
  271. ctx.arc(-6, 0, 8, Math.PI, (3 * Math.PI) / 2)
  272. ctx.lineTo(6, -8)
  273. ctx.arc(6, 0, 8, (3 * Math.PI) / 2, 2 * Math.PI)
  274. ctx.lineTo(18, 28)
  275. ctx.lineTo(-18, 28)
  276. ctx.closePath()
  277. ctx.fill()
  278. ctx.save()
  279. ctx.translate(0, -16)
  280. ctx.scale(0.7, 0.7)
  281. Picture.DashHead(ctx, options)
  282. ctx.restore()
  283. }
  284. Picture.Skull = function(ctx, options) {
  285. let width = options.width
  286. let height = options.height
  287. ctx.fillStyle = "white"
  288. ctx.beginPath()
  289. ctx.arc(0,0, width/ 3, 0, 2 * Math.PI)
  290. ctx.fill()
  291. ctx.beginPath()
  292. ctx.roundRect(-width/12,height/8,width /3, height /3,2)
  293. ctx.fill()
  294. ctx.fillStyle = "black"
  295. ctx.beginPath()
  296. ctx.arc(0,0,6,0, 2 * Math.PI)
  297. ctx.fill()
  298. ctx.beginPath()
  299. ctx.arc(width/4,0,6,0, 2 * Math.PI)
  300. ctx.fill()
  301. ctx.strokeStyle = "black"
  302. ctx.beginPath()
  303. ctx.moveTo(0,0.3 * height)
  304. ctx.lineTo(0, 0.45 * height)
  305. ctx.stroke()
  306. ctx.beginPath()
  307. ctx.moveTo(0.1 * width,0.3 * height)
  308. ctx.lineTo(0.1 * width, 0.45 * height)
  309. ctx.stroke()
  310. ctx.beginPath()
  311. ctx.moveTo(0.2 * width,0.3 * height)
  312. ctx.lineTo(0.2 * width, 0.45 * height)
  313. ctx.stroke()
  314. ctx.beginPath()
  315. ctx.moveTo(0.13 * width,0.1* height)
  316. ctx.lineTo(0.18 * width, 0.2* height)
  317. ctx.lineTo(0.08 * width, 0.2* height)
  318. ctx.closePath()
  319. ctx.stroke()
  320. }
  321. Picture.DirtSkullBlock = function (ctx, options) {
  322. let width = options.width
  323. let height = options.height
  324. Picture.DirtBlock(ctx, { width, height })
  325. ctx.save()
  326. ctx.translate(width / 2, height /2)
  327. Picture.Skull(ctx, { width, height })
  328. ctx.restore()
  329. }
  330. Picture.Shovel = function(ctx, options) {
  331. let width = options.width
  332. let height = options.height
  333. ctx.fillStyle = "#823c0a"
  334. ctx.strokeStyle = "#823c0a"
  335. ctx.lineCap = "round"
  336. ctx.lineWidth = 4
  337. ctx.beginPath()
  338. ctx.moveTo(1/8 * width, 7/8 * height)
  339. ctx.lineTo(4/8 * width, 4/8 * height)
  340. ctx.stroke()
  341. ctx.fillStyle="gray"
  342. ctx.beginPath()
  343. ctx.moveTo(7/8 * width, 3/8* height)
  344. ctx.lineTo(5/8 * width, 5/8* height)
  345. ctx.lineTo(3/8* width, 3/8 * height)
  346. ctx.lineTo(5/8 * width, 1/8* height)
  347. ctx.arc(5/8 * width, 3/8 * height, 2/8 * width, -Math.PI /2, 0)
  348. ctx.closePath()
  349. ctx.fill()
  350. }
  351. Picture.Tombstone = function(ctx, options) {
  352. let width = options.width
  353. let height = options.height
  354. ctx.fillStyle="gray"
  355. ctx.beginPath()
  356. ctx.moveTo(6/8 * width, 3/8* height)
  357. ctx.lineTo(6/8 * width, 7/8* height)
  358. ctx.lineTo(2/8* width, 7/8 * height)
  359. ctx.lineTo(2/8 * width, 3/8* height)
  360. ctx.arc(4/8 * width, 3/8 * height, 2/8 * width, -Math.PI, 0)
  361. ctx.closePath()
  362. ctx.fill()
  363. ctx.fillStyle = "black"
  364. ctx.font = `14px sans-serif`
  365. ctx.textAlign = "center"
  366. ctx.fillText("xxx", 4/8 * width, 4/8 * height)
  367. }
  368. Picture.Diamond = function(ctx, options) {
  369. let width = options.width
  370. let height = options.height
  371. ctx.fillStyle = "#B4FFFD"
  372. ctx.beginPath()
  373. ctx.moveTo(2/8 * width, 3/8 * height)
  374. ctx.lineTo(3/8 * width, 1/8 * height)
  375. ctx.lineTo(4/8 * width, 3/8 * height)
  376. ctx.fill()
  377. ctx.fillStyle = "white"
  378. ctx.beginPath()
  379. ctx.moveTo(3/8 * width, 1/8 * height)
  380. ctx.lineTo((4.5)/8 * width, 1/8 * height)
  381. ctx.lineTo(4/8 * width, 3/8 * height)
  382. ctx.fill()
  383. ctx.fillStyle = "#4898B8"
  384. ctx.beginPath()
  385. ctx.moveTo((4.5)/8 * width, 1/8 * height)
  386. ctx.lineTo(5/8 * width, 3/8 * height)
  387. ctx.lineTo(4/8 * width, 3/8 * height)
  388. ctx.fill()
  389. ctx.fillStyle = "#B4FFFD"
  390. ctx.beginPath()
  391. ctx.moveTo((4.5)/8 * width, 1/8 * height)
  392. ctx.lineTo(6/8 * width, 1/8 * height)
  393. ctx.lineTo(5/8 * width, 3/8 * height)
  394. ctx.fill()
  395. ctx.fillStyle = "#61CAFB"
  396. ctx.beginPath()
  397. ctx.moveTo(6/8 * width, 1/8 * height)
  398. ctx.lineTo(7/8 * width, 3/8 * height)
  399. ctx.lineTo(5/8 * width, 3/8 * height)
  400. ctx.fill()
  401. ctx.fillStyle = "#B4FFFD"
  402. ctx.beginPath()
  403. ctx.moveTo(5/8 * width, 3/8 * height)
  404. ctx.lineTo(7/8 * width, 3/8 * height)
  405. ctx.lineTo((4.5)/8 * width, 6/8 * height)
  406. ctx.fill()
  407. ctx.fillStyle = "#61CAFB"
  408. ctx.beginPath()
  409. ctx.moveTo(5/8 * width, 3/8 * height)
  410. ctx.lineTo((4.5)/8 * width, 6/8 * height)
  411. ctx.lineTo(4/8 * width, 3/8 * height)
  412. ctx.fill()
  413. ctx.fillStyle = "#4898B8"
  414. ctx.beginPath()
  415. ctx.moveTo(4/8 * width, 3/8 * height)
  416. ctx.lineTo((4.5)/8 * width, 6/8 * height)
  417. ctx.lineTo(2/8 * width, 3/8 * height)
  418. ctx.fill()
  419. }
  420. Picture.DirtDiamondBlock = function (ctx, options) {
  421. let width = options.width
  422. let height = options.height
  423. Picture.DirtBlock(ctx, { width, height })
  424. ctx.save()
  425. ctx.translate(-1/12 * width, height / 6)
  426. Picture.Diamond(ctx, { width, height: height * 0.8 })
  427. ctx.restore()
  428. }