Skip to content

Commit 99c1167

Browse files
committed
修正画布大小不受控制的问题,原因是Processing软件3.0.2版本中的settings()函数在Processing.js不认,因此pde文件中的size不能被processingjs解释,把size放到setup中即可。注意本地调试processingjs请用Firefox,Chrome和IE Edge不支持JavaScript本地访问外部文件。
1 parent 74d1f71 commit 99c1167

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

jsExample.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
<head>
44
<title>JavaScript实例</title>
55
<script src="js/processing.min.js"></script>
6-
<style type="text/css" rel="stylesheet">
7-
.processingEle{
8-
width: 640px ;
9-
height: 480px;
10-
}
11-
</style>
126
</head>
137

148
<body>
@@ -27,7 +21,7 @@
2721
<button id="submitButton2" onclick="minusFunction()">减法提交</button>
2822
</form>
2923

30-
<canvas id="processingEle" data-processing-sources="sketch/demo.pde"></canvas>
24+
<canvas id="processingEle" data-processing-sources="sketch/demo.pde" width=640px height=480px style='width:640px;height:480px'></canvas>
3125

3226
<script>
3327
function plusFunction()

sketch/demo.pde

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
float x = 0.0;
2-
void settings(){
3-
size(640,480) ;
4-
}
52
void setup(){
3+
size(640,480) ;
64
background(color(100,199,0)) ;
75
frameRate(50) ;
86
noStroke() ;
97
fill(color(252,194,0)) ;
108
}
119
void draw(){
12-
if (x >= width)
10+
if (width/2 - 100 + x >= width)
1311
{
14-
x = -width/2 ;
12+
x = -width/2 -100;
1513
}
1614
background(color(100,199,0)) ;
1715
rect(width/2 - 100 + x, height/2 -100, 200,200) ;
18-
x += 5.1 ;
16+
x += 5 ;
1917
}

0 commit comments

Comments
 (0)