Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (C) 2007 Apple Inc. All rights reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Redistribution and use in source and binary forms, with or without |
michael@0 | 5 | * modification, are permitted provided that the following conditions |
michael@0 | 6 | * are met: |
michael@0 | 7 | * 1. Redistributions of source code must retain the above copyright |
michael@0 | 8 | * notice, this list of conditions and the following disclaimer. |
michael@0 | 9 | * 2. Redistributions in binary form must reproduce the above copyright |
michael@0 | 10 | * notice, this list of conditions and the following disclaimer in the |
michael@0 | 11 | * documentation and/or other materials provided with the distribution. |
michael@0 | 12 | * |
michael@0 | 13 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
michael@0 | 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
michael@0 | 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
michael@0 | 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
michael@0 | 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
michael@0 | 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
michael@0 | 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
michael@0 | 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
michael@0 | 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
michael@0 | 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
michael@0 | 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 24 | */ |
michael@0 | 25 | |
michael@0 | 26 | function createVector(x,y,z) { |
michael@0 | 27 | return new Array(x,y,z); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function sqrLengthVector(self) { |
michael@0 | 31 | return self[0] * self[0] + self[1] * self[1] + self[2] * self[2]; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function lengthVector(self) { |
michael@0 | 35 | return Math.sqrt(self[0] * self[0] + self[1] * self[1] + self[2] * self[2]); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | function addVector(self, v) { |
michael@0 | 39 | self[0] += v[0]; |
michael@0 | 40 | self[1] += v[1]; |
michael@0 | 41 | self[2] += v[2]; |
michael@0 | 42 | return self; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function subVector(self, v) { |
michael@0 | 46 | self[0] -= v[0]; |
michael@0 | 47 | self[1] -= v[1]; |
michael@0 | 48 | self[2] -= v[2]; |
michael@0 | 49 | return self; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | function scaleVector(self, scale) { |
michael@0 | 53 | self[0] *= scale; |
michael@0 | 54 | self[1] *= scale; |
michael@0 | 55 | self[2] *= scale; |
michael@0 | 56 | return self; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function normaliseVector(self) { |
michael@0 | 60 | var len = Math.sqrt(self[0] * self[0] + self[1] * self[1] + self[2] * self[2]); |
michael@0 | 61 | self[0] /= len; |
michael@0 | 62 | self[1] /= len; |
michael@0 | 63 | self[2] /= len; |
michael@0 | 64 | return self; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | function add(v1, v2) { |
michael@0 | 68 | return new Array(v1[0] + v2[0], v1[1] + v2[1], v1[2] + v2[2]); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | function sub(v1, v2) { |
michael@0 | 72 | return new Array(v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2]); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | function scalev(v1, v2) { |
michael@0 | 76 | return new Array(v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | function dot(v1, v2) { |
michael@0 | 80 | return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | function scale(v, scale) { |
michael@0 | 84 | return [v[0] * scale, v[1] * scale, v[2] * scale]; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | function cross(v1, v2) { |
michael@0 | 88 | return [v1[1] * v2[2] - v1[2] * v2[1], |
michael@0 | 89 | v1[2] * v2[0] - v1[0] * v2[2], |
michael@0 | 90 | v1[0] * v2[1] - v1[1] * v2[0]]; |
michael@0 | 91 | |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | function normalise(v) { |
michael@0 | 95 | var len = lengthVector(v); |
michael@0 | 96 | return [v[0] / len, v[1] / len, v[2] / len]; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | function transformMatrix(self, v) { |
michael@0 | 100 | var vals = self; |
michael@0 | 101 | var x = vals[0] * v[0] + vals[1] * v[1] + vals[2] * v[2] + vals[3]; |
michael@0 | 102 | var y = vals[4] * v[0] + vals[5] * v[1] + vals[6] * v[2] + vals[7]; |
michael@0 | 103 | var z = vals[8] * v[0] + vals[9] * v[1] + vals[10] * v[2] + vals[11]; |
michael@0 | 104 | return [x, y, z]; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | function invertMatrix(self) { |
michael@0 | 108 | var temp = new Array(16); |
michael@0 | 109 | var tx = -self[3]; |
michael@0 | 110 | var ty = -self[7]; |
michael@0 | 111 | var tz = -self[11]; |
michael@0 | 112 | for (h = 0; h < 3; h++) |
michael@0 | 113 | for (v = 0; v < 3; v++) |
michael@0 | 114 | temp[h + v * 4] = self[v + h * 4]; |
michael@0 | 115 | for (i = 0; i < 11; i++) |
michael@0 | 116 | self[i] = temp[i]; |
michael@0 | 117 | self[3] = tx * self[0] + ty * self[1] + tz * self[2]; |
michael@0 | 118 | self[7] = tx * self[4] + ty * self[5] + tz * self[6]; |
michael@0 | 119 | self[11] = tx * self[8] + ty * self[9] + tz * self[10]; |
michael@0 | 120 | return self; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | |
michael@0 | 124 | // Triangle intersection using barycentric coord method |
michael@0 | 125 | function Triangle(p1, p2, p3) { |
michael@0 | 126 | var edge1 = sub(p3, p1); |
michael@0 | 127 | var edge2 = sub(p2, p1); |
michael@0 | 128 | var normal = cross(edge1, edge2); |
michael@0 | 129 | if (Math.abs(normal[0]) > Math.abs(normal[1])) |
michael@0 | 130 | if (Math.abs(normal[0]) > Math.abs(normal[2])) |
michael@0 | 131 | this.axis = 0; |
michael@0 | 132 | else |
michael@0 | 133 | this.axis = 2; |
michael@0 | 134 | else |
michael@0 | 135 | if (Math.abs(normal[1]) > Math.abs(normal[2])) |
michael@0 | 136 | this.axis = 1; |
michael@0 | 137 | else |
michael@0 | 138 | this.axis = 2; |
michael@0 | 139 | var u = (this.axis + 1) % 3; |
michael@0 | 140 | var v = (this.axis + 2) % 3; |
michael@0 | 141 | var u1 = edge1[u]; |
michael@0 | 142 | var v1 = edge1[v]; |
michael@0 | 143 | |
michael@0 | 144 | var u2 = edge2[u]; |
michael@0 | 145 | var v2 = edge2[v]; |
michael@0 | 146 | this.normal = normalise(normal); |
michael@0 | 147 | this.nu = normal[u] / normal[this.axis]; |
michael@0 | 148 | this.nv = normal[v] / normal[this.axis]; |
michael@0 | 149 | this.nd = dot(normal, p1) / normal[this.axis]; |
michael@0 | 150 | var det = u1 * v2 - v1 * u2; |
michael@0 | 151 | this.eu = p1[u]; |
michael@0 | 152 | this.ev = p1[v]; |
michael@0 | 153 | this.nu1 = u1 / det; |
michael@0 | 154 | this.nv1 = -v1 / det; |
michael@0 | 155 | this.nu2 = v2 / det; |
michael@0 | 156 | this.nv2 = -u2 / det; |
michael@0 | 157 | this.material = [0.7, 0.7, 0.7]; |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | Triangle.prototype.intersect = function(orig, dir, near, far) { |
michael@0 | 161 | var u = (this.axis + 1) % 3; |
michael@0 | 162 | var v = (this.axis + 2) % 3; |
michael@0 | 163 | var d = dir[this.axis] + this.nu * dir[u] + this.nv * dir[v]; |
michael@0 | 164 | var t = (this.nd - orig[this.axis] - this.nu * orig[u] - this.nv * orig[v]) / d; |
michael@0 | 165 | if (t < near || t > far) |
michael@0 | 166 | return null; |
michael@0 | 167 | var Pu = orig[u] + t * dir[u] - this.eu; |
michael@0 | 168 | var Pv = orig[v] + t * dir[v] - this.ev; |
michael@0 | 169 | var a2 = Pv * this.nu1 + Pu * this.nv1; |
michael@0 | 170 | if (a2 < 0) |
michael@0 | 171 | return null; |
michael@0 | 172 | var a3 = Pu * this.nu2 + Pv * this.nv2; |
michael@0 | 173 | if (a3 < 0) |
michael@0 | 174 | return null; |
michael@0 | 175 | |
michael@0 | 176 | if ((a2 + a3) > 1) |
michael@0 | 177 | return null; |
michael@0 | 178 | return t; |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | function Scene(a_triangles) { |
michael@0 | 182 | this.triangles = a_triangles; |
michael@0 | 183 | this.lights = []; |
michael@0 | 184 | this.ambient = [0,0,0]; |
michael@0 | 185 | this.background = [0.8,0.8,1]; |
michael@0 | 186 | } |
michael@0 | 187 | var zero = new Array(0,0,0); |
michael@0 | 188 | |
michael@0 | 189 | Scene.prototype.intersect = function(origin, dir, near, far) { |
michael@0 | 190 | var closest = null; |
michael@0 | 191 | for (i = 0; i < this.triangles.length; i++) { |
michael@0 | 192 | var triangle = this.triangles[i]; |
michael@0 | 193 | var d = triangle.intersect(origin, dir, near, far); |
michael@0 | 194 | if (d == null || d > far || d < near) |
michael@0 | 195 | continue; |
michael@0 | 196 | far = d; |
michael@0 | 197 | closest = triangle; |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | if (!closest) |
michael@0 | 201 | return [this.background[0],this.background[1],this.background[2]]; |
michael@0 | 202 | |
michael@0 | 203 | var normal = closest.normal; |
michael@0 | 204 | var hit = add(origin, scale(dir, far)); |
michael@0 | 205 | if (dot(dir, normal) > 0) |
michael@0 | 206 | normal = [-normal[0], -normal[1], -normal[2]]; |
michael@0 | 207 | |
michael@0 | 208 | var colour = null; |
michael@0 | 209 | if (closest.shader) { |
michael@0 | 210 | colour = closest.shader(closest, hit, dir); |
michael@0 | 211 | } else { |
michael@0 | 212 | colour = closest.material; |
michael@0 | 213 | } |
michael@0 | 214 | |
michael@0 | 215 | // do reflection |
michael@0 | 216 | var reflected = null; |
michael@0 | 217 | if (colour.reflection > 0.001) { |
michael@0 | 218 | var reflection = addVector(scale(normal, -2*dot(dir, normal)), dir); |
michael@0 | 219 | reflected = this.intersect(hit, reflection, 0.0001, 1000000); |
michael@0 | 220 | if (colour.reflection >= 0.999999) |
michael@0 | 221 | return reflected; |
michael@0 | 222 | } |
michael@0 | 223 | |
michael@0 | 224 | var l = [this.ambient[0], this.ambient[1], this.ambient[2]]; |
michael@0 | 225 | for (var i = 0; i < this.lights.length; i++) { |
michael@0 | 226 | var light = this.lights[i]; |
michael@0 | 227 | var toLight = sub(light, hit); |
michael@0 | 228 | var distance = lengthVector(toLight); |
michael@0 | 229 | scaleVector(toLight, 1.0/distance); |
michael@0 | 230 | distance -= 0.0001; |
michael@0 | 231 | if (this.blocked(hit, toLight, distance)) |
michael@0 | 232 | continue; |
michael@0 | 233 | var nl = dot(normal, toLight); |
michael@0 | 234 | if (nl > 0) |
michael@0 | 235 | addVector(l, scale(light.colour, nl)); |
michael@0 | 236 | } |
michael@0 | 237 | l = scalev(l, colour); |
michael@0 | 238 | if (reflected) { |
michael@0 | 239 | l = addVector(scaleVector(l, 1 - colour.reflection), scaleVector(reflected, colour.reflection)); |
michael@0 | 240 | } |
michael@0 | 241 | return l; |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | Scene.prototype.blocked = function(O, D, far) { |
michael@0 | 245 | var near = 0.0001; |
michael@0 | 246 | var closest = null; |
michael@0 | 247 | for (i = 0; i < this.triangles.length; i++) { |
michael@0 | 248 | var triangle = this.triangles[i]; |
michael@0 | 249 | var d = triangle.intersect(O, D, near, far); |
michael@0 | 250 | if (d == null || d > far || d < near) |
michael@0 | 251 | continue; |
michael@0 | 252 | return true; |
michael@0 | 253 | } |
michael@0 | 254 | |
michael@0 | 255 | return false; |
michael@0 | 256 | } |
michael@0 | 257 | |
michael@0 | 258 | |
michael@0 | 259 | // this camera code is from notes i made ages ago, it is from *somewhere* -- i cannot remember where |
michael@0 | 260 | // that somewhere is |
michael@0 | 261 | function Camera(origin, lookat, up) { |
michael@0 | 262 | var zaxis = normaliseVector(subVector(lookat, origin)); |
michael@0 | 263 | var xaxis = normaliseVector(cross(up, zaxis)); |
michael@0 | 264 | var yaxis = normaliseVector(cross(xaxis, subVector([0,0,0], zaxis))); |
michael@0 | 265 | var m = new Array(16); |
michael@0 | 266 | m[0] = xaxis[0]; m[1] = xaxis[1]; m[2] = xaxis[2]; |
michael@0 | 267 | m[4] = yaxis[0]; m[5] = yaxis[1]; m[6] = yaxis[2]; |
michael@0 | 268 | m[8] = zaxis[0]; m[9] = zaxis[1]; m[10] = zaxis[2]; |
michael@0 | 269 | invertMatrix(m); |
michael@0 | 270 | m[3] = 0; m[7] = 0; m[11] = 0; |
michael@0 | 271 | this.origin = origin; |
michael@0 | 272 | this.directions = new Array(4); |
michael@0 | 273 | this.directions[0] = normalise([-0.7, 0.7, 1]); |
michael@0 | 274 | this.directions[1] = normalise([ 0.7, 0.7, 1]); |
michael@0 | 275 | this.directions[2] = normalise([ 0.7, -0.7, 1]); |
michael@0 | 276 | this.directions[3] = normalise([-0.7, -0.7, 1]); |
michael@0 | 277 | this.directions[0] = transformMatrix(m, this.directions[0]); |
michael@0 | 278 | this.directions[1] = transformMatrix(m, this.directions[1]); |
michael@0 | 279 | this.directions[2] = transformMatrix(m, this.directions[2]); |
michael@0 | 280 | this.directions[3] = transformMatrix(m, this.directions[3]); |
michael@0 | 281 | } |
michael@0 | 282 | |
michael@0 | 283 | Camera.prototype.generateRayPair = function(y) { |
michael@0 | 284 | rays = new Array(new Object(), new Object()); |
michael@0 | 285 | rays[0].origin = this.origin; |
michael@0 | 286 | rays[1].origin = this.origin; |
michael@0 | 287 | rays[0].dir = addVector(scale(this.directions[0], y), scale(this.directions[3], 1 - y)); |
michael@0 | 288 | rays[1].dir = addVector(scale(this.directions[1], y), scale(this.directions[2], 1 - y)); |
michael@0 | 289 | return rays; |
michael@0 | 290 | } |
michael@0 | 291 | |
michael@0 | 292 | function renderRows(camera, scene, pixels, width, height, starty, stopy) { |
michael@0 | 293 | for (var y = starty; y < stopy; y++) { |
michael@0 | 294 | var rays = camera.generateRayPair(y / height); |
michael@0 | 295 | for (var x = 0; x < width; x++) { |
michael@0 | 296 | var xp = x / width; |
michael@0 | 297 | var origin = addVector(scale(rays[0].origin, xp), scale(rays[1].origin, 1 - xp)); |
michael@0 | 298 | var dir = normaliseVector(addVector(scale(rays[0].dir, xp), scale(rays[1].dir, 1 - xp))); |
michael@0 | 299 | var l = scene.intersect(origin, dir); |
michael@0 | 300 | pixels[y][x] = l; |
michael@0 | 301 | } |
michael@0 | 302 | } |
michael@0 | 303 | } |
michael@0 | 304 | |
michael@0 | 305 | Camera.prototype.render = function(scene, pixels, width, height) { |
michael@0 | 306 | var cam = this; |
michael@0 | 307 | var row = 0; |
michael@0 | 308 | renderRows(cam, scene, pixels, width, height, 0, height); |
michael@0 | 309 | } |
michael@0 | 310 | |
michael@0 | 311 | |
michael@0 | 312 | |
michael@0 | 313 | function raytraceScene() |
michael@0 | 314 | { |
michael@0 | 315 | var numTriangles = 2 * 6; |
michael@0 | 316 | var triangles = new Array();//numTriangles); |
michael@0 | 317 | var tfl = createVector(-10, 10, -10); |
michael@0 | 318 | var tfr = createVector( 10, 10, -10); |
michael@0 | 319 | var tbl = createVector(-10, 10, 10); |
michael@0 | 320 | var tbr = createVector( 10, 10, 10); |
michael@0 | 321 | var bfl = createVector(-10, -10, -10); |
michael@0 | 322 | var bfr = createVector( 10, -10, -10); |
michael@0 | 323 | var bbl = createVector(-10, -10, 10); |
michael@0 | 324 | var bbr = createVector( 10, -10, 10); |
michael@0 | 325 | |
michael@0 | 326 | // cube!!! |
michael@0 | 327 | // front |
michael@0 | 328 | var i = 0; |
michael@0 | 329 | |
michael@0 | 330 | triangles[i++] = new Triangle(tfl, tfr, bfr); |
michael@0 | 331 | triangles[i++] = new Triangle(tfl, bfr, bfl); |
michael@0 | 332 | // back |
michael@0 | 333 | triangles[i++] = new Triangle(tbl, tbr, bbr); |
michael@0 | 334 | triangles[i++] = new Triangle(tbl, bbr, bbl); |
michael@0 | 335 | // triangles[i-1].material = [0.7,0.2,0.2]; |
michael@0 | 336 | // triangles[i-1].material.reflection = 0.8; |
michael@0 | 337 | // left |
michael@0 | 338 | triangles[i++] = new Triangle(tbl, tfl, bbl); |
michael@0 | 339 | // triangles[i-1].reflection = 0.6; |
michael@0 | 340 | triangles[i++] = new Triangle(tfl, bfl, bbl); |
michael@0 | 341 | // triangles[i-1].reflection = 0.6; |
michael@0 | 342 | // right |
michael@0 | 343 | triangles[i++] = new Triangle(tbr, tfr, bbr); |
michael@0 | 344 | triangles[i++] = new Triangle(tfr, bfr, bbr); |
michael@0 | 345 | // top |
michael@0 | 346 | triangles[i++] = new Triangle(tbl, tbr, tfr); |
michael@0 | 347 | triangles[i++] = new Triangle(tbl, tfr, tfl); |
michael@0 | 348 | // bottom |
michael@0 | 349 | triangles[i++] = new Triangle(bbl, bbr, bfr); |
michael@0 | 350 | triangles[i++] = new Triangle(bbl, bfr, bfl); |
michael@0 | 351 | |
michael@0 | 352 | //Floor!!!! |
michael@0 | 353 | var green = createVector(0.0, 0.4, 0.0); |
michael@0 | 354 | var grey = createVector(0.4, 0.4, 0.4); |
michael@0 | 355 | grey.reflection = 1.0; |
michael@0 | 356 | var floorShader = function(tri, pos, view) { |
michael@0 | 357 | var x = ((pos[0]/32) % 2 + 2) % 2; |
michael@0 | 358 | var z = ((pos[2]/32 + 0.3) % 2 + 2) % 2; |
michael@0 | 359 | if (x < 1 != z < 1) { |
michael@0 | 360 | //in the real world we use the fresnel term... |
michael@0 | 361 | // var angle = 1-dot(view, tri.normal); |
michael@0 | 362 | // angle *= angle; |
michael@0 | 363 | // angle *= angle; |
michael@0 | 364 | // angle *= angle; |
michael@0 | 365 | //grey.reflection = angle; |
michael@0 | 366 | return grey; |
michael@0 | 367 | } else |
michael@0 | 368 | return green; |
michael@0 | 369 | } |
michael@0 | 370 | var ffl = createVector(-1000, -30, -1000); |
michael@0 | 371 | var ffr = createVector( 1000, -30, -1000); |
michael@0 | 372 | var fbl = createVector(-1000, -30, 1000); |
michael@0 | 373 | var fbr = createVector( 1000, -30, 1000); |
michael@0 | 374 | triangles[i++] = new Triangle(fbl, fbr, ffr); |
michael@0 | 375 | triangles[i-1].shader = floorShader; |
michael@0 | 376 | triangles[i++] = new Triangle(fbl, ffr, ffl); |
michael@0 | 377 | triangles[i-1].shader = floorShader; |
michael@0 | 378 | |
michael@0 | 379 | var _scene = new Scene(triangles); |
michael@0 | 380 | _scene.lights[0] = createVector(20, 38, -22); |
michael@0 | 381 | _scene.lights[0].colour = createVector(0.7, 0.3, 0.3); |
michael@0 | 382 | _scene.lights[1] = createVector(-23, 40, 17); |
michael@0 | 383 | _scene.lights[1].colour = createVector(0.7, 0.3, 0.3); |
michael@0 | 384 | _scene.lights[2] = createVector(23, 20, 17); |
michael@0 | 385 | _scene.lights[2].colour = createVector(0.7, 0.7, 0.7); |
michael@0 | 386 | _scene.ambient = createVector(0.1, 0.1, 0.1); |
michael@0 | 387 | // _scene.background = createVector(0.7, 0.7, 1.0); |
michael@0 | 388 | |
michael@0 | 389 | var size = 30; |
michael@0 | 390 | var pixels = new Array(); |
michael@0 | 391 | for (var y = 0; y < size; y++) { |
michael@0 | 392 | pixels[y] = new Array(); |
michael@0 | 393 | for (var x = 0; x < size; x++) { |
michael@0 | 394 | pixels[y][x] = 0; |
michael@0 | 395 | } |
michael@0 | 396 | } |
michael@0 | 397 | |
michael@0 | 398 | var _camera = new Camera(createVector(-40, 40, 40), createVector(0, 0, 0), createVector(0, 1, 0)); |
michael@0 | 399 | _camera.render(_scene, pixels, size, size); |
michael@0 | 400 | |
michael@0 | 401 | return pixels; |
michael@0 | 402 | } |
michael@0 | 403 | |
michael@0 | 404 | function arrayToCanvasCommands(pixels) |
michael@0 | 405 | { |
michael@0 | 406 | var s = '<canvas id="renderCanvas" width="30px" height="30px"></canvas><scr' + 'ipt>\nvar pixels = ['; |
michael@0 | 407 | var size = 30; |
michael@0 | 408 | for (var y = 0; y < size; y++) { |
michael@0 | 409 | s += "["; |
michael@0 | 410 | for (var x = 0; x < size; x++) { |
michael@0 | 411 | s += "[" + pixels[y][x] + "],"; |
michael@0 | 412 | } |
michael@0 | 413 | s+= "],"; |
michael@0 | 414 | } |
michael@0 | 415 | s += '];\n var canvas = document.getElementById("renderCanvas").getContext("2d");\n\ |
michael@0 | 416 | \n\ |
michael@0 | 417 | \n\ |
michael@0 | 418 | var size = 30;\n\ |
michael@0 | 419 | canvas.fillStyle = "red";\n\ |
michael@0 | 420 | canvas.fillRect(0, 0, size, size);\n\ |
michael@0 | 421 | canvas.scale(1, -1);\n\ |
michael@0 | 422 | canvas.translate(0, -size);\n\ |
michael@0 | 423 | \n\ |
michael@0 | 424 | if (!canvas.setFillColor)\n\ |
michael@0 | 425 | canvas.setFillColor = function(r, g, b, a) {\n\ |
michael@0 | 426 | this.fillStyle = "rgb("+[Math.floor(r * 255), Math.floor(g * 255), Math.floor(b * 255)]+")";\n\ |
michael@0 | 427 | }\n\ |
michael@0 | 428 | \n\ |
michael@0 | 429 | for (var y = 0; y < size; y++) {\n\ |
michael@0 | 430 | for (var x = 0; x < size; x++) {\n\ |
michael@0 | 431 | var l = pixels[y][x];\n\ |
michael@0 | 432 | canvas.setFillColor(l[0], l[1], l[2], 1);\n\ |
michael@0 | 433 | canvas.fillRect(x, y, 1, 1);\n\ |
michael@0 | 434 | }\n\ |
michael@0 | 435 | }</scr' + 'ipt>'; |
michael@0 | 436 | |
michael@0 | 437 | return s; |
michael@0 | 438 | } |
michael@0 | 439 | |
michael@0 | 440 | testOutput = arrayToCanvasCommands(raytraceScene()); |
michael@0 | 441 | expected = '<canvas id="renderCanvas" width="30px" height="30px"></canvas><script>\nvar pixels = [[[0,0.22646733835486615,0],[0,0.22917348499592718,0],[0,0.23178836719862694,0],[0,0.23429286876882874,0],[0,0.23666708243914814,0],[0,0.2388906159889881,0],[0,0.3260187640505792,0],[0,0.33121005205394954,0],[0,0.3363076586511704,0],[0,0.3412818000213254,0],[0,0.34610095331648705,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.369829536245317,0],[0,0.3725822614817006,0],[0,0.37489560357280544,0],[0,0.37673658797290227,0],[0,0.3780753374916205,0],[0,0.378886188721004,0],[0,0.3791488586269958,0],[0,0.3788495731470844,0],[0,0.3779820527845238,0],[0,0.37654824729910663,0],[0,0.4585834760044105,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],],[[0.8,0.8,1],[0,0.22925665044954321,0],[0,0.2320573979410493,0],[0,0.23474822091583247,0],[0,0.2373069549209832,0],[0,0.2397107002896524,0],[0,0.15436982463108695,0],[0,0.15568628300351414,0],[0,0.33780762567168454,0],[0,0.3431766295062631,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.24744701364085558,0.14604872013179526,0.14604872013179526],[0,0.3743786742105677,0],[0,0.37742123153478285,0],[0,0.3799794006700716,0],[0,0.38201209682126785,0],[0,0.38348180518082586,0],[0,0.384356168843629,0],[0,0.3846096564538848,0],[0,0.3842251672467923,0],[0,0.3831954061706588,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],],[[0.8,0.8,1],[0.8,0.8,1],[0,0.23215413887706876,0],[0,0.2350440502458203,0],[0,0.23780113739316563,0],[0,0.24039973450409946,0],[0,0.24281359296637,0],[0,0.15528082901621987,0],[0,0.15653052853852803,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.24335890550700673,0.1442966737887172,0.1442966737887172],[0.21191595684264103,0.13082112436113186,0.13082112436113186],[0.27664813175852776,0.2248217713585563,0.2248217713585563],[0,0.3823836235518836,0],[0,0.3852234408034573,0],[0,0.38747642030616,0],[0,0.3890951276817348,0],[0,0.39003853152190077,0],[0,0.39027440447223904,0],[0,0.3897816153712006,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],],[[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.23811367607569112,0],[0,0.240922314629212,0],[0,0.2435404294800615,0],[0,0.24593811382698388,0],[0,0.1559883317159253,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.233189785862315,0.13993847965527784,0.13993847965527784],[0.2095470195339134,0.1298058655145343,0.1298058655145343],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.2414541261336147,0.19927150247084813,0.19927150247084813],[0.30463716829842996,0.25698429422662805,0.25698429422662805],[0,0.39057010876231657,0],[0,0.39307456071571556,0],[0,0.394860705064173,0],[0,0.3958762994996104,0],[0,0.3960806578453934,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],],[[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.24123643784061885,0],[0,0.24407545031211067,0],[0,0.24668523203085055,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.20428988349740462,0.1275528072131734,0.1275528072131734],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.2553534506258493,0.21540752629099336,0.21540752629099336],[0.8,0.8,1],[0,0.39871352471166227,0],[0,0.40068391900131317,0],[0,0.4017699848209471,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],],[[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],],[[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.24436322334505386,0],[0,0.24745253188899904,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0,0.40943101981787544,0],[0,0.41179341435345673,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],],[[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.24398601063610253,0],[0,0.24734388131046534,0],[0,0.2504039497369661,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.8,0.8,1],[0,0.41015054936419404,0],[0,0.4139256751539831,0],[0,0.5176011801301246,0],[0,0.5175400296826781,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],],[[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.23925831942915582,0],[0,0.2431514340750372,0],[0,0.24679679895694717,0],[0,0.25013656179204347,0],[0,0.25311244537612027,0],[0,0.2556680399787405,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.06999999999999999,0.06999999999999999,0.06999999999999999],[0.8,0.8,1],[0,0.4078259849771481,0],[0,0.4131357292874544,0],[0,0.5218814714518779,0],[0,0.5233124012306586,0],[0,0.522962771547786,0],[0,0.5207522057325761,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.47311372545546515,0],[0,0.4614041416827006,0],],[[0,0.21490764011046362,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.2331842261176049,0],[0,0.23755980367223836,0],[0,0.24175353358196602,0],[0,0.24570333061205787,0],[0,0.24934343472275186,0],[0,0.252606535195386,0],[0,0.25542647135913205,0],[0,0.25774138056580276,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.04000000000000001,0],[0,0.2913399551219817,0],[0,0.40821549181429595,0],[0,0.5226526471916983,0],[0,0.5257809891986108,0],[0,0.5270304637173788,0],[0,0.5262436797403963,0],[0,0.5233412343635394,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.48095949311801045,0],[0,0.46869626187306984,0],[0,0.4558873544509206,0],],[[0,0.21129537920439745,0],[0,0.2160838834157171,0],[0,0.22090682198375836,0],[0.8,0.8,1],[0,0.23049540839949767,0],[0,0.23516114626695328,0],[0,0.23966144813312718,0],[0,0.24392754707957162,0],[0,0.24788516106908107,0],[0,0.25145680804980497,0],[0,0.2545649373510444,0],[0,0.2571357591990073,0],[0,0.2591035093142245,0],[0,0.15255606913369724,0],[0,0.15301134862115395,0],[0.19736821241316202,0.12458637674849803,0.12458637674849803],[0,0.40504494009802183,0],[0,0.4123372862951718,0],[0,0.4183003766375901,0],[0,0.5268338036458257,0],[0,0.5277169309488912,0],[0,0.5263102439245335,0],[0,0.5225497158196737,0],[0,0.5164937589802646,0],[0.8,0.8,1],[0,0.49832248210805585,0],[0,0.4868414893043067,0],[0,0.47425805574715646,0],[0,0.46093994347307254,0],[0,0.4472184699099014,0],],[[0,0.20695133260602822,0],[0,0.21189973891969208,0],[0,0.21691233850171843,0],[0.8,0.8,1],[0.8,0.8,1],[0,0.23191357418198488,0],[0,0.23671451069678634,0],[0,0.24129830018648707,0],[0,0.24558190818576656,0],[0,0.24947677854650704,0],[0,0.2528923625850763,0],[0,0.1528305739035691,0],[0,0.1542326299051252,0],[0.8,0.8,1],[0.19785925315493239,0.12479682278068532,0.12479682278068532],[0.2081375194488818,0.12920179404952076,0.12920179404952076],[0.2240887656214228,0.18514359742568504,0.18514359742568504],[0,0.4135020430625767,0],[0,0.4192949763868133,0],[0,0.42324582463394744,0],[0,0.524175088930771,0],[0,0.5219574826556216,0],[0,0.5172050501700545,0],[0.8,0.8,1],[0.8,0.8,1],[0,0.4895533585416516,0],[0,0.4770140400123619,0],[0,0.4635030619052592,0],[0,0.44941365075166806,0],[0,0.43508467272477774,0],],[[0,0.20179362237895174,0],[0,0.20685458951965674,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.23760464753632676,0],[0,0.24220528986272394,0],[0,0.2464227921634767,0],[0,0.2501524694953926,0],[0,0.15461153696054686,0],[0.18550977568907606,0.11950418958103261,0.11950418958103261],[0.1973204644052136,0.12456591331652012,0.12456591331652012],[0.2088287796802108,0.12949804843437607,0.12949804843437607],[0.21976471724250635,0.134184878818217,0.134184878818217],[0.23568458491329167,0.19345433251780333,0.19345433251780333],[0.23236149715622312,0.19397984285078584,0.19397984285078584],[0.22707008733584053,0.19247800386744748,0.19247800386744748],[0,0.41921793505330557,0],[0,0.42018199893505187,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.4624620672233052,0],[0,0.4484080186022647,0],[0,0.43394937018864516,0],[0,0.4194117002954933,0],],[[0,0.195751560483372,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.4179362030887152,0],[0.8,0.8,1],[0.18284994643317204,0.11836426275707375,0.11836426275707375],[0.19559717882822145,0.12382736235495205,0.12382736235495205],[0.20829587479733996,0.1292696606274314,0.1292696606274314],[0.22064479825066774,0.13456205639314334,0.13456205639314334],[0.2323223325492669,0.13956671394968584,0.13956671394968584],[0.24724443467900797,0.20148878770701636,0.20148878770701636],[0.24548491352821342,0.20390487818440434,0.20390487818440434],[0.24239083545814452,0.20490715724849212,0.20490715724849212],[0.23580267356471662,0.2022853173521094,0.2022853173521094],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.42907468966717865,0],[0,0.4147140942539032,0],[0.8,0.8,1],],[[0.8,0.8,1],[0,0.19385093619429258,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.40369350610660937,0],[0,0.4158360873491173,0],[0.19261301561109398,0.12254843526189743,0.12254843526189743],[0.20636000368544563,0.1284400015794767,0.1284400015794767],[0.22006309132254379,0.13431275342394736,0.13431275342394736],[0.23336548922639505,0.14001378109702645,0.14001378109702645],[0.24588206119264946,0.1453780262254212,0.1453780262254212],[0.2585904923823373,0.20905557193769056,0.20905557193769056],[0.2583880059856603,0.21340384806404408,0.21340384806404408],[0.2579257731612357,0.21738553706566144,0.21738553706566144],[0.25469196497831764,0.21843261169087974,0.21843261169087974],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.4196956387047621,0],[0,0.40600233966188104,0],[0.8,0.8,1],[0.8,0.8,1],],[[0,0.18086678377768206,0],[0,0.29820732165845826,0],[0,0.3078671511008362,0],[0,0.31797632104786633,0],[0,0.3285185113204014,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.3740646417282967,0],[0,0.38583856211873363,0],[0,0.39747405235976174,0],[0.2029477686069114,0.12697761511724776,0.12697761511724776],[0.21781735307317274,0.1333502941742169,0.1333502941742169],[0.2326566051026994,0.13970997361544257,0.13970997361544257],[0.2470420370437997,0.145875158733057,0.145875158733057],[0.9125534455486627,0.5106731929990184,0.5106731929990184],[0.26957187383368114,0.21599310805975738,0.21599310805975738],[0.2707166126603939,0.2221190287629908,0.2221190287629908],[0.2730659500911373,0.22930539474084957,0.22930539474084957],[0.27432898752113144,0.23520013372187343,0.23520013372187343],[0,0.370913970040732,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.41728826192115065,0],[0,0.4053708259838642,0],[0,0.39282677897301016,0],[0,0.37998757881530154,0],[0,0.3671261088322657,0],[0.8,0.8,1],],[[0,0.2734507658091365,0],[0,0.28211354268150884,0],[0,0.29120495530846624,0],[0,0.3007197072254542,0],[0,0.31064069882287787,0],[0,0.32093517914620384,0],[0,0.3315502317284035,0],[0,0.34240777559380986,0],[0,0.35339949423457706,0],[0,0.3643824114196257,0],[0,0.3751761555363945,0],[0.21384735597314658,0.13164886684563426,0.13164886684563426],[0.2299739346154931,0.1385602576923542,0.1385602576923542],[0.24609657496992726,0.1454699607013974,0.1454699607013974],[0.9085781768104235,0.508698320758555,0.508698320758555],[0.9154549906081679,0.5170357163338555,0.5170357163338555],[0.9205088622142807,0.5252164494222175,0.5252164494222175],[0.28215745535360465,0.22973861951523428,0.22973861951523428],[0.2871003088909314,0.23996159648606105,0.23996159648606105],[0.29363706106359355,0.2515193872815144,0.2515193872815144],[0,0.41902122210815307,0],[0,0.41310298499553366,0],[0,0.40544274823125576,0],[0,0.396335311262737,0],[0,0.3861118369914827,0],[0,0.37510764377615097,0],[0,0.3636351145776063,0],[0,0.35196551120236436,0],[0,0.3403202703614798,0],[0,0.32887008288221503,0],],[[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.28175542273932297,0],[0,0.29085225965171946,0],[0,0.3002718747152153,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.3493460616221397,0],[0.22528651843925174,0.1365513650453936,0.1365513650453936],[0.884020287542635,0.49068080880618953,0.49068080880618953],[0.8974534722142382,0.5016001274737849,0.5016001274737849],[0.9089511260291274,0.5124192313516149,0.5124192313516149],[0.918724776273931,0.5233733004162796,0.5233733004162796],[0.9271769325614658,0.5348099989058438,0.5348099989058438],[0.9348913571357613,0.5471866228466732,0.5471866228466732],[0.9425953513779031,0.5610467455399599,0.5610467455399599],[0.31111289810529186,0.2659003418574735,0.2659003418574735],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.36238100335464446,0],[0,0.353165370752559,0],[0,0.3433460721377995,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],],[[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.269553510147819,0],[0,0.2779247384646558,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.862863795871991,0.4769708653359615,0.4769708653359615],[0.8809280461363547,0.48977541774660666,0.48977541774660666],[0.8970168973464191,0.5025218831442017,0.5025218831442017],[0.911183718592768,0.5154210174684783,0.5154210174684783],[0.923749369873305,0.5288572912288372,0.5288572912288372],[0.9353543113230034,0.5434323975814477,0.5434323975814477],[0.9469976115499875,0.5600089248350288,0.5600089248350288],[0.9600573266066551,0.5797476044207045,0.5797476044207045],[0.976264515309917,0.6041064704498702,0.6041064704498702],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.31964250752889856,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],],[[0,0.22050019052313752,0],[0,0.22681553981028935,0],[0,0.23339203717763343,0],[0,0.240214496679792,0],[0,0.24725746972595297,0],[0,0.25448250911433834,0],[0,0.26183515020613984,0],[0,0.26924183890499,0],[0,0.27660721846944913,0],[0,0.2838124066288337,0],[0,0.290715098224911,0],[0,0.2971524154784058,0],[0,0.3029472623689724,0],[0,0.3079184123129743,0],[0.9166547694971252,0.5166323224598249,0.5166323224598249],[0.9306991201883348,0.5311982918579957,0.5311982918579957],[0.942986803591991,0.5467760342781277,0.5467760342781277],[0,0.3165578521241011,0],[0,0.31548839579667104,0],[0,0.3131368632708015,0],[0.8,0.8,1],[0,0.30500137342777356,0],[0,0.29951030523776406,0],[0,0.29329773299429385,0],[0,0.28653936257609475,0],[0,0.27940222592749825,0],[0.8,0.8,1],[0,0.26457440761040923,0],[0,0.2571216942588568,0],[0,0.24976474642245705,0],],[[0.8,0.8,1],[0,0.20714814874471174,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.23670584867979186,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.2653456430194066,0],[0,0.2698801253354915,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.2797697633705014,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.2652596644585568,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.23044738434960232,0],[0.8,0.8,1],],[[0.8,0.8,1],[0,0.1874620478256095,0],[0,0.19215316230371715,0],[0,0.19696169224108015,0],[0,0.20186087426658073,0],[0,0.20681514030842463,0],[0,0.2117788084075138,0],[0,0.21669500719585458,0],[0,0.22149508562026893,0],[0,0.22609882383824634,0],[0,0.23041578943560334,0],[0,0.23434813805418903,0],[0,0.23779500435424242,0],[0,0.240658357082728,0],[0.8,0.8,1],[0,0.24429776275232565,0],[0,0.24495325891611666,0],[0,0.24479455500778916,0],[0,0.24382873003864916,0],[0.8,0.8,1],[0,0.23963973129383997,0],[0,0.23655408649128906,0],[0,0.23292473874860314,0],[0,0.2288489260033022,0],[0.8,0.8,1],[0,0.21974417921637143,0],[0,0.21489400490094954,0],[0,0.20994923454342304,0],[0,0.20497430079270745,0],[0.8,0.8,1],],[[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.1797204574749079,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.19516287408734248,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.2074862652007326,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.20573701126457444,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.19259287153244908,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.17697513874785395,0],],[[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.1614935034375082,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.17936757268974335,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.17026872079690972,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],],[[0,0.12879641411423945,0],[0.8,0.8,1],[0.8,0.8,1],[0,0.1358377385211167,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.1546643297719027,0],[0.8,0.8,1],[0.8,0.8,1],[0,0.1559650385862031,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.14211514071040432,0],[0.8,0.8,1],[0.8,0.8,1],[0,0.13513052327523242,0],],[[0,0.11212384156112787,0],[0.8,0.8,1],[0,0.11564325792725064,0],[0,0.1174011949544484,0],[0.8,0.8,1],[0,0.12084571295779206,0],[0,0.12249918688067803,0],[0,0.1240816293005488,0],[0,0.12557222890553357,0],[0.8,0.8,1],[0,0.12819024296879525,0],[0,0.12927368617900967,0],[0.8,0.8,1],[0,0.13088813449481448,0],[0,0.13138603838942955,0],[0.8,0.8,1],[0,0.13170953912018962,0],[0.8,0.8,1],[0,0.13112114069722186,0],[0,0.13049815823500216,0],[0.8,0.8,1],[0,0.12866048872503766,0],[0,0.1274822855623644,0],[0.8,0.8,1],[0,0.1247126669400825,0],[0,0.12316534788101306,0],[0,0.12153830315457151,0],[0,0.11985151859147432,0],[0.8,0.8,1],[0,0.11637011656642021,0],],[[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.104782462250846,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.1094376687357348,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],],[[0.8,0.8,1],[0.8,0.8,1],[0,0.0830756783895465,0],[0.8,0.8,1],[0,0.08474229354589341,0],[0.8,0.8,1],[0.8,0.8,1],[0,0.08702004690763979,0],[0.8,0.8,1],[0,0.08829471061229066,0],[0.8,0.8,1],[0.8,0.8,1],[0,0.0896722795161435,0],[0.8,0.8,1],[0,0.0901512080809384,0],[0.8,0.8,1],[0.8,0.8,1],[0,0.09012955842093213,0],[0.8,0.8,1],[0,0.08962319641070081,0],[0.8,0.8,1],[0.8,0.8,1],[0,0.08821080590025861,0],[0.8,0.8,1],[0,0.08691857775431859,0],[0.8,0.8,1],[0.8,0.8,1],[0,0.08462346811430875,0],[0.8,0.8,1],[0,0.08295071578903558,0],],[[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.06935458357760912,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.07223735845162484,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0,0.07191875490542338,0],[0,0.07163456254931609,0],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],],[[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],[0.8,0.8,1],],];\n var canvas = document.getElementById("renderCanvas").getContext("2d");\n\n\n var size = 30;\n canvas.fillStyle = "red";\n canvas.fillRect(0, 0, size, size);\n canvas.scale(1, -1);\n canvas.translate(0, -size);\n\n if (!canvas.setFillColor)\n canvas.setFillColor = function(r, g, b, a) {\n this.fillStyle = "rgb("+[Math.floor(r * 255), Math.floor(g * 255), Math.floor(b * 255)]+")";\n }\n\nfor (var y = 0; y < size; y++) {\n for (var x = 0; x < size; x++) {\n var l = pixels[y][x];\n canvas.setFillColor(l[0], l[1], l[2], 1);\n canvas.fillRect(x, y, 1, 1);\n }\n}</script>'; |
michael@0 | 442 | assertEq(testOutput, expected) |