How to use drawFigure method in wpt

Best JavaScript code snippet using wpt

tilemanager.ts

Source:tilemanager.ts Github

copy

Full Screen

...138 this.ctx.stroke();139 }140 }141 }142 private drawFigure(fig: Array<Array<number>>, repeat: number, addBeginStroke: boolean = true) {143 for (let pa of fig) {144 for (let i = 0; i < repeat; ++i) {145 if (addBeginStroke) this.drawPrimitive([DP.begin]);146 this.drawPrimitive(pa);147 if (addBeginStroke) this.drawPrimitive([DP.stroke]);148 }149 }150 }151 private prepare() {152 this.cacheCanvas.width = cacheCanvasWidth;153 this.cacheCanvas.height = cacheCanvasHeight;154 this.ctx = this.cacheCanvas.getContext('2d');155 let ctx = this.ctx;156 ctx.fillStyle = 'rgba(255,255,255,0.2)';157 let r = this.getCacheRecord('tile-highlight');158 let pos = this.getNextCachePos();159 r.addFrame(pos);160 ctx.fillRect(pos.x, pos.y, tileSize, tileSize);161 ctx.lineWidth = 2;162 ctx.shadowBlur = tileGlowSize;163 this.genPlayer();164 ctx.shadowColor = 'cyan';165 ctx.strokeStyle = 'cyan';166 this.genMarker();167 //this.genConnection('my');168 this.genFeatures();169 this.genFloor();170 this.genDoors();171 this.genDirMarks()172 this.genStunEffect()173 this.genStairsDown()174 ctx.shadowColor = 'white';175 ctx.strokeStyle = 'white';176 this.genWalls();177 ctx.shadowColor = 'red';178 ctx.strokeStyle = 'red';179 this.genEnemies();180 const tilesPerRow = (cacheCanvasWidth / tileFullSize) | 0;181 const totalRows = (cacheCanvasHeight / tileFullSize) | 0;182 const totalTiles = tilesPerRow * totalRows;183 console.log(`cache:${this.cacheLastIdx}/${totalTiles} (%${100 * this.cacheLastIdx / totalTiles})`);184 }185 private genMarker() {186 let r = this.getCacheRecord('marker');187 for (let f = 0; f < 8; ++f) {188 r.addFrame(this.getNextCachePos());189 let fa: Array<Array<number>> = [];190 for (let i = 0; i < 4; ++i) {191 fa.push([DP.begin]);192 let arc = [DP.arc, 0.5, 0.5, 0.55];193 let sig = ((i & 1) * 2 - 1);194 let a1 = ((f / 8) * sig + (i & 2) / 2);195 let a2 = a1 + sig / 10;196 arc.push(a1, a2, sig > 0 ? 0 : 1);197 fa.push(arc, [DP.stroke]);198 }199 this.drawFigure(fa, 1, false);200 }201 }202 203 private genStunEffect() {204 let ctx = this.ctx205 ctx.shadowColor = 'white';206 ctx.strokeStyle = 'white';207 let r = this.getCacheRecord('stun-effect');208 let a = [ 0, 2.0/4.0, 4.0/4.0, 6.0/4.0]209 let delta = 0.15210 for (let f = 0; f < 20; ++f) {211 r.addFrame(this.getNextCachePos());212 for(let i=0;i<4;++i) {213 let x1 = 0.5+ssin(a[i])/2214 let x2 = 0.5+ssin(a[i]+delta)/2215 let y1 = 0.1+0.1*scos(a[i])/2216 let y2 = 0.1+0.1*scos(a[i]+delta)/2217 this.drawFigure([[DP.line, x1, y1, x2, y2]], 1)218 a[i]+=1.0/20219 }220 }221 }222 private genDirMarks() {223 let ctx = this.ctx224 ctx.shadowColor = 'lightgrey';225 ctx.strokeStyle = 'lightgrey';226 let r = this.getCacheRecord('dir-up');227 r.addFrame(this.getNextCachePos());228 this.drawFigure([[DP.line, 0.25, 0.75, 0.5, 0.5, 0.75, 0.75]], 1)229 r = this.getCacheRecord('dir-down');230 r.addFrame(this.getNextCachePos());231 this.drawFigure([[DP.line, 0.25, 0.25, 0.5, 0.5, 0.75, 0.25]], 1) 232 r = this.getCacheRecord('dir-left');233 r.addFrame(this.getNextCachePos());234 this.drawFigure([[DP.line, 0.75, 0.25, 0.5, 0.5, 0.75, 0.75]], 1) 235 r = this.getCacheRecord('dir-right');236 r.addFrame(this.getNextCachePos());237 this.drawFigure([[DP.line, 0.25, 0.25, 0.5, 0.5, 0.25, 0.75]], 1) 238 }239 private genFeatures() {240 this.ctx.lineWidth = 2;241 let r = this.getCacheRecord('connector');242 r.addFrame(this.getNextCachePos());243 let box = [DP.line, 0.1, 0.1, 0.9, 0.1, 0.9, 0.9, 0.1, 0.9, 0.1, 0.1];244 this.drawFigure([245 box,246 [DP.line, 0.25, 0.5, 0.5, 0.25, 0.75, 0.5, 0.5, 0.75, 0.25, 0.5]247 ], 1)248 r = this.getCacheRecord('data-box');249 r.addFrame(this.getNextCachePos());250 this.drawFigure([251 box,252 [DP.line, 0.2, 0.3, 0.8, 0.3],253 [DP.line, 0.2, 0.5, 0.8, 0.5],254 [DP.line, 0.2, 0.7, 0.8, 0.7],255 ], 1)256 r = this.getCacheRecord('data-processor');257 for (let f = 0; f < 11; ++f) {258 r.addFrame(this.getNextCachePos());259 let x1 = 0.8 * (f > 4 ? 10 - f : f) / 5;260 let x2 = 0.8 - x1;261 this.drawFigure([262 box,263 [DP.line, 0.1 + x1, 0.1, 0.1 + x2, 0.9],264 ], 1)265 }266 }267 private genPlayer() {268 let ctx = this.ctx269 ctx.shadowColor = idleColor;270 ctx.strokeStyle = idleColor;271 let r = this.getCacheRecord('player-1');272 r.addFrame(this.getNextCachePos());273 this.drawFigure([274 [DP.arc, 0.5, 0.5, 0.2, 0, 2],275 [DP.stroke],276 [DP.line, 0.7, 0.3, 0.7, 0.7],277 [DP.line, 0.7, 0.7, 0.92, 0.7],278 [DP.arc, 0.5, 0.5, 0.45, 0.12, 0.3, 1]279 ], 1);280 ctx.shadowColor = impulseColor;281 ctx.strokeStyle = impulseColor;282 r = this.getCacheRecord('player-2');283 r.addFrame(this.getNextCachePos());284 this.drawFigure([285 [DP.arc, 0.5, 0.5, 0.2, 0, 2],286 [DP.stroke],287 [DP.line, 0.7, 0.3, 0.7, 0.7],288 [DP.line, 0.7, 0.7, 0.8, 0.7, 1, 0.5, 0.5, 0, 0, 0.5, 0.5, 1, 0.7, 0.8],289 ], 1);290 ctx.shadowColor = impactColor;291 ctx.strokeStyle = impactColor;292 r = this.getCacheRecord('player-3');293 r.addFrame(this.getNextCachePos());294 this.drawFigure([295 [DP.arc, 0.5, 0.5, 0.2, 0, 2],296 [DP.stroke],297 [DP.line, 0.7, 0.3, 0.7, 0.7],298 [DP.line, 0.7, 0.7, 0.85, 0.65, 0.80, 0.5, 1, 0, 0.5, 0.2, 0, 0, 0.2, 0.5, 0, 1, 0.5, 0.8, 1, 1, 0.9, 0.8],299 ], 1);300 }301 private genConnection(prefix: string) {302 const rep = 1;303 let r = this.getCacheRecord(prefix + '-connection-piece-lr');304 for (let f = 0; f < 25; ++f) {305 r.addFrame(this.getNextCachePos());306 let fig1 = [DP.line];307 let fig2 = [DP.line];308 genHWaves(fig1, fig2, f, 0, 1);309 this.drawFigure([fig1, fig2], rep);310 }311 r = this.getCacheRecord(prefix + '-connection-piece-tb');312 for (let f = 0; f < 25; ++f) {313 r.addFrame(this.getNextCachePos());314 let fig1 = [DP.line];315 let fig2 = [DP.line];316 genVWaves(fig1, fig2, f, 0, 1.1);317 this.drawFigure([fig1, fig2], rep);318 }319 let sq = [DP.line, 0.25, 0.25, 0.25, 0.75, 0.75, 0.75, 0.75, 0.25, 0.25, 0.25];320 r = this.getCacheRecord(prefix + '-connection-piece-bl');321 for (let f = 0; f < 25; ++f) {322 r.addFrame(this.getNextCachePos());323 let fig1 = [DP.line];324 let fig2 = [DP.line];325 genHWaves(fig1, fig2, f, 0, 0.3);326 let idx1 = fig1.length;327 let idx2 = fig2.length;328 fig1.push(0, fig1[idx1 - 1]);329 fig2.push(0, fig2[idx2 - 1]);330 genVWaves(fig1, fig2, f, 0.7, 1.1);331 fig1[idx1] = fig1[idx1 + 2];332 fig2[idx2] = fig2[idx2 + 2];333 this.drawFigure([fig1, fig2, sq], rep);334 }335 r = this.getCacheRecord(prefix + '-connection-piece-br');336 for (let f = 0; f < 25; ++f) {337 r.addFrame(this.getNextCachePos());338 let fig1 = [DP.line];339 let fig2 = [DP.line];340 genHWaves(fig1, fig2, f, 0.7, 1.1);341 reverseByPairs(fig1);342 reverseByPairs(fig2);343 let idx1 = fig1.length;344 let idx2 = fig2.length;345 fig1.push(0, fig1[idx1 - 1]);346 fig2.push(0, fig2[idx2 - 1]);347 genVWaves(fig1, fig2, f, 0.7, 1.1);348 fig1[idx1] = fig1[idx1 + 2];349 fig2[idx2] = fig2[idx2 + 2];350 this.drawFigure([fig1, fig2, sq], rep);351 }352 r = this.getCacheRecord(prefix + '-connection-piece-tl');353 for (let f = 0; f < 25; ++f) {354 r.addFrame(this.getNextCachePos());355 let fig1 = [DP.line];356 let fig2 = [DP.line];357 genHWaves(fig1, fig2, f, 0.0, 0.3);358 let idx1 = fig1.length;359 let idx2 = fig2.length;360 fig1.push(0, fig1[idx1 - 1]);361 fig2.push(0, fig2[idx2 - 1]);362 genVWaves(fig1, fig2, f, 0.0, 0.3);363 reverseByPairs(fig1, idx1 + 2);364 reverseByPairs(fig2, idx2 + 2);365 fig1[idx1] = fig1[idx1 + 2];366 fig2[idx2] = fig2[idx2 + 2];367 this.drawFigure([fig1, fig2, sq], rep);368 }369 r = this.getCacheRecord(prefix + '-connection-piece-tr');370 for (let f = 0; f < 25; ++f) {371 r.addFrame(this.getNextCachePos());372 let fig1 = [DP.line];373 let fig2 = [DP.line];374 genVWaves(fig1, fig2, f, 0, 0.3);375 let idx1 = fig1.length;376 let idx2 = fig2.length;377 fig1.push(fig1[idx1 - 2], 0);378 fig2.push(fig2[idx2 - 2], 0);379 genHWaves(fig1, fig2, f, 0.7, 1.1);380 fig1[idx1 + 1] = fig1[idx1 + 3];381 fig2[idx2 + 1] = fig2[idx2 + 3];382 this.drawFigure([fig1, fig2, sq], rep);383 }384 r = this.getCacheRecord(prefix + '-connection-piece-tlr');385 for (let f = 0; f < 25; ++f) {386 r.addFrame(this.getNextCachePos());387 let fig1 = [DP.line];388 let fig2 = [DP.line];389 genVWaves(fig1, fig2, f, 0, 0.3);390 let idx1 = fig1.length;391 let idx2 = fig2.length;392 let x1 = fig1[idx1 - 2];393 let x2 = fig2[idx2 - 2];394 fig1.push(fig1[idx1 - 2], 0);395 fig2.push(fig2[idx2 - 2], 0);396 genHWaves(fig1, fig2, f, 0.7, 1.1);397 fig1[idx1 + 1] = fig1[idx1 + 3];398 fig2[idx2 + 1] = fig2[idx2 + 3];399 let y1 = fig1[idx1 + 3];400 let y2 = fig2[idx2 + 3]401 this.drawFigure([fig1, fig2, sq], rep);402 fig1 = [DP.line];403 fig2 = [DP.line];404 genHWaves(fig1, fig2, f, 0, 0.3);405 fig1.push(x1, y1);406 fig2.push(x2, y2);407 this.drawFigure([fig1, fig2], rep);408 }409 r = this.getCacheRecord(prefix + '-connection-piece-blr');410 for (let f = 0; f < 25; ++f) {411 r.addFrame(this.getNextCachePos());412 let fig1 = [DP.line];413 let fig2 = [DP.line];414 genHWaves(fig1, fig2, f, 0, 0.3);415 let idx1 = fig1.length;416 let idx2 = fig2.length;417 fig1.push(0, fig1[idx1 - 1]);418 fig2.push(0, fig2[idx2 - 1]);419 let y1 = fig1[idx1 - 1];420 let y2 = fig2[idx2 - 1];421 genVWaves(fig1, fig2, f, 0.7, 1.1);422 fig1[idx1] = fig1[idx1 + 2];423 fig2[idx2] = fig2[idx2 + 2];424 let x1 = fig1[idx1 + 2];425 let x2 = fig2[idx2 + 2];426 this.drawFigure([fig1, fig2, sq], rep);427 fig1 = [DP.line];428 fig2 = [DP.line];429 fig1.push(x1, y1);430 fig2.push(x2, y2);431 genHWaves(fig1, fig2, f, 0.7, 1.1);432 this.drawFigure([fig1, fig2], rep);433 }434 r = this.getCacheRecord(prefix + '-connection-piece-tbl');435 for (let f = 0; f < 25; ++f) {436 r.addFrame(this.getNextCachePos());437 let fig1 = [DP.line];438 let fig2 = [DP.line];439 genHWaves(fig1, fig2, f, 0.0, 0.3);440 let idx1 = fig1.length;441 let idx2 = fig2.length;442 fig1.push(0, fig1[idx1 - 1]);443 fig2.push(0, fig2[idx2 - 1]);444 let y1 = fig1[idx1 - 1];445 let y2 = fig2[idx2 - 1];446 genVWaves(fig1, fig2, f, 0.0, 0.3);447 reverseByPairs(fig1, idx1 + 2);448 reverseByPairs(fig2, idx2 + 2);449 fig1[idx1] = fig1[idx1 + 2];450 fig2[idx2] = fig2[idx2 + 2];451 let x1 = fig1[idx1 + 2];452 let x2 = fig2[idx2 + 2];453 this.drawFigure([fig1, fig2, sq], rep);454 fig1 = [DP.line];455 fig2 = [DP.line];456 fig1.push(x1, y1);457 fig2.push(x2, y2);458 genVWaves(fig1, fig2, f, 0.7, 1.1);459 this.drawFigure([fig1, fig2], rep);460 }461 r = this.getCacheRecord(prefix + '-connection-piece-tbr');462 for (let f = 0; f < 25; ++f) {463 r.addFrame(this.getNextCachePos());464 let fig1 = [DP.line];465 let fig2 = [DP.line];466 genVWaves(fig1, fig2, f, 0, 0.3);467 let idx1 = fig1.length;468 let idx2 = fig2.length;469 fig1.push(fig1[idx1 - 2], 0);470 fig2.push(fig2[idx2 - 2], 0);471 let x1 = fig1[idx1 - 2];472 let x2 = fig2[idx2 - 2];473 genHWaves(fig1, fig2, f, 0.7, 1.1);474 fig1[idx1 + 1] = fig1[idx1 + 3];475 fig2[idx2 + 1] = fig2[idx2 + 3];476 let y1 = fig1[idx1 + 3];477 let y2 = fig2[idx2 + 3]478 this.drawFigure([fig1, fig2, sq], rep);479 fig1 = [DP.line];480 fig2 = [DP.line];481 fig1.push(x1, y1);482 fig2.push(x2, y2);483 genVWaves(fig1, fig2, f, 0.7, 1.1);484 this.drawFigure([fig1, fig2], rep);485 }486 r = this.getCacheRecord(prefix + '-connection-piece-tblr');487 for (let f = 0; f < 25; ++f) {488 r.addFrame(this.getNextCachePos());489 let fig1 = [DP.line];490 let fig2 = [DP.line];491 genVWaves(fig1, fig2, f, 0, 0.3);492 let idx1 = fig1.length;493 let idx2 = fig2.length;494 fig1.push(fig1[idx1 - 2], 0);495 fig2.push(fig2[idx2 - 2], 0);496 let x1 = fig1[idx1 - 2];497 let x2 = fig2[idx2 - 2];498 genHWaves(fig1, fig2, f, 0.7, 1.1);499 fig1[idx1 + 1] = fig1[idx1 + 3];500 fig2[idx2 + 1] = fig2[idx2 + 3];501 let y1 = fig1[idx1 + 3];502 let y2 = fig2[idx2 + 3]503 this.drawFigure([fig1, fig2, sq], rep);504 fig1 = [DP.line];505 fig2 = [DP.line];506 fig1.push(x1, y1);507 fig2.push(x2, y2);508 genVWaves(fig1, fig2, f, 0.7, 1.1);509 this.drawFigure([fig1, fig2], rep);510 fig1 = [DP.line];511 fig2 = [DP.line];512 genHWaves(fig1, fig2, f, 0, 0.3);513 fig1.push(x1, y1);514 fig2.push(x2, y2);515 this.drawFigure([fig1, fig2], rep);516 }517 r = this.getCacheRecord(prefix + '-connection-piece-t');518 for (let f = 0; f < 25; ++f) {519 r.addFrame(this.getNextCachePos());520 let fig1 = [DP.line];521 let fig2 = [DP.line];522 genVWaves(fig1, fig2, f, 0, 0.3);523 let arc = [DP.arc, 0.5, 0.5, 0.3, 0, 2];524 let fa = [fig1, fig2, arc];525 genSparks(fa, f);526 this.drawFigure(fa, rep);527 }528 r = this.getCacheRecord(prefix + '-connection-piece-b');529 for (let f = 0; f < 25; ++f) {530 r.addFrame(this.getNextCachePos());531 let fig1 = [DP.line];532 let fig2 = [DP.line];533 genVWaves(fig1, fig2, f, 0.7, 1.1);534 let arc = [DP.arc, 0.5, 0.5, 0.3, 0, 2];535 let fa = [fig1, fig2, arc];536 genSparks(fa, f);537 this.drawFigure(fa, rep);538 }539 r = this.getCacheRecord(prefix + '-connection-piece-l');540 for (let f = 0; f < 25; ++f) {541 r.addFrame(this.getNextCachePos());542 let fig1 = [DP.line];543 let fig2 = [DP.line];544 genHWaves(fig1, fig2, f, 0, 0.3);545 let arc = [DP.arc, 0.5, 0.5, 0.3, 0, 2];546 let fa = [fig1, fig2, arc];547 genSparks(fa, f);548 this.drawFigure(fa, rep);549 }550 r = this.getCacheRecord(prefix + '-connection-piece-r');551 for (let f = 0; f < 25; ++f) {552 r.addFrame(this.getNextCachePos());553 let fig1 = [DP.line];554 let fig2 = [DP.line];555 genHWaves(fig1, fig2, f, 0.7, 1.1);556 let arc = [DP.arc, 0.5, 0.5, 0.3, 0, 2];557 let fa = [fig1, fig2, arc];558 genSparks(fa, f);559 this.drawFigure(fa, rep);560 }561 }562 private genEnemies() {563 this.ctx.lineWidth = 1.5;564 let r = this.getCacheRecord('muncher');565 for (let f = 0; f < 5; ++f) {566 r.addFrame(this.getNextCachePos());567 let d = f / 20;568 this.drawFigure([569 [DP.arc, 0.5, 0.5, 0.45, 0, 2],570 [DP.arc, 0.3, 0.3, 0.04, 0, 2],571 [DP.arc, 0.7, 0.3, 0.04, 0, 2],572 [DP.line, 0.25, 0.75 + d, 0.25 + 0.125, 0.75 - 0.125 + d],573 [DP.line, 0.25 + 0.125, 0.75 - 0.125 + d, 0.5, 0.75 + d],574 [DP.line, 0.5, 0.75 + d, 0.5 + 0.125, 0.75 - 0.125 + d],575 [DP.line, 0.5 + 0.125, 0.75 - 0.125 + d, 0.75, 0.75 + d],576 [DP.line, 0.25, 0.75 - d, 0.25 + 0.125, 0.75 - 0.125 - d],577 [DP.line, 0.25 + 0.125, 0.75 - 0.125 - d, 0.5, 0.75 - d],578 [DP.line, 0.5, 0.75 - d, 0.5 + 0.125, 0.75 - 0.125 - d],579 [DP.line, 0.5 + 0.125, 0.75 - 0.125 - d, 0.75, 0.75 - d],580 ], 2);581 }582 r = this.getCacheRecord('spyware');583 for (let f = 0; f < 10; ++f) {584 r.addFrame(this.getNextCachePos());585 let d = 0.15 * f / 10;586 this.drawFigure([587 [DP.arc, 0.5, 0.5, 0.45, 0, 2],588 [DP.line, 0.2, 0.4, 0.2 + d, 0.4],589 [DP.line, 0.3 + d, 0.4, 0.4, 0.4],590 [DP.line, 0.6, 0.4, 0.6 + d, 0.4],591 [DP.line, 0.7 + d, 0.4, 0.8, 0.4],592 [DP.line, 0.25, 0.7, 0.75, 0.7]593 ], 2);594 }595 }596 private genWallSegment(name: string, fig: Array<Array<number>>) {597 let r = this.getCacheRecord(name);598 for (let f = 0; f < 5; ++f) {599 r.addFrame(this.getNextCachePos());600 this.drawFigure(fig, 1 + f);601 }602 }603 private genWalls() {604 this.ctx.lineWidth = 4;605 this.ctx.lineCap = "round";606 this.genWallSegment('wall-tb', [[DP.line, 0.5, 0, 0.5, 1]]);607 this.genWallSegment('wall-lr', [[DP.line, 0, 0.5, 1, 0.5]])608 this.genWallSegment('wall-tr', [609 [DP.line, 0.5, 0, 0.5, 0.25],610 [DP.arc, 0.75, 0.25, 0.25, 1, 0.5, 1],611 [DP.line, 0.75, 0.5, 1, 0.5]612 ]);613 this.genWallSegment('wall-tl', [614 [DP.line, 0.5, 0, 0.5, 0.25],615 [DP.arc, 0.25, 0.25, 0.25, 0, 0.5, 0],616 [DP.line, 0.25, 0.5, 0, 0.5]617 ]);618 this.genWallSegment('wall-br', [619 [DP.line, 0.5, 1, 0.5, 0.75],620 [DP.arc, 0.75, 0.75, 0.25, 1, 1.5, 0],621 [DP.line, 0.75, 0.5, 1, 0.5]622 ]);623 this.genWallSegment('wall-bl', [624 [DP.line, 0.5, 1, 0.5, 0.75],625 [DP.arc, 0.25, 0.75, 0.25, 2, 1.5, 1],626 [DP.line, 0.25, 0.5, 0, 0.5]627 ]);628 this.genWallSegment('wall-tbl', [[DP.line, 0.5, 0, 0.5, 1], [DP.line, 0, 0.5, 0.5, 0.5]]);629 this.genWallSegment('wall-tbr', [[DP.line, 0.5, 0, 0.5, 1], [DP.line, 0.5, 0.5, 1, 0.5]]);630 this.genWallSegment('wall-tlr', [[DP.line, 0, 0.5, 1, 0.5], [DP.line, 0.5, 0, 0.5, 0.5]]);631 this.genWallSegment('wall-blr', [[DP.line, 0, 0.5, 1, 0.5], [DP.line, 0.5, 0.5, 0.5, 1]]);632 this.genWallSegment('wall-tblr', [[DP.line, 0, 0.5, 1, 0.5], [DP.line, 0.5, 0, 0.5, 1]]);633 }634 private genFloor() {635 //this.ctx.strokeStyle='#00A0A0';636 /*637 this.ctx.lineWidth = 1.5;638 this.ctx.lineCap = "round";639 this.genWallSegment('floor-tb', [[DP.line, 0.5, 0, 0.5, 1]]);640 this.genWallSegment('floor-lr', [[DP.line, 0, 0.5, 1, 0.5]])641 this.genWallSegment('floor-tr', [642 [DP.line, 0.5, 0, 0.5, 0.25],643 [DP.arc, 0.75, 0.25, 0.25, 1, 0.5, 1],644 [DP.line, 0.75, 0.5, 1, 0.5]645 ]);646 this.genWallSegment('floor-tl', [647 [DP.line, 0.5, 0, 0.5, 0.25],648 [DP.arc, 0.25, 0.25, 0.25, 0, 0.5, 0],649 [DP.line, 0.25, 0.5, 0, 0.5]650 ]);651 this.genWallSegment('floor-br', [652 [DP.line, 0.5, 1, 0.5, 0.75],653 [DP.arc, 0.75, 0.75, 0.25, 1, 1.5, 0],654 [DP.line, 0.75, 0.5, 1, 0.5]655 ]);656 this.genWallSegment('floor-bl', [657 [DP.line, 0.5, 1, 0.5, 0.75],658 [DP.arc, 0.25, 0.75, 0.25, 2, 1.5, 1],659 [DP.line, 0.25, 0.5, 0, 0.5]660 ]);661 this.genWallSegment('floor-tbl', [[DP.line, 0.5, 0, 0.5, 1], [DP.line, 0, 0.5, 0.5, 0.5]]);662 this.genWallSegment('floor-tbr', [[DP.line, 0.5, 0, 0.5, 1], [DP.line, 0.5, 0.5, 1, 0.5]]);663 this.genWallSegment('floor-tlr', [[DP.line, 0, 0.5, 1, 0.5], [DP.line, 0.5, 0, 0.5, 0.5]]);664 this.genWallSegment('floor-blr', [[DP.line, 0, 0.5, 1, 0.5], [DP.line, 0.5, 0.5, 0.5, 1]]);665 this.genWallSegment('floor-tblr', [[DP.line, 0, 0.5, 1, 0.5], [DP.line, 0.5, 0, 0.5, 1]]);666 this.genWallSegment('floor', [[DP.line, 0, 0, 1, 1], [DP.line, 1, 0, 0, 1]])*/667 this.ctx.strokeStyle = '#888888';668 let r = this.getCacheRecord('floor');669 r.addFrame(this.getNextCachePos());670 let cr = 0.1671 this.ctx.lineWidth = 1;672 this.ctx.shadowColor='#888888'673 this.drawFigure([[DP.arc, 0.5, 0.5, cr, 0, 2], 674 [DP.line, 0.5, 0.5-cr, 0.5, 0], 675 [DP.line, 0.5, 0.5+cr, 0.5, 1],676 [DP.line, 0.5-cr, 0.5, 0, 0.5], 677 [DP.line, 0.5+cr, 0.5, 1, 0.5],678 ],1);679 // this.drawFigure([[DP.arc, 0.5, 0.5, cr, 0, 2], 680 // [DP.line, 0.5, 0.5-cr, 0.5, cr], [DP.arc, 0.5, 0, cr, 0, 1],681 // [DP.line, 0.5, 0.5+cr, 0.5, 1-cr], [DP.arc, 0.5, 1, cr, 1, 2],682 // [DP.line, 0.5-cr, 0.5, cr, 0.5], [DP.arc, 0, 0.5, cr, 1.5, 2.5],683 // [DP.line, 0.5+cr, 0.5, 1-cr, 0.5], [DP.arc, 1, 0.5, cr, 0.5, 1.5],684 // ],1);685 }686 private genStairsDown() {687 this.ctx.strokeStyle = '#aaaaaa';688 let r = this.getCacheRecord('stairs-down');689 r.addFrame(this.getNextCachePos());690 let fig : Array<Array<number>> = [[DP.line, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0]]691 let w = 1/5692 let h = 1/5693 let x = 1-w//0.5 - w/2694 let y = 1-h695 for(let i=0;i<5;++i) {696 fig.push([DP.line, x, y, x + w, y, x + w, y + h, x, y + h, x, y])697 y -= h698 w += h699 x = 1-w;//0.5 - w/2700 }701 this.drawFigure(fig, 1)702 }703 private genDoorFrame(off:number, f:number) {704 let d = f/10.0705 let a1 = off + d706 let a2 = 1 + off - d707 let a3 = 1 + off + d708 let a4 = 2 + off - d709 let rr = 0.5710 let x1 = 0.5 + rr*scos(a1)711 let y1 = 0.5 + rr*ssin(a1)712 let x2 = 0.5 + rr*scos(a2)713 let y2 = 0.5 + rr*ssin(a2)714 let x3 = 0.5 + rr*scos(a3)715 let y3 = 0.5 + rr*ssin(a3)716 let x4 = 0.5 + rr*scos(a4)717 let y4 = 0.5 + rr*ssin(a4)718 this.drawFigure([719 [DP.arc, 0.5, 0.5, 0.5, a1, a2], [DP.arc, 0.5, 0.5, 0.5, a3, a4], 720 [DP.line, x1, y1, x2, y2], [DP.line, x3, y3, x4, y4], 721 ],1);722 }723 private genDoors() {724 this.ctx.strokeStyle = '#FFFFFF';725 this.ctx.shadowColor='#FFFFFF'726 this.ctx.lineWidth = 2;727 let r = this.getCacheRecord('door-h');728 for(let f = 0; f<5;++f) {729 r.addFrame(this.getNextCachePos());730 this.genDoorFrame(0.5, f)731 }732 r = this.getCacheRecord('door-h-locked');733 r.addFrame(this.getNextCachePos());734 this.genDoorFrame(0.5, 0)735 this.drawFigure([[DP.arc, 0.5, 0.5, 0.2, 1, 2], [DP.line, 0.3, 0.5, 0.7, 0.5, 0.7, 0.8, 0.3, 0.8, 0.3, 0.5]], 1)736 r = this.getCacheRecord('door-h-blocked');737 r.addFrame(this.getNextCachePos());738 this.genDoorFrame(0.5, 0)739 this.drawFigure([[DP.line, 0.2, 0.2, 0.8, 0.8], [DP.line, 0.2, 0.8, 0.8, 0.2]], 1)740 r = this.getCacheRecord('door-v');741 for(let f = 0; f<5;++f) {742 r.addFrame(this.getNextCachePos());743 this.genDoorFrame(0, f)744 }745 r = this.getCacheRecord('door-v-locked');746 r.addFrame(this.getNextCachePos());747 this.genDoorFrame(0, 0)748 this.drawFigure([[DP.arc, 0.5, 0.5, 0.2, 1, 2], [DP.line, 0.3, 0.5, 0.7, 0.5, 0.7, 0.8, 0.3, 0.8, 0.3, 0.5]], 1)749 750 r = this.getCacheRecord('door-v-blocked');751 r.addFrame(this.getNextCachePos());752 this.genDoorFrame(0.5, 0)753 this.drawFigure([[DP.line, 0.2, 0.2, 0.8, 0.8], [DP.line, 0.2, 0.8, 0.8, 0.2]], 1)754 }755 drawTile(pos: Pos, tileName: string, frame: number = 0) {756 let ctx = gr.getCtx();757 let r = this.cache[tileName];758 if (r) {759 let fr = r.frames.length;760 frame = ((frame % fr) + fr) % fr;761 let fi = r.frames[frame];762 ctx.drawImage(this.cacheCanvas, fi.outerRect.pos.x, fi.outerRect.pos.y, tileFullSize, tileFullSize, pos.x - tileGlowSize, pos.y - tileGlowSize, tileFullSize, tileFullSize);763 return fr;764 }765 return 0;766 }767 drawTileTinted(pos: Pos, tileName: string, color: string, frame: number = 0, extraSize: boolean = false) {...

Full Screen

Full Screen

puzzle_figures.js

Source:puzzle_figures.js Github

copy

Full Screen

...186 var cellSize = width/28;187 }188 snap.node.setAttribute("height", cellSize * 4 + puzzleFigures.gapTop*2);189 puzzleFigures.gapLeft = (width - cellSize*20)/2190 puzzleFigures.drawFigure(snap,{x:0,y:0}, puzzleFigures.tetro_O, cellSize, withLetters);191 puzzleFigures.drawFigure(snap,{x:4,y:0}, puzzleFigures.tetro_Z, cellSize, withLetters);192 puzzleFigures.drawFigure(snap,{x:6,y:0}, puzzleFigures.tetro_S, cellSize, withLetters);193 puzzleFigures.drawFigure(snap,{x:9,y:0}, puzzleFigures.tetro_I_vert, cellSize, withLetters);194 puzzleFigures.drawFigure(snap,{x:11,y:0}, puzzleFigures.tetro_L, cellSize, withLetters);195 puzzleFigures.drawFigure(snap,{x:15,y:0}, puzzleFigures.tetro_J, cellSize, withLetters);196 puzzleFigures.drawFigure(snap,{x:17,y:0}, puzzleFigures.tetro_T, cellSize, withLetters);197 } else {198 var cellSize = width/8;199 snap.node.setAttribute("height", cellSize * 8 + puzzleFigures.gapTop*2);200 puzzleFigures.gapLeft = (width - cellSize*8)/2201 puzzleFigures.drawFigure(snap,{x:3,y:0}, puzzleFigures.tetro_O, cellSize, withLetters);202 puzzleFigures.drawFigure(snap,{x:1,y:0}, puzzleFigures.tetro_Z, cellSize, withLetters);203 puzzleFigures.drawFigure(snap,{x:6,y:0}, puzzleFigures.tetro_S, cellSize, withLetters);204 puzzleFigures.drawFigure(snap,{x:2,y:3}, puzzleFigures.tetro_I, cellSize, withLetters);205 puzzleFigures.drawFigure(snap,{x:2.5,y:5}, puzzleFigures.tetro_T, cellSize, withLetters);206 puzzleFigures.drawFigure(snap,{x:0,y:5}, puzzleFigures.tetro_L, cellSize, withLetters);207 puzzleFigures.drawFigure(snap,{x:7,y:5}, puzzleFigures.tetro_J, cellSize, withLetters);208 }209},210createTetro4: function(snap, withLetters) {211 let width = $(snap.node).parent().width();212 const viewportWidth = Math.max(213 document.documentElement.clientWidth,214 window.innerWidth || 0215 )216 snap.node.setAttribute("width", width);217 var cellSize = width/10;218 snap.node.setAttribute("height", cellSize * 4 + puzzleFigures.gapTop*2);219 puzzleFigures.gapLeft = (width - cellSize*9)/2220 puzzleFigures.drawFigure(snap,{x:0,y:1}, puzzleFigures.tetro_L, cellSize, withLetters);221 puzzleFigures.drawFigure(snap,{x:2.5,y:0}, puzzleFigures.tetro_I_vert, cellSize, withLetters);222 puzzleFigures.drawFigure(snap,{x:4,y:2}, puzzleFigures.tetro_T, cellSize, withLetters);223 puzzleFigures.drawFigure(snap,{x:7.5,y:1}, puzzleFigures.tetro_S, cellSize, withLetters);224},225createPento12: function(snap, withLetters) {226 let width = $(snap.node).parent().width();227 const viewportWidth = Math.max(228 document.documentElement.clientWidth,229 window.innerWidth || 0230 )231 snap.node.setAttribute("width", width);232 if (viewportWidth < 992) {233 var cellSize = width/36;234 snap.node.setAttribute("height", cellSize * 5 + puzzleFigures.gapTop*2);235 puzzleFigures.gapLeft = (width - cellSize*35.5)/2236 puzzleFigures.drawFigure(snap,{x:1,y:0}, puzzleFigures.penta_F, cellSize, withLetters);237 puzzleFigures.drawFigure(snap,{x:3.5,y:0}, puzzleFigures.penta_I, cellSize, withLetters);238 puzzleFigures.drawFigure(snap,{x:5,y:0}, puzzleFigures.penta_L, cellSize, withLetters);239 puzzleFigures.drawFigure(snap,{x:8.5,y:0}, puzzleFigures.penta_N, cellSize, withLetters);240 puzzleFigures.drawFigure(snap,{x:10,y:0}, puzzleFigures.penta_P, cellSize, withLetters);241 puzzleFigures.drawFigure(snap,{x:12.5,y:0}, puzzleFigures.penta_T, cellSize, withLetters);242 puzzleFigures.drawFigure(snap,{x:16,y:0}, puzzleFigures.penta_U, cellSize, withLetters);243 puzzleFigures.drawFigure(snap,{x:19.5,y:0}, puzzleFigures.penta_V, cellSize, withLetters);244 puzzleFigures.drawFigure(snap,{x:23,y:0}, puzzleFigures.penta_W, cellSize, withLetters);245 puzzleFigures.drawFigure(snap,{x:27.5,y:0}, puzzleFigures.penta_X, cellSize, withLetters);246 puzzleFigures.drawFigure(snap,{x:30,y:0}, puzzleFigures.penta_Y, cellSize, withLetters);247 puzzleFigures.drawFigure(snap,{x:32.5,y:0}, puzzleFigures.penta_Z, cellSize, withLetters);248 } else {249 var cellSize = width/12.5;250 snap.node.setAttribute("height", cellSize * 14.5 + puzzleFigures.gapTop*2);251 puzzleFigures.gapLeft = (width - cellSize*12.5)/2252 puzzleFigures.drawFigure(snap,{x:1,y:0}, puzzleFigures.penta_F, cellSize, withLetters);253 puzzleFigures.drawFigure(snap,{x:4,y:0}, puzzleFigures.penta_I, cellSize, withLetters);254 puzzleFigures.drawFigure(snap,{x:6.5,y:0}, puzzleFigures.penta_L, cellSize, withLetters);255 puzzleFigures.drawFigure(snap,{x:10.5,y:0}, puzzleFigures.penta_N, cellSize, withLetters);256 puzzleFigures.drawFigure(snap,{x:0,y:3.5}, puzzleFigures.penta_Y, cellSize, withLetters);257 puzzleFigures.drawFigure(snap,{x:2.5,y:5.5}, puzzleFigures.penta_U, cellSize, withLetters);258 puzzleFigures.drawFigure(snap,{x:6,y:4.5}, puzzleFigures.penta_T, cellSize, withLetters);259 puzzleFigures.drawFigure(snap,{x:10.5,y:4.5}, puzzleFigures.penta_X, cellSize, withLetters);260 puzzleFigures.drawFigure(snap,{x:0,y:8}, puzzleFigures.penta_P, cellSize, withLetters);261 puzzleFigures.drawFigure(snap,{x:2.5,y:8}, puzzleFigures.penta_W, cellSize, withLetters);262 puzzleFigures.drawFigure(snap,{x:6,y:8}, puzzleFigures.penta_Z, cellSize, withLetters);263 puzzleFigures.drawFigure(snap,{x:9.5,y:8}, puzzleFigures.penta_V, cellSize, withLetters);264 }265},266figureHeight: function(figure){267 let minY = 0;268 let maxY = 0;269 figure.cells.forEach(cell => { minY = Math.min(minY, cell.y); maxY = Math.max(maxY, cell.y);});270 return maxY - minY + 1;271},272figureWidth: function(figure){273 let minX = 0;274 let maxX = 0;275 figure.cells.forEach(cell => { minX = Math.min(minX, cell.x); maxX = Math.max(maxX, cell.x);});276 return maxX - minX + 1;277},278figureLeft: function(figure){279 let minX = 0;280 figure.cells.forEach(cell => { minX = Math.min(minX, cell.x);});281 return minX;282},283createPento: function(snap, pentominos, withLetters) {284 let width = $(snap.node).parent().width();285 const viewportWidth = Math.max(286 document.documentElement.clientWidth,287 window.innerWidth || 0288 )289 snap.node.setAttribute("width", width);290 if (viewportWidth < 992) {291 let figuresHeight = 0;292 let figuresWidth = 0;293 for (var i = 0; i < pentominos.length; i++) {294 figuresHeight = Math.max(figuresHeight, puzzleFigures.figureHeight(puzzleFigures.allPenta[pentominos.charAt(i)]));295 figuresWidth = figuresWidth + puzzleFigures.figureWidth(puzzleFigures.allPenta[pentominos.charAt(i)]) + 0.5;296 }297 var cellSize = width/figuresWidth;298 snap.node.setAttribute("height", cellSize * figuresHeight + puzzleFigures.gapTop*2);299 puzzleFigures.gapLeft = (width - cellSize*(figuresWidth-0.5))/2300 let x = 0;301 let y = 0;302 for (var i = 0; i < pentominos.length; i++) {303 puzzleFigures.drawFigure(304 snap,305 {x : x - puzzleFigures.figureLeft(puzzleFigures.allPenta[pentominos.charAt(i)]), y : y},306 puzzleFigures.allPenta[pentominos.charAt(i)],307 cellSize,308 withLetters);309 x+=puzzleFigures.figureWidth(puzzleFigures.allPenta[pentominos.charAt(i)]) + 0.5;310 }311 } else {312 let rows = 3;313 if (pentominos.length > 12) {314 rows = 4;315 }316 if (pentominos.length < 9) {317 rows = 2;318 }319 if (pentominos.length < 5) {320 rows = 1;321 }322 let figuresInRow = Math.ceil(pentominos.length/rows);323 let figuresHeight = 0;324 let maxHeightInRow = 0;325 let rowWidth = 0;326 let figuresWidth = 0;327 for (var i = 0; i < pentominos.length; i++) {328 maxHeightInRow = Math.max(maxHeightInRow, puzzleFigures.figureHeight(puzzleFigures.allPenta[pentominos.charAt(i)]));329 rowWidth += puzzleFigures.figureWidth(puzzleFigures.allPenta[pentominos.charAt(i)]) + 0.5;330 figuresWidth = Math.max(figuresWidth, rowWidth);331 if ((i+1)%figuresInRow==0) {332 rowWidth = 0;333 figuresHeight += maxHeightInRow + 0.5;334 maxHeightInRow = 0;335 }336 }337 if (pentominos%rows != 0) {338 figuresHeight += maxHeightInRow + 0.5;339 }340 var cellSize = width/figuresWidth;341 snap.node.setAttribute("height", cellSize * figuresHeight + puzzleFigures.gapTop*2);342 let x = 0;343 let y = 0;344 maxHeightInRow = 0;345 for (var i = 0; i < pentominos.length; i++) {346 maxHeightInRow = Math.max(maxHeightInRow, puzzleFigures.figureHeight(puzzleFigures.allPenta[pentominos.charAt(i)]));347 puzzleFigures.drawFigure(348 snap,349 {x : x - puzzleFigures.figureLeft(puzzleFigures.allPenta[pentominos.charAt(i)]), y : y},350 puzzleFigures.allPenta[pentominos.charAt(i)],351 cellSize,352 withLetters);353 x+=puzzleFigures.figureWidth(puzzleFigures.allPenta[pentominos.charAt(i)]) + 0.5;354 if ((i+1)%figuresInRow==0) {355 x = 0;356 y += maxHeightInRow + 0.5;357 maxHeightInRow = 0;358 }359 }360 }361},362createBattleship: function(snap, counts) {363 let width = $(snap.node).parent().width();364 const viewportWidth = Math.max(365 document.documentElement.clientWidth,366 window.innerWidth || 0367 )368 snap.node.setAttribute("width", width);369 if (viewportWidth < 992) {370 let totalLength = 0;371 for (let i=0;i<counts.length;i++){372 totalLength += (i+1.5)*counts[i];373 }374 var horizontal = totalLength;375 if (totalLength > 16) {376 var horizontal = 0;377 for (let i=0;i<counts.length;i++){378 let next = horizontal+(i+1.5)*counts[i];379 if (next > totalLength/2.) {380 if (next-totalLength/2. < totalLength/2-horizontal) {381 horizontal = next;382 }383 break;384 }385 horizontal = next;386 }387 horizontal = Math.max(totalLength - horizontal, horizontal);388 }389 var cellSize = width/horizontal;390 if (totalLength > 16) {391 snap.node.setAttribute("height", cellSize * 2.5 + puzzleFigures.gapTop*2);392 } else {393 snap.node.setAttribute("height", cellSize + puzzleFigures.gapTop*2);394 }395 puzzleFigures.gapLeft = (width - cellSize*(horizontal-0.5))/2396 let x = 0;397 let y = 0;398 for (let i=counts.length-1;i>=0;i--){399 for (let j=0;j<counts[i];j++) {400 puzzleFigures.drawFigure(snap,{x:x,y:y}, puzzleFigures.ship(i+1), cellSize, false);401 x+=i+1.5;402 if (x+i+1>=horizontal) {403 x=0;404 y+=1.5;405 }406 }407 }408 } else {409 let totalLength = 0;410 for (let i=0;i<counts.length;i++){411 totalLength = Math.max(totalLength, (i+1.5)*counts[i]);412 }413 var cellSize = width/totalLength;414 snap.node.setAttribute("height", cellSize * counts.length * 1.5 - 0.5 + puzzleFigures.gapTop*2);415 puzzleFigures.gapLeft = (width - cellSize*(totalLength-0.5))/2416 let x = 0;417 let y = 0;418 for (let i=counts.length-1;i>=0;i--){419 for (let j=0;j<counts[i];j++) {420 puzzleFigures.drawFigure(snap,{x:x,y:y}, puzzleFigures.ship(i+1), cellSize, false);421 x+=i+1.5;422 }423 x=0;424 y+=1.5;425 }426 }427},428init: function(element) {429 puzzleFigures.allTetro7 = {'I': puzzleFigures.tetro_I_vert, 'T': puzzleFigures.tetro_T, 'L': puzzleFigures.tetro_L,430 'J': puzzleFigures.tetro_J, 'S': puzzleFigures.tetro_S, 'Z': puzzleFigures.tetro_Z,431 'O': puzzleFigures.tetro_O},432 puzzleFigures.allTetro5 = {'I': puzzleFigures.tetro_I_vert, 'T': puzzleFigures.tetro_T, 'L': puzzleFigures.tetro_L,433 'S': puzzleFigures.tetro_S, 'O': puzzleFigures.tetro_O},434 puzzleFigures.allTetro4 = {'L': puzzleFigures.tetro_L, 'I': puzzleFigures.tetro_I_vert, 'T': puzzleFigures.tetro_T,...

Full Screen

Full Screen

app.js

Source:app.js Github

copy

Full Screen

...103 u_projectedTexture: depthTexture,104 u_reverseLightDirection: lightWorldMatrix.slice(8, 11),105 });106 // ------ Draw the plane --------107 drawFigure(programInfo, planeBufferInfo,108 {109 u_colorMult: [1, 1, 1, 1],110 u_color: [1, 0, 0, 1],111 u_texture: chessboardTexture,112 u_world: m4.translation(0, 0, 0),113 });114 drawFigure(programInfo, cubeBufferInfo, {115 u_colorMult: [1, 1, 1, 1],116 u_color: [1, 0, 0, 1],117 u_texture: woodTexture2,118 u_world: m4.scale(m4.translation(0, -1.0, 0), 12.5, 1, 12.5),119 });120 // ------ Draw the cubes --------121 drawFigure(programInfo, cubeBufferInfo, {122 u_colorMult: [1, 1, 1, 1],123 u_color: [1, 0, 0, 1],124 u_texture: woodTexture2,125 u_world: m4.scale(m4.translation(1.25, 1, 9.25), 1, 1, 1),126 });127 drawFigure(programInfo, cubeBufferInfo, {128 u_colorMult: [1, 1, 1, 1],129 u_color: [1, 0, 0, 1],130 u_texture: woodTexture2,131 u_world: m4.axisRotate(m4.scale(m4.translation(1.25, 2.75, 9.25), 0.75, 0.75, 0.75), [0, 1, 0], degToRad(45))132 });133 drawFigure(programInfo, cubeBufferInfo, {134 u_colorMult: [1, 1, 1, 1],135 u_color: [1, 0, 0, 1],136 u_texture: woodTexture2,137 u_world: m4.scale(m4.translation(-6.75, 1, 9.25), 1, 1, 1),138 });139 drawFigure(programInfo, cubeBufferInfo, {140 u_colorMult: [1, 1, 1, 1],141 u_color: [1, 0, 0, 1],142 u_texture: woodTexture2,143 u_world: m4.scale(m4.translation(-1.25, 0.75, -1.25), 0.75, 0.75, 0.75)144 });145 drawFigure(programInfo, cubeBufferInfo, {146 u_colorMult: [1, 1, 1, 1],147 u_color: [1, 0, 0, 1],148 u_texture: blackWoodTexture,149 u_world: m4.scale(m4.translation(-1.25, 1, -6.5), 1, 1, 1),150 });151 drawFigure(programInfo, cubeBufferInfo, {152 u_colorMult: [1, 1, 1, 1],153 u_color: [1, 0, 0, 1],154 u_texture: blackWoodTexture,155 u_world: m4.scale(m4.translation(1.25, 0.75, -6.5), 0.75, 0.75, 0.75),156 });157 drawFigure(programInfo, cubeBufferInfo, {158 u_colorMult: [1, 1, 1, 1],159 u_color: [1, 0, 0, 1],160 u_texture: blackWoodTexture,161 u_world: m4.scale(m4.translation(1.25, 1, -9.25), 1, 1, 1),162 });163 drawFigure(programInfo, cubeBufferInfo, {164 u_colorMult: [1, 1, 1, 1],165 u_color: [1, 0, 0, 1],166 u_texture: blackWoodTexture,167 u_world: m4.axisRotate(m4.scale(m4.translation(1.25, 2.75, -9.25), 0.75, 0.75, 0.75), [0, 1, 0], degToRad(45))168 });169 drawFigure(programInfo, cubeBufferInfo, {170 u_colorMult: [1, 1, 1, 1],171 u_color: [1, 0, 0, 1],172 u_texture: woodTexture2,173 u_world: m4.scale(m4.translation(1.25, 1, 1.25), 1, 1, 1)174 });175 drawFigure(programInfo, cubeBufferInfo, {176 u_colorMult: [1, 1, 1, 1],177 u_color: [1, 0, 0, 1],178 u_texture: woodTexture2,179 u_world: m4.axisRotate(m4.scale(m4.translation(3.75, 0.75, 3.75), 0.75, 0.75, 0.75), [0, 1, 0], degToRad(45))180 });181 drawFigure(programInfo, cubeBufferInfo, {182 u_colorMult: [1, 1, 1, 1],183 u_color: [1, 0, 0, 1],184 u_texture: blackWoodTexture,185 u_world: m4.scale(m4.translation(3.75, 1, -3.75), 1, 1, 1)186 });187 drawFigure(programInfo, cubeBufferInfo, {188 u_colorMult: [1, 1, 1, 1],189 u_color: [1, 0, 0, 1],190 u_texture: blackWoodTexture,191 u_world: m4.scale(m4.translation(-6.5, 1, 4), 1, 1, 1)192 });193 drawFigure(programInfo, cubeBufferInfo, {194 u_colorMult: [1, 1, 1, 1],195 u_color: [1, 0, 0, 1],196 u_texture: blackWoodTexture,197 u_world: m4.scale(m4.translation(-7.0, 1, 1.5), 0.5, 1, 1)198 });199 drawFigure(programInfo, cubeBufferInfo, {200 u_colorMult: [1, 1, 1, 1],201 u_color: [1, 0, 0, 1],202 u_texture: blackWoodTexture,203 u_world: m4.scale(m4.translation(-6.5, 1, -1.25), 1, 1, 1)204 });205 drawFigure(programInfo, cubeBufferInfo, {206 u_colorMult: [1, 1, 1, 1],207 u_color: [1, 0, 0, 1],208 u_texture: woodTexture2,209 u_world: m4.scale(m4.axisRotate(m4.translation(-4.0, 1, 1.5), [0, 1, 0], degToRad(45)), 0.25, 1, 1)210 });211 drawFigure(programInfo, cubeBufferInfo, {212 u_colorMult: [1, 1, 1, 1],213 u_color: [1, 0, 0, 1],214 u_texture: woodTexture2,215 u_world: m4.scale(m4.axisRotate(m4.translation(-4.0, 1, 1.5), [0, 1, 0], degToRad(-45)), 0.25, 1, 1)216 });217 drawFigure(programInfo, sphereBufferInfo, {218 u_colorMult: [1, 1, 1, 1],219 u_color: [1, 0, 0, 1],220 u_texture: woodTexture2,221 u_world: m4.scale(m4.translation(1.25, 3, 1.25), 1, 1, 1)222 });223 drawFigure(programInfo, sphereBufferInfo, {224 u_colorMult: [1, 1, 1, 1],225 u_color: [1, 0, 0, 1],226 u_texture: blackWoodTexture,227 u_world: m4.scale(m4.translation(-6.5, 3, -1.25), 1, 1, 1)228 });229 }230 function drawFigure(program, figureBuffer, figureUniform, primitive) {231 webglUtils.setBuffersAndAttributes(gl, program, figureBuffer);232 // Set the uniforms unique to the cube233 webglUtils.setUniforms(program, figureUniform);234 // calls gl.drawArrays or gl.drawElements235 if (primitive) {236 webglUtils.drawBufferInfo(gl, figureBuffer, primitive);237 } else {238 webglUtils.drawBufferInfo(gl, figureBuffer);239 }240 }241 // Draw the scene.242 function render() {243 webglUtils.resizeCanvasToDisplaySize(gl.canvas);244 gl.enable(gl.CULL_FACE);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.drawFigure(10);3var wpt = require('wpt');4wpt.drawFigure(10);5var wpt = require('wpt');6wpt.drawFigure(10);7var wpt = require('wpt');8wpt.drawFigure(10);9var wpt = require('wpt');10wpt.drawFigure(10);11var wpt = require('wpt');12wpt.drawFigure(10);13var wpt = require('wpt');14wpt.drawFigure(10);15var wpt = require('wpt');16wpt.drawFigure(10);17var wpt = require('wpt');18wpt.drawFigure(10);19var wpt = require('wpt');20wpt.drawFigure(10);21var wpt = require('wpt');22wpt.drawFigure(10);23var wpt = require('wpt');24wpt.drawFigure(10);25var wpt = require('wpt');26wpt.drawFigure(10);

