-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
922 lines (745 loc) · 30.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Mixlab送你一本人工智能书</title>
<script src="https://aframe.io/releases/0.8.2/aframe.min.js"></script>
</head>
<style>
.logo {
position: fixed;
bottom: 12px;
z-index: 99;
color: #252525;
font-weight: 600;
font-size: 15px;
padding: 12px;
display: flex;
flex-direction: column;
}
.logo img {
display: block;
width: 56px;
height: 56px;
}
#txt {
padding: 12px;
width: 70%;
}
#user {
position: fixed;
top: 0;
width: 100%;
z-index: 99;
background: #eee;
padding: 24px;
padding-top: 72px;
height: 100vh;
display: flex;
flex-direction: column;
}
input {
outline: 1px solid black;
height: 44px;
margin-top: 24px;
font-size: 24px;
padding: 24px;
width: 228px;
border: none;
}
.save_btn {
height: 44px;
background: black;
color: white;
font-size: 18px;
margin-top: 24px;
width: 72px;
position: fixed;
top: 24px;
right: 24px;
}
</style>
<body>
<div id="user">
<div>输入姓名,生成你的人工智能著作</div>
<input type="text" placeholder="例如 shadow">
<button onclick="start();" style="width: 140px;
background: rgba(0, 0, 0, 0.8);
height: 44px;
color: white;
margin-top: 24px;
outline: none;
border: none;
font-size: 18px;">生 成</button>
<!--<div style="font-size: 10px;margin-top: 8px;">生成后,移动手机寻找属于你的AI书籍</div>-->
</div>
<a-scene fog="type: linear; color:#eee" vr-mode-ui="enabled: false" keyboard-shortcuts="enterVR: false" style="display:none">
<a-assets>
<img id="cover">
<img id="cover_small">
</a-assets>
<a-entity position="0 0 0" camera="active:true;fov:45" look-controls="enabled:false;">
</a-entity>
<a-entity shadow="receive: true" geometry="primitive: box" light="type: point; intensity: 1.1">
<a-box position="0 0.6 -6.6" rotation="0 26 0" color="#ffffff" depth="0.4" height="3.5" width="2.3" id="bookCover">
<a-box position="-1.148 0 0" rotation="0 0 0" color="#4a4a4a" depth="0.4" height="3.5" width="0.01" id="bookCover_small"></a-box>
</a-box>
<!--
<a-box position="-1.81 2 -5.4" rotation="0 -45 0" color="#4a4a4a" depth="0.01" height="4" width="0.7"></a-box>-->
<a-entity light="type: point; intensity: 0.8; distance: 50; decay: 2" position="-4 4 -2.4"></a-entity>
</a-entity>
<a-box color="white" shadow="receive: false" position="0 -1.2 -4" rotation="0 45 0" depth="1240" height="0.1" width="1200"></a-box>
<a-sky color="#ECECEC"></a-sky>
</a-scene>
<div class="logo" style="display: none">
<div style="display:flex;">
<img src="./code.jpg" alt="" id="logo">
<div id="txt"></div>
</div>
<div style="font-size:12px;font-weight: 400;color:rgba(0, 0, 0, 0.8)">长按二维码制作你的AI书籍</div>
<button onclick="save();" class="save_btn">SAVE</button>
</div>
<script>
var t = getTitle(),
l = getLevel(),
c = getColors();
var isDone = 0;
var name = 'shadow 著';
function start() {
name = (document.querySelector('input').value || 'mixlab') + ' 著';
document.querySelector('a-scene').style.display = "block";
document.querySelector('#user').style.display = "none";
document.querySelector('.logo').style.display = "flex";
setTimeout(run, 500);
};
function getColors() {
var colors = [
["#240041", "#900048"],
["#1C1124", "#684656"],
["#394A51", "#7FA99B"],
["#22559C", "#F27370"],
["#FF6D24", "#4E413B"],
["#F0CA6D", '#F7F2C1'],
["#A13939", "#E75151"],
["#657DC4", "#838ED9"],
["#461B93", "#6A3CBC"],
["#4A3333", "#98D083"],
["#AD1457", "#F06292"],
["#18587A", "#FC624D"]
];
var index = Math.abs(Math.ceil(Math.random() * colors.length - 1));
return colors[index]
}
function getTitle() {
var titles = [{
zh: "人工智能基础",
en: ['Fundamentals of', 'Artificial Intelligence']
}, {
zh: "机器视觉基础",
en: ['Fundamentals of', 'Machine Vision']
}, {
zh: "深度学习基础",
en: ['Fundamentals of', 'Deep Learning']
}, {
zh: "机器学习基础",
en: ['Fundamentals of', 'Machine Learning']
}, {
zh: "自然语言处理基础",
en: ['Fundamentals of', 'Natural Language Processing']
}];
var index = Math.abs(Math.ceil(Math.random() * titles.length - 1));
var title = {
texts: titles[index].zh.split(''),
text: titles[index]
};
return title;
};
function getLevel() {
var levels = ["学前教育版", "小学版", "初中版", "高中版"];
var index = Math.abs(Math.ceil(Math.random() * levels.length - 1));
return levels[index];
};
function getMyWords() {
var words = [{
"text": "幸福是可以通过学习来获得的,尽管它不是我们的母语。 ",
"from": "——韩寒",
"url": "http://www.juzimi.com/ju/723",
"id": "723",
"tag": "学习"
}, {
"text": "此刻打盹,你将做梦; 而此刻学习,你将圆梦。 ",
"from": "原创",
"url": "http://www.juzimi.com/ju/6897",
"id": "6897",
"tag": "学习"
}, {
"text": "无目的读书是散步而不是学习。 ",
"from": "——胡适",
"url": "http://www.juzimi.com/ju/9359",
"id": "9359",
"tag": "学习"
}, {
"text": "越学习,越发现自己的无知。 ",
"from": "——笛卡尔",
"url": "http://www.juzimi.com/ju/11801",
"id": "11801",
"tag": "学习"
}, {
"text": "如果学习只在于模仿,那么我们就不会有科学,也不会有技术。 ",
"from": "——高尔基",
"url": "http://www.juzimi.com/ju/14851",
"id": "14851",
"tag": "学习"
}, {
"text": "如果不想在世界上虚度一生,那就要学习一辈子。 ",
"from": "——高尔基",
"url": "http://www.juzimi.com/ju/16211",
"id": "16211",
"tag": "学习"
}, {
"text": "我活着是为学习,而学习并不是为活着。 ",
"from": "——培根",
"url": "http://www.juzimi.com/ju/23252",
"id": "23252",
"tag": "学习"
}, {
"text": "在任何情况下,你都要学习——以更换学习内容作为你的休息。 ",
"from": "——安·莫洛亚《大仲马传》",
"url": "http://www.juzimi.com/ju/35427",
"id": "35427",
"tag": "学习"
}, {
"text": "读书是学习,使用也是学习,而且是更重要的学习。 ",
"from": "——毛泽东",
"url": "http://www.juzimi.com/ju/47346",
"id": "47346",
"tag": "学习"
}, {
"text": "听不见喘息也就不知疲惫 看不清的终点也该要坚持。 ",
"from": "原创",
"url": "http://www.juzimi.com/ju/61527",
"id": "61527",
"tag": "学习"
}, {
"text": "平时的学习和经验,是我们在危急关头最有力的支持。 ",
"from": "——林肯",
"url": "http://www.juzimi.com/ju/73760",
"id": "73760",
"tag": "学习"
}, {
"text": "博学之,审问之,慎思之,明辨之,笃行之。 ",
"from": "《大戴礼记》",
"url": "http://www.juzimi.com/ju/101045",
"id": "101045",
"tag": "学习"
}, {
"text": "富贵必从勤苦得,男儿须读五车书。 ",
"from": "——杜甫《柏学士茅屋》",
"url": "http://www.juzimi.com/ju/120119",
"id": "120119",
"tag": "学习"
}, {
"text": "聪明在于学习,天才在于积累。 ",
"from": "——列宁",
"url": "http://www.juzimi.com/ju/176029",
"id": "176029",
"tag": "学习"
}, {
"text": "要学习向日葵,哪里有阳光就朝向哪里。 ",
"from": "《每天一张正能量》",
"url": "http://www.juzimi.com/ju/192896",
"id": "192896",
"tag": "学习"
}, {
"text": "什么时候,我连微笑也要学习。 ",
"from": "原创",
"url": "http://www.juzimi.com/ju/254071",
"id": "254071",
"tag": "学习"
}, {
"text": "当你的脾气大于出息,你就该去拼命学习。 ",
"from": "原创",
"url": "http://www.juzimi.com/ju/275806",
"id": "275806",
"tag": "学习"
}, {
"text": "把学习当学习,注定枯燥;把学习当成兴趣,注定有趣。 ",
"from": "原创",
"url": "http://www.juzimi.com/ju/380779",
"id": "380779",
"tag": "学习"
}, {
"text": "即使现在,对手也不停地翻动书页。 ",
"from": "《哈佛校训》",
"url": "http://www.juzimi.com/ju/385063",
"id": "385063",
"tag": "学习"
}, {
"text": "男孩子不学习做饭,会找不到女朋友的。 ",
"from": "——吴镇宇《爸爸去哪儿2》",
"url": "http://www.juzimi.com/ju/389941",
"id": "389941",
"tag": "学习"
}, {
"text": "原谅,是我们这一生都要学习的功课 ",
"from": "——张小娴《谢谢你离开我》",
"url": "http://www.juzimi.com/ju/421789",
"id": "421789",
"tag": "学习"
}, {
"text": "真的很想做一只小强,拥有两个大脑,一个学习,一个想你。 ",
"from": "原创",
"url": "http://www.juzimi.com/ju/486868",
"id": "486868",
"tag": "学习"
}, {
"text": "愚者向经验学习,贤者向历史学习。 ",
"from": "——宜野座伸元《心理测量者》",
"url": "http://www.juzimi.com/ju/570920",
"id": "570920",
"tag": "学习"
}, {
"text": "不好好学习怎么见TFBOYS? ",
"from": "——TFBOYS",
"url": "http://www.juzimi.com/ju/624543",
"id": "624543",
"tag": "学习"
}, {
"text": "学习好的人连打架都这么有格调。 ",
"from": "——八月长安《最好的我们》",
"url": "http://www.juzimi.com/ju/744975",
"id": "744975",
"tag": "学习"
}, {
"text": "背生字,做习题,一天不得间断,因为学习语言,不进则退。 ",
"from": "——杨绛《杂忆与杂写》",
"url": "http://www.juzimi.com/ju/849440",
"id": "849440",
"tag": "学习"
}, {
"text": "我从来不让上学耽误我的学习。 ",
"from": "——马克·吐温",
"url": "http://www.juzimi.com/ju/859492",
"id": "859492",
"tag": "学习"
}, {
"text": "你不是不擅长学习,只是没有找到自己想要学习的东西而已。 ",
"from": "——东野圭吾《梦幻花》",
"url": "http://www.juzimi.com/ju/990846",
"id": "990846",
"tag": "学习"
}, {
"text": "学习是为了养成,不是致富。 ",
"from": "《三傻大闹宝莱坞》",
"url": "http://www.juzimi.com/ju/1107974",
"id": "1107974",
"tag": "学习"
}, {
"text": "想成为最优秀的人,就要向最优秀的人学习。 ",
"from": "——巴菲特",
"url": "http://www.juzimi.com/ju/1215931",
"id": "1215931",
"tag": "学习"
}, {
"text": "“一切研究,一切学习都只不过是回忆罢了。” ",
"from": "——柏拉图《美诺篇》",
"url": "http://www.juzimi.com/ju/1435208",
"id": "1435208",
"tag": "学习"
}, {
"text": "我们为什么会跌倒呢?这样我们才能学习怎么站起来。 ",
"from": "《蝙蝠侠:开战时刻》",
"url": "http://www.juzimi.com/ju/1514754",
"id": "1514754",
"tag": "学习"
}, {
"text": "只要还在学习,人生就有无穷的可能。 ",
"from": "《女王的教室》",
"url": "http://www.juzimi.com/ju/1616776",
"id": "1616776",
"tag": "学习"
}, {
"text": "加紧学习,抓住中心,宁精勿杂,宁专勿多。 ",
"from": "——周恩来",
"url": "http://www.juzimi.com/ju/1638108",
"id": "1638108",
"tag": "学习"
}, {
"text": "好好学习,安心学习 ",
"from": "原创",
"url": "http://www.juzimi.com/ju/1746545",
"id": "1746545",
"tag": "学习"
}, {
"text": "没有脑子却要学习 一个大写的身残志坚 ",
"from": "原创",
"url": "http://www.juzimi.com/ju/1874200",
"id": "1874200",
"tag": "学习"
}, {
"text": "学习哲学的目的,是使人成为人,而不是使人成为某种人。 ",
"from": "——冯友兰《中国哲学简史》",
"url": "http://www.juzimi.com/ju/2030975",
"id": "2030975",
"tag": "学习"
}, {
"text": "一个人学到的最重要的东西是学习的方法。 ",
"from": "——尼尔·波兹曼《娱乐至死》",
"url": "http://www.juzimi.com/ju/2117796",
"id": "2117796",
"tag": "学习"
}, {
"text": "我不能改变过去,但我能向过去学习 ",
"from": "《爱丽丝漫游仙境:镜中奇遇记》",
"url": "http://www.juzimi.com/ju/2127253",
"id": "2127253",
"tag": "学习"
}, {
"text": "忙完秋收忙秋种,学习,学习,再学习。 ",
"from": "——哈佛大学格言",
"url": "http://www.juzimi.com/ju/2344632",
"id": "2344632",
"tag": "学习"
}, {
"text": "学习等于接受,学习等于感受,学习等于承受,学习是受 ",
"from": "原创",
"url": "http://www.juzimi.com/ju/2565447",
"id": "2565447",
"tag": "学习"
}, {
"text": "当你的才华还撑不上你的野心时,你应该就去静心去学习 ",
"from": "原创",
"url": "http://www.juzimi.com/ju/2682793",
"id": "2682793",
"tag": "学习"
}, {
"text": "我爱学习 学习使我快乐 我爱学习 学习使我冷静 ",
"from": "原创",
"url": "http://www.juzimi.com/ju/2806212",
"id": "2806212",
"tag": "学习"
}, {
"text": "人如果停止了学习,就开始走向失败。 ",
"from": "——马云",
"url": "http://www.juzimi.com/ju/2807817",
"id": "2807817",
"tag": "学习"
}, {
"text": "我和你在一起的有限时间里,我希望向你学习学习学习。 ",
"from": "原创",
"url": "http://www.juzimi.com/ju/3054382",
"id": "3054382",
"tag": "学习"
}, {
"text": "哪有什么烦心事 一定是你不认真学习又想太多 ",
"from": "原创",
"url": "http://www.juzimi.com/ju/3180285",
"id": "3180285",
"tag": "学习"
}, {
"text": "我不爱学习 只是比较喜欢 那个认真努力的自己 ",
"from": "原创",
"url": "http://www.juzimi.com/ju/3259089",
"id": "3259089",
"tag": "学习"
}, {
"text": "以学习为乐,以学习为贵,以学习为荣。 ",
"from": "原创",
"url": "http://www.juzimi.com/ju/3676496",
"id": "3676496",
"tag": "学习"
}, {
"text": "“为什么要学习?” “学习累两年,不学习累一辈子” ",
"from": "原创",
"url": "http://www.juzimi.com/ju/3848723",
"id": "3848723",
"tag": "学习"
}, {
"text": "我不想努力,却又不允许自己堕落。 ",
"from": "原创",
"url": "http://www.juzimi.com/ju/3978054",
"id": "3978054",
"tag": "学习"
}, {
"text": "学习,学习,再学习!学,然后知不足。 ",
"from": "——列宁",
"url": "http://www.juzimi.com/ju/4034175",
"id": "4034175",
"tag": "学习"
}];
var index = Math.abs(Math.ceil(Math.random() * words.length - 1));
return words[index];
};
function getGrid(w, h) {
var ln = 10;
var ps = [];
for (var index = 0; index < ln; index++) {
var x = w / ln * (index + 1);
for (var j = 0; j < ln; j++) {
var y = h / ln * (j + 1);
ps.push({
x: x,
y: y
})
}
};
return ps
};
function run() {
initCover();
initCover_small();
initMy();
};
function save() {
var s = document.querySelector('a-scene').components.screenshot;
var w=window.innerWidth*2,h=window.innerHeight*2;
s.data.height = h;
s.data.width =w;
var c=s.getCanvas('perspective');
var cc=document.createElement('canvas');
var nc=cc.getContext('2d');
cc.width= w;
cc.height=h;
nc.drawImage(c,0,0);
var logo=document.querySelector('#logo');
var size=w*0.25;
var y=h-size-20;
nc.drawImage(logo,w/2-size/2,y, size,size);
var base64=cc.toDataURL('image/png');
var img=document.createElement('img');
img.style.width="100%";
img.onload=function(){
document.body.innerHTML='';
document.body.appendChild(img);
}
img.src=base64;
// s.capture('perspective');
}
function initMy() {
var words = getMyWords();
var txt = document.querySelector('#txt');
if (words.from == '原创') {
words.from = '';
};
txt.innerText = words.text + ' ' + words.from;
//console.log(words)
}
function initCover() {
var canvas = document.createElement('canvas');
canvas.width = 500;
canvas.height = 700;
var color = "rgba(0,0,0,0.8)";
var grids = getGrid(canvas.width, canvas.height);
var ctx = canvas.getContext('2d');
ctx.fillStyle = "white";
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (var index = 0; index < grids.length; index++) {
var p = grids[index];
ctx.fillStyle = "rgba(0,0,0,0.8)";
ctx.fillRect(p.x, p.y, 4, 4);
};
ctx.strokeStyle = "rgba(0,0,0,0.2)";
ctx.beginPath();
ctx.moveTo(grids[randomRangeInt(0, 10)].x, grids[randomRangeInt(0, 10)].y);
ctx.lineTo(grids[grids.length - randomRangeInt(1, 10)].x, grids[grids.length - randomRangeInt(1, 10)].y);
ctx.closePath();
ctx.stroke();
for (var index = 0; index < 8; index++) {
var _a = randomStandardNormal();
var _x = Math.abs(_a[0] * canvas.width * 0.8);
var _y = _a[1] * canvas.height * 2;
if (_y > 220 && _y < 360) {
_y = _y + 200;
};
if (_y > 0 && _y < 140) {
_y = _y - 90;
};
// console.log(_x,_y)
var pattern = createPattern(c);
var size = (80 + (150 * _a[0])) < 50 ? (Math.random() > 0.35 ? 280 : 50) : (80 + (150 * _a[0]));
ctx.drawImage(pattern, _x, _y, size, size);
};
//
ctx.fillStyle = 'rgba(255,255,255,0.7)';
ctx.fillRect(0, 0, canvas.width, 384);
ctx.font = "bold 48px sans-serif";
ctx.fillStyle = color;
ctx.strokeStyle = "#ffffff";
ctx.lineWidth = 4;
ctx.strokeText(t.text.zh, 50, 128);
ctx.fillText(t.text.zh, 50, 128);
ctx.font = "bold 28px sans-serif";
ctx.fillStyle = color;
ctx.strokeStyle = "#ffffff";
ctx.lineWidth = 4;
ctx.strokeText('( ' + l + ' )', 50, 180);
ctx.fillText('( ' + l + ' )', 50, 180);
ctx.font = "bold 30px sans-serif";
ctx.fillStyle = c[0];
ctx.strokeStyle = "#ffffff";
ctx.lineWidth = 1;
ctx.strokeText(t.text.en[0], 50, 320);
ctx.strokeText(t.text.en[1], 50, 360);
ctx.fillText(t.text.en[0], 50, 320);
ctx.fillText(t.text.en[1], 50, 360);
ctx.fillRect(50, canvas.height - 80, 10, 10);
ctx.fillStyle = 'rgba(255,255,255,0.7)';
ctx.fillRect(0, canvas.height - 90, canvas.width, 384);
ctx.font = "bold 16px sans-serif";
ctx.fillStyle = 'black';
ctx.textBaseline = "hanging";
ctx.fillText('人工智能+设计修炼指南系列', 70, canvas.height - 80);
ctx.fillText('科技Mix设计Lab 出品', 70, canvas.height - 60);
ctx.fillStyle = 'black';
ctx.font = "bold 18px sans-serif";
ctx.strokeStyle = "#ffffff";
ctx.lineWidth = 4;
var tw2 = ctx.measureText(name).width;
ctx.fillStyle = 'black';
ctx.strokeText(name, 70, canvas.height - 40);
ctx.fillText(name, 70, canvas.height - 40);
ctx.fillStyle = c[0];
ctx.fillRect(0, canvas.height - 35, tw2 - 20, 10);
ctx.fillRect(90 + tw2, canvas.height - 35, canvas.width, 10);
var imgSrc = canvas.toDataURL();
//alert(imgSrc)
var img = document.querySelector('#cover');
img.src = imgSrc;
img.onload = function () {
console.log('done');
document.querySelector('#bookCover').setAttribute('src', '#cover');
isDone = isDone + 1;
//document.body.innerHTML='';
// document.body.appendChild(img)
};
};
function initCover_small() {
var canvas = document.createElement('canvas');
canvas.width = 80;
canvas.height = 700;
var ctx = canvas.getContext('2d');
//ctx.fillStyle="white";
//ctx.fillRect(0,0,canvas.width,canvas.height);
ctx.font = "30px Verdana";
// 创建渐变
var grd = ctx.createLinearGradient(0, 0, canvas.width, 0);
grd.addColorStop(1, "rgba(0,0,0,0.05)");
grd.addColorStop(0, "white");
ctx.fillStyle = 'rgba(0,0,0,0.1)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.font = "bold 20px sans-serif";
ctx.fillStyle = 'black';
ctx.textBaseline = "hanging";
var tts = t.texts.concat('人工智能+设计修炼指南'.split(''));
for (var index = 0; index < tts.length; index++) {
var tt = tts[index];
if (index >= t.texts.length) {
ctx.font = "bold 12px sans-serif";
ctx.fillText(tt, 30, index * 18 + 300);
} else {
ctx.font = "bold 20px sans-serif";
ctx.fillText(tt, 30, index * 24 + 50);
}
};
ctx.fillStyle = c[0];
ctx.fillRect(0, canvas.height - 35, 300, 10);
var imgSrc = canvas.toDataURL();
var img = document.querySelector('#cover_small');
img.src = imgSrc;
img.onload = function () {
console.log('done')
document.querySelector('#bookCover_small').setAttribute('src', '#cover_small')
isDone = isDone + 1;
/* if (isDone >= 2) {
var base64 = document.querySelector('.a-canvas').toDataURL();
var img = new Image();
img.src = base64;
img.onload = function () {
document.body.appendChild(img)
}
};
*/
//document.body.appendChild(canvas)
};
};
function createPattern(colors) {
var canvas = document.createElement('canvas');
canvas.width = 150;
canvas.height = 150;
var ctx = canvas.getContext('2d');
// ctx.strokeRect(0,0,canvas.width,canvas.height);
// ctx.rotate(randomRangeInt(0,40)*Math.PI/180);
var vertices = Math.random() > 0.45 ? 5 : 6;
var pattern1 = create(colors, true, vertices);
ctx.drawImage(pattern1, 0, 0, 150, 150);
var pattern2 = create(colors, false, vertices);
ctx.drawImage(pattern2, 10, 10, 120, 120);
return canvas
};
function create(colors, isStroke, vertices) {
var canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d');
// 定义边长、边数、canvas大小
var length = 100,
size = 500;
canvas.width = size;
canvas.height = size;
var getDegree = function (vertices, index) {
return 360 / vertices * (i + 0.5) + 90;
}
var getRadian = function (degree) {
return degree * Math.PI / 180;
};
ctx.beginPath();
for (var i = 0; i < vertices; i++) {
// 计算偏转
var degree = getDegree(vertices, i),
radian = getRadian(degree);
// 增加1/3的canvas大小位移量以免被边缘挡住
var x = Math.cos(radian) * length + size / 3;
var y = Math.sin(radian) * length + size / 3;
ctx.lineTo(x, y);
}
ctx.closePath();
if (isStroke) {
ctx.strokeStyle = colors[1];
ctx.lineWidth = 10;
ctx.stroke();
} else {
ctx.fillStyle = colors[0];
ctx.fill();
};
return canvas
}
//如何生成指定分布的随机数
function randomRange(min, max) {
return Math.random() * (max - min) + min;
};
function randomRangeInt(min, max) {
return Math.round(Math.random() * (max - min)) + min;
};
//正态分布
function mathNormal(x, mu, sigma) {
mu = mu || 0;
sigma = sigma || 1;
var res = (1 / (Math.sqrt(2 * Math.PI) * sigma)) * (Math.exp(-Math.pow(x - mu, 2) / (2 * Math.pow(sigma, 2))));
return res
};
function randomStandardNormal() {
var isTarget = false,
res;
while (!isTarget) {
var a = randomRange(-1, 1);
var b = randomRange(0, 1);
if (b <= mathNormal(a)) {
isTarget = true;
res = [a, b]
};
};
return res;
};
</script>
</body>
</html>