-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
163 lines (139 loc) · 4.89 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
<html>
<head>
<script id="codetabs" type="text/javascript" src="js/codetabs.js"></script>
<style>
body {
margin:32px;
padding:0px;
background-color:#eee;
}
</style>
</head>
<body>
<!--
data-appendbody="true"
data-width="800"
data-height="300"
data-name="sketch"
data-processing="http://cdnjs.cloudflare.com/ajax/libs/processing.js/1.4.1/processing.min.js"
data-nohints="true"
data-nozip="true"
data-nofullscreen="true"
data-ishidden="true"
data-isplaying="true"
data-isfullscreen="true"
data-webcam="true"
data-scripts="http://cdnjs.cloudflare.com/ajax/libs/three.js/r57/three.min.js"
data-fontsize="16px"
data-images="img/cat.jpg"
data-lines="#eee"
data-background="#aaa"
-->
<div class="codetabs" data-name="sketch" data-width="1000" data-height="450"
data-webcam="true"
data-scripts="http://cdnjs.cloudflare.com/ajax/libs/three.js/r57/three.min.js"
data-fontsize="16px" data-lines="#eee" data-background="#aaa">
<textarea data-name="three.js">
onPageLoad(function() {
var camera, scene, renderer, geometry, material, mesh;
init();
animate();
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(50, fullWidth/fullHeight, 1, 10000);
camera.position.z = 500;
scene.add(camera);
geometry = new THREE.CubeGeometry(200, 200, 200);
material = new THREE.MeshNormalMaterial();
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
renderer = new THREE.CanvasRenderer();
renderer.setSize(fullWidth, fullHeight);
document.body.appendChild(renderer.domElement);
}
function animate() {
requestAnimationFrame(animate);
render();
}
function render() {
mesh.rotation.x += 0.01;
mesh.rotation.y += 0.02;
renderer.render(scene, camera);
}
});
</textarea>
</div>
<div class="codetabs" data-name="sketch2" data-processing="js/local/processing-1.4.1.min.js"
data-webcam="true" data-width="1000" data-height="450"
data-fontsize="16px" data-lines="#eee" data-background="#aaa">
<textarea data-name="sketch.pde">
ArrayList<Ball> ballList = new ArrayList<Ball>();
PImage cat;
void setup() {
size(fullWidth, fullHeight);
stroke(0, 128);
//strokeWeight(2);
fill(255, 0, 0, 128);
//The ArrayList doesn't have a size yet
//So we have to set how much we will loop literally (10)
for (int i = 0; i < 10; i++) {
//Add a new ball object to the ArrayList ballList
ballList.add(new Ball());
}
cat = loadImage(cat);
//Webcam.init();
}
void draw() {
background(255);
image(cat, 0, 0, width/2, height);
if (Webcam.video) externals.context.drawImage(Webcam.video, width/2, 0, width/2, height);
//Now that the ArrayList has a size we can use .size()
//in our loop
for (int i = 0; i < ballList.size(); i++) {
//Get the current ball in the loop, the ball at position i
//Notice we DON'T have to cast the reference variable
//since the ArrayList is typed
Ball curBall = ballList.get(i);
curBall.update();
curBall.checkWalls();
curBall.drawMe();
}
}
</textarea>
<textarea data-name="Ball.pde">
//A class to describe a ball object
class Ball {
float xPos, yPos, xVel, yVel;
Ball() {
//Set the initial values for our Ball object's variables (fields)
xPos = random(16, width - 16);
yPos = random(16, height - 16);
xVel = random(-2, 2);
yVel = random(-2, 2);
}
//A method to update the ball position
void update() {
xPos += xVel;
yPos += yVel;
}
//A method to check collisions with the walls
void checkWalls() {
if (abs(xPos - width/2) > width/2 - 16) {
xVel *= -1;
}
if (abs(yPos - height/2) > height/2 - 16) {
yVel *= -1;
}
}
//A method to draw the ball object
void drawMe() {
pushMatrix();
translate(xPos, yPos);
ellipse(0, 0, 32, 32);
popMatrix();
}
}
</textarea>
</div>
</body>
</html>