Full Screen

Using AI Code Generation

copy

Full Screen

1var figure = new Figure();2figure.drawFigure();3var figure = new Figure();4figure.drawFigure();5var figure = new Figure();6figure.drawFigure();7var figure = new Figure();8figure.drawFigure();9var figure = new Figure();10figure.drawFigure();11var figure = new Figure();12figure.drawFigure();13var figure = new Figure();14figure.drawFigure();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.drawFigure(5);3var myModule = require('./myModule');4myModule.drawFigure(5);5var wpt = require('wpt');6exports.drawFigure = function (n) {7 for (var i = 1; i <= n; i++) {8 console.log(wpt.repeatString('*', i));9 }10}11exports.repeatString = function (s, n) {12 var result = '';13 for (var i = 0; i < n; i++) {14 result += s;15 }16 return result;17}18var wpt = (function () {19 var name = 'Web Programming Tutorial';20 var repeatString = function (s, n) {21 var result = '';22 for (var i = 0; i < n; i++) {23 result += s;24 }25 return result;26 };27 return {28 drawFigure: function (n) {29 for (var i = 1; i <= n; i++) {30 console.log(repeatString('*', i));31 }32 }33 };34})();35wpt.drawFigure(5);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2wpt.drawFigure("circle", 10, 10, 10);3wpt.drawFigure("rectangle", 10, 10, 10, 10);4wpt.drawFigure("square", 10, 10, 10);5wpt.drawFigure("triangle", 10, 10, 10);6Export another function that returns a version of the data list that is sorted in ascending order. The function you use to sort the data correctly should not be accessible from outside the module. (Think back to the Custom Sorting Exercise when handling sorting)7var data = [];8exports.addData = function (newData) {9data.push(newData);10};11function sortData() {12return data.sort();13}14exports.getSortedData = function () {15return sortData();16};17var wpt = require('./wpt.js');18wpt.addData(10);19wpt.addData(1);20wpt.addData(5);21wpt.addData(20);22wpt.addData(15);23console.log(wpt.getSortedData());24Implement a Node.js script that imports the functionality of your module, counts the number

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var figure = new wpt.Figure();3figure.addPoint(1, 2);4figure.addPoint(3, 4);5figure.addPoint(5, 6);6figure.drawFigure();7var Figure = (function () {8 function Figure() {9 this.points = [];10 }11 Figure.prototype.addPoint = function (x, y) {12 this.points.push({ x: x, y: y });13 };14 Figure.prototype.drawFigure = function () {15 for (var _i = 0, _a = this.points; _i < _a.length; _i++) {16 var point = _a[_i];17 console.log("Point: " + point.x + ", " + point.y);18 }19 console.log("Figure drawn.");20 };21 return Figure;22})();23exports.Figure = Figure;24var wpt = require('./wpt.js');25var figure = new wpt.Figure();26figure.addPoint(1, 2);27figure.addPoint(3, 4);28figure.addPoint(5, 6);29figure.drawFigure();30var Figure = (function () {31 function Figure() {32 this.points = [];33 }34 Figure.prototype.addPoint = function (x, y) {35 this.points.push({ x: x, y: y });36 };37 Figure.prototype.drawFigure = function () {38 for (var _i = 0, _a = this.points; _i < _a.length; _i++) {39 var point = _a[_i];40 console.log("Point: " + point.x + ", " + point.y);41 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var myFigure = wpt.drawFigure(5);3console.log(myFigure);4module.exports.drawFigure = function (n) {5 var result = "";6 for (var i = 0; i < n; i++) {7 for (var j = 0; j < n; j++) {8 result += "*";9 }10";11 }12 return result;13}14module.exports.drawFigure = function (n) {15 var result = "";16 for (var i = 0; i < n; i++) {17 for (var j = 0; j < n; j++) {18 result += "*";19 }20";21 }22 return result;23}24module.exports.drawFigure = function (n) {25 var result = "";26 for (var i = 0; i < n; i++) {27 for (var j = 0; j < n; j++) {28 result += "*";29 }30";31 }32 return result;33}34module.exports.drawFigure = function (n) {35 var result = "";36 for (var i = 0; i < n; i++) {37 for (var j = 0; j < n; j++) {38 result += "*";39 }40";41 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt');2wpt.drawFigure(5,5);3var wpt2 = require('./wpt2');4wpt2.drawFigure(5,5, 'x');5var wpt3 = require('./wpt3');6wpt3.drawFigure(5,5, 'x', 'left');7var wpt4 = require('./wpt4');8wpt4.drawFigure(5,5, 'x', 'left');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful