This repository has been archived by the owner on Aug 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
146 lines (146 loc) · 2.91 KB
/
demo.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
<style type="text/css">
#code {
height: 384px;
}
#draw-button {
margin-top: 145px;
}
div {
float: left;
}
.border {
border: 1px solid;
border-color: rgb(169, 169, 169);
}
</style>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="Flash It.js"></script>
<script type="text/javascript" src="built-in functions.js"></script>
<script type="text/javascript">
x = flashit();
$(document).ready(function(){
var ctx = document.getElementById('anime-canvas').getContext('2d');
var counts = 0;
var code = "";
var frameEnd = false;
var pause = false;
$("#read-button").click(function(){
counts = 0;
code = $("#code").val();
frameEnd = false;
x.init(code,[stdlib(ctx,{
width:683,
height:384
},function(){
frameEnd = true;
})]);
});
$("#pause-button").click(function(){
pause = true;
});
$("#full-speed-button").click(function(){
goes = function(){
if(!x.hasNext()){
console.log("anime finished after "+counts+" times caculate");
}else{
if(frameEnd){
frameEnd = false;
setTimeout(goes,30);
}else{
if(pause){
pause = false;
}else{
x.next();
counts += 1;
goes();
}
}
}
}
goes();
});
$("#by-frame-button").click(function(){
goes = function(){
if(!x.hasNext()){
console.log("anime finished after "+counts+" times caculate");
}else{
if(frameEnd){
frameEnd = false;
console.log("a frame finished")
}else{
if(pause){
pause = false;
}else{
x.next();
counts += 1;
goes();
}
}
}
}
goes();
});
$("#by-step-button").click(function(){
goes = function(){
if(!x.hasNext()){
console.log("anime finished after "+counts+" times caculate");
}else{
console.log("one step finished");
x.next(function(x){console.log(x)});
counts += 1;
}
}
goes();
});
})
</script>
</head>
<body>
<h1>Demo</h1>
<div>
<textarea id="code" cols="50">
(begin
(define loop
(lambda (n f)
(if (= n 0)
1
(begin
(f)
(self (- n 1) f)))))
(define futiao
(g
(line (p 10 10) (p 80 80))
(line (p 10 80) (p 80 10))))
(define kuang
(circle (p 45 45) 50))
(define lunzi
(g futiao kuang))
(place lunzi (p 10 10))
(loop 60
(lambda ()
(begin
(rotate futiao (* PI 0.02))
(shift lunzi (p 2 0))
(draw))))
)
</textarea>
</div>
<div id="button-bar">
<button id="read-button">read</button>
<button id="full-speed-button">Full Speed</button>
<button id="by-frame-button">By Frame</button>
<button id="by-step-button">By Step</button>
<button id="pause-button">pause</button>
</div>
<div class="border">
<canvas id="anime-canvas" width="683" height="384">
your browser not support
</canvas>
</div>
</body>
</html>