You can use the following code to achieve what you want:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
$("#div").load(
body>
</html>
A:
You can use the following code to get the value of the input field and then use it to set the value of the hidden field.
$(document).ready(function(){
$('#myForm').submit(function(e){
e.preventDefault();
var value
You can use the following code to get the desired output.
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
</style>
</head>
<body>
<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>Gender</th>
echo=FALSE}
library(ggplot2)
library(dplyr)
library(tidyr)
library(stringr)
library(reshape2)
library(scales)
library(gridExtra)
library(grid)
library(gridBase)
library(gridExtra)
library(
You can use the following CSS:
#main {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
#main .container {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 1;
ript
function dupe(startNum, endNum) {
var result = startNum;
for (var i = 1; i <= endNum; i++) {
result += startNum;
}
return result;
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
ript
function fill(n) {
var result = "";
for (var i = 0; i < n; i++) {
result += " ";
}
return result;
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function getRandomColor() {
var
ript
function fillNumbers(startNum, endNum) {
for (var i = startNum; i <= endNum; i++) {
document.getElementById("number").innerHTML += i;
}
}
function fillNumbers2(startNum, endNum) {
for (var i = startNum; i <= endNum; i++) {
document.getElementById("
You can use the following code to get the desired output.
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export
function that: add two numbers together
```python
def add(a, b):
return a + b
add(1, 2)
```
function that: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(
```Javascript
You can use the following code to achieve what you want:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
$("#div").load(
You can use the following code to achieve what you want:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
$("#div").load(
ript
function fillRange(startNum, endNum) {
for (var i = startNum; i <= endNum; i++) {
$('#range').append('<option value="' + i + '">' + i + '</option>');
}
}
function fillRange2(startNum, endNum) {
for (var i = startNum; i
ript
function duplicate(count) {
var result = [];
for (var i = 0; i < count; i++) {
result.push({
name: 'Item ' + (i + 1)
});
}
return result;
}
function addItem(item) {
var list = document.getElementById('list');
var clone = item.cloneNode
ript
function fillNumbers(startNum, endNum) {
var result = [];
for (var i = startNum; i <= endNum; i++) {
result.push(i);
}
return result;
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min
function that: add two numbers together
```python
def add(a, b):
return a + b
add(1, 2)
```
function that: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(count) {
```Javascript
ript
function count(a, b) {
return a + b;
}
count(1, 2);
A:
You can use the following code to get the count of the number of elements in the array.
var arr = [1,2,3,4,5,6,7,8,9,10];
var count = arr.length;
A:
You
ript
function fill(startNum, endNum) {
for (var i = startNum; i <= endNum; i++) {
document.getElementById("demo").innerHTML += i + "<br>";
}
}
fill(1, 10);
A:
You can use the following code to get the desired output.
function fill(startNum, endNum) {
You can use the Bootstrap grid system to achieve this. You can use the following code to achieve this.
<div class="row">
<div class="col-md-4">
<div class="thumbnail">
<img src="img/thumb1.jpg" alt="...">
<div class="caption">
<h3>Thumbnail label</h3>
<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Don
html code that: create a div with class "container" and id "main" and text "hello world"
```
<div class="container" id="main">hello world</div>
```
html code that:
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<link rel="apple-touch-icon" type="image/png" href="https://cpwebassets.codepen.io/assets/favicon/apple-touch-icon-5ae1a0698dcc2402e9712f7d01ed509a57814f994c660df9f7a952f3060705ee.png" />
<meta name="apple-mobile-web-app-title" content="CodePen">
<link rel="shortcut icon" type="image/x-icon" href="https://cpwebassets.codepen.io/assets/favicon/favicon-aec34940fbc1a6e787974dcd360f2c6b63348d4b1f4e06c77743096d55480f33.ico" />
<link rel="mask-icon" type="image/x-icon" href="https://cpwebassets.codepen.io/assets/favicon/logo-pin-b4b4269c16397ad2f0f7a01bcdf513a1994f4c94b8af2f191c09eb0d601762b1.svg" color="#111" />
<script src="https://cpwebassets.codepen.io/assets/common/stopExecutionOnTimeout-2c7831bb44f98c1391d6a4ffda0e1fd302503391ca806e7fcc7b9b87197aec26.js"></script>
<title>CodePen - js music tracker thing</title>
<link rel="canonical" href="https://codepen.io/mavrK/pen/GQJbYm">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<style>
* {
box-sizing: border-box;
transition: 0.3s cubic-bezier(0.6, 0, 0.2, 1);
}
.abs-center {
position: absolute;
top: 50%;
left: 50%;
right: ;
bottom: ;
transform: translate(-50%, -50%);
}
.vert-center {
position: absolute;
top: 50%;
left: ;
right: ;
bottom: ;
transform: translateY(-50%);
}
.horz-center {
position: absolute;
top: ;
left: 50%;
right: ;
bottom: ;
transform: translateX(-50%);
}
.rela-block {
display: block;
position: relative;
}
.rela-inline {
display: inline-block;
position: relative;
}
.left {
position: relative;
float: left;
}
.right {
position: relative;
float: right;
}
body {
transition: 0s;
background-color: #f1f1f1;
font-family: 'Ubuntu Mono', monospace;
}
h1 {
font-size: 30px;
margin-bottom: 20px;
}
input {
width: 45px;
border: none;
background-color: transparent;
color: inherit;
font: inherit;
}
input:focus {
outline: none;
}
.container {
width: 88%;
text-align: center;
}
.tracker {
padding: 20px;
background-color: #444;
color: #fff;
}
.info-container {
margin-bottom: 20px;
padding: 10px;
border: 1px solid #bbb;
}
.ui-container {
vertical-align: top;
}
.ui-container.left-container {
margin-right: 20px;
}
.track {
padding: 90px 0 10px;
border: 1px solid #bbb;
}
.track .row {
padding: 0 22px 0 20px;
}
.track-ruler {
border: 1px solid #bbb;
margin-right: -5px;
padding: 10px 0;
}
.track-header {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: ;
height: 80px;
line-height: 30px;
border-bottom: 1px solid #bbb;
}
.track-name-input {
height: 25px;
width: 100%;
text-align: center;
}
.option-select {
height: 24px;
width: 100%;
overflow: hidden;
}
.option-svg {
width: 22%;
margin: 0 -4px;
fill: none;
stroke: #999;
stroke-width: 5;
cursor: pointer;
transition: 0s;
}
.option-svg.active {
stroke: #fff;
}
.noise-label {
line-height: 24px;
}
.mute-button {
border: 1px solid;
padding: 0 5px;
height: 20px;
line-height: 19px;
cursor: pointer;
}
.mute-button.active {
border: 1px solid #fd2;
color: #fd2;
}
.info-cell,
.row {
transition: 0s;
}
.row {
padding: 0 10px;
cursor: default;
}
.row.highlight {
background-color: rgba(0,0,0,0.3);
}
.row.highlight.edit {
background-color: rgba(150,0,0,0.3);
}
.info-cell.highlight {
background-color: rgba(255,255,255,0.3);
}
.volume-info {
color: #49f;
}
.effect-command,
.effect-info {
margin: 0 -3px;
}
.effect-command {
margin-left: 0;
color: #c18;
}
.effect-info {
color: #f77;
}
.pattern-container,
.effect-container {
width: 140px;
margin: 0 auto 20px;
padding: 15px 5px;
border: 1px solid #bbb;
overflow: hidden;
}
.pattern-container p,
.effect-container p {
margin-bottom: 10px;
}
.effect-container {
width: 200px;
padding: 10px;
}
.effect-container div {
text-align: left;
}
.pattern {
width: 21%;
margin: 2%;
cursor: pointer;
}
.pattern.highlight {
background-color: rgba(255,255,255,0.3);
}
.control-container {
overflow: hidden;
padding: 10px;
}
.control-container p {
margin-bottom: 5px;
}
.control-container button {
margin: 0 5px 5px;
}
.add-button {
height: 20px;
width: 20px;
line-height: 18px;
border: 1px solid #bbb;
color: #bbb;
vertical-align: bottom;
cursor: pointer;
}
.add-button:hover {
border: 1px solid #fff;
color: #fff;
}
</style>
<script>
window.console = window.console || function(t) {};
</script>
</head>
<body translate="no">
<!-- FONTS -->
<link href="https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700" rel="stylesheet">
<!-- PAGE STUFF -->
<div id="tracker" @click="captureInput()">
<div class="abs-center container">
<div class="rela-inline tracker">
<h1>JS Tracker</h1>
<div class="rela-block info-container">
<pre>Octave: {{octaveMod + 4}} Tempo: <input v-model="tempo" type="number" min="1" max="255" @click="stopInputCapture(); event.stopPropagation();" @change="checkTempo(); if(playing){resetPlay()}"/></pre>
<div class="rela-block control-container">
<p>- Controls -</p>
<button class="left" @click="addTrack('New Track')">New Track</button>
<button class="left" @click="addTrack('New Track',undefined,true)">New Noise Track</button>
<button class="left" @click="duplicateTrack(Math.floor(cursor.x/5))">Duplicate Track</button>
<button class="left" @click="removeTrack(Math.floor(cursor.x/5));">Remove Track</button>
<button class="left" @click="clearTrack(Math.floor(cursor.x/5));">Clear Track</button>
<button class="left" @click="copyTrackPattern(currentPattern, Math.floor(cursor.x/5))">Copy Track</button>
<button class="left" @click="pasteTrackPattern(currentPattern, Math.floor(cursor.x/5))">Paste Track</button><br><br>
<button class="left" @click="addPattern(currentPattern)">New Pattern</button>
<button class="left" @click="duplicatePattern(currentPattern)">Duplicate Pattern</button>
<button class="left" @click="removePattern(currentPattern)">Remove Pattern</button>
<button class="left" @click="clearPattern(currentPattern);">Clear Pattern</button>
<button class="left" @click="copyPattern(currentPattern)">Copy Pattern</button>
<button class="left" @click="pastePattern(currentPattern)">Paste Pattern</button>
<button class="left" @click="ac.resume()">START AUDIO</button>
<button class="left" onclick="share()">Share</button>
</div>
</div>
<div class="rela-block editor-container">
<div class="rela-inline ui-container left-container">
<div class="rela-block pattern-container">
<p>- Patterns -</p>
<div v-for="p in patternNum" :class="['left', 'pattern', (p-1===currentPattern)?'highlight':'']"
@click="currentPattern=(p-1); updatePatterns();">{{((p-1 <= 15)?'0':'')+(p-1).toString(16).toUpperCase()}}</div>
</div>
<div class="rela-block effect-container">
<p>- Effects -</p>
<div v-for="(e,key) in effects">{{key}}XX - {{e.desc}}</div>
</div>
</div>
<div class="rela-inline ui-container right-container">
<div class="rela-inline track-ruler">
<div v-for="i in 16" class="rela-block row">0{{(i-1).toString(16).toUpperCase()}}</div>
</div>
<div v-for="(t,ind) in tracks" class="rela-inline track">
<div class="track-header">
<input class="rela-block track-name-input" placeholder="Track Name" type="text" v-model="t.trackName" @click="stopInputCapture(); event.stopPropagation();"/>
<div v-if="t.osc" class="rela-block option-select">
<svg viewbox="0 0 100 100" @click="t.waveform = 'sine'; t.osc.type = 'sine';"
:class="['rela-inline', 'option-svg', 'big', t.waveform==='sine'?'active':'']">
<path d="M 15 15 L 85 15 L 85 85 L 15 85 Z"/>
<path d="M 16 50 C 28 22, 38 22, 50 50 S 72 78, 84 50"/>
</svg>
<svg viewbox="0 0 100 100" @click="t.waveform = 'triangle'; t.osc.type = 'triangle';"
:class="['rela-inline', 'option-svg', 'big', t.waveform==='triangle'?'active':'']">
<path d="M 15 15 L 85 15 L 85 85 L 15 85 Z"/>
<path d="M 16 50 L 34 26 L 66 74 L 84 50"/>
</svg>
<svg viewbox="0 0 100 100" @click="t.waveform = 'square'; t.osc.type = 'square';"
:class="['rela-inline', 'option-svg', 'big', t.waveform==='square'?'active':'']">
<path d="M 15 15 L 85 15 L 85 85 L 15 85 Z"/>
<path d="M 16 30 L 50 30 L 50 70 L 84 70"/>
</svg>
<svg viewbox="0 0 100 100" @click="t.waveform = 'sawtooth'; t.osc.type = 'sawtooth';"
:class="['rela-inline', 'option-svg', 'big', t.waveform==='sawtooth'?'active':'']">
<path d="M 15 15 L 85 15 L 85 85 L 15 85 Z"/>
<path d="M 16 58 L 28 70 L 28 30 L 70 70 L 70 30 L 84 44"/>
</svg>
</div>
<div v-else class="rela-block noise-label">- NOISE -</div>
<div :class="['rela-inline', 'mute-button', t.muted?'active':'']" @click="t.muted = !t.muted">Mute</div>
</div>
<div v-for="(i,index) in t.pattern" :class="['rela-block', 'row', (index === cursor.y)?'highlight':'', editMode?'edit':'']">
<div :class="['rela-inline', 'info-cell', 'note-info', (cursor.x === ind*5 && index === cursor.y)?'highlight':'']"
@click="if(!playing) {cursor.y = index; cursor.x = ind*5;}">{{keyFromNote(i[0])||'---'}}</div>
<div :class="['rela-inline', 'info-cell', 'volume-info', (cursor.x === (ind*5)+1 && index === cursor.y)?'highlight':'']"
@click="if(!playing) {cursor.y = index; cursor.x = ind*5 + 1;}">{{i[1]||'-'}}</div>
<div :class="['rela-inline', 'info-cell', 'effect-command', (cursor.x === (ind*5)+2 && index === cursor.y)?'highlight':'']"
@click="if(!playing) {cursor.y = index; cursor.x = ind*5 + 2;}">{{i[2]||'-'}}</div>
<div :class="['rela-inline', 'info-cell', 'effect-info', (cursor.x === (ind*5)+3 && index === cursor.y)?'highlight':'']"
@click="if(!playing) {cursor.y = index; cursor.x = ind*5 + 3;}">{{i[3]||'-'}}</div>
<div :class="['rela-inline', 'info-cell', 'effect-info', (cursor.x === (ind*5)+4 && index === cursor.y)?'highlight':'']"
@click="if(!playing) {cursor.y = index; cursor.x = ind*5 + 4;}">{{i[4]||'-'}}</div>
</div>
</div>
<div class="rela-inline add-button" @click="addTrack('New Track')">+</div>
</div>
</div>
</div>
</div>
</div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.10/vue.min.js'></script>
<script id="rendered-js" >
// --- Notes ---
// Hey look it's a tracker thing.
// Definitely better in full screen mode
// JSON.parse(JSON.stringify( array||object )) is the best!
// Noise channel credit to Mike Foskett
/*
Note: The tracker takes value inputs in hexidecimal.
Meaning the blue volume columns and effect columns will take values from 0 - F
--- Controls ---
A - K is the keyboard while editting / playing
Z and X are octave up and down
Q is a Note Off
Space toggles Edit mode
Enter is Play / Stop
Arrow keys move the cursor around (or you can click around)
Shift + Up / Shift + Down will jump patterns
Tab / Shift + Tab will jump tracks
Shift + Left / Shift + Right will also jump tracks
(For preference options. May change later if new functionality requires it)
* - For the buttload of shortcuts below, there are also buttons on the top for lazy people -
N creates a new pattern after the current pattern
Shift + N duplicates the current pattern
M removes the current pattern
Shift + M clears the current pattern
O creates a new track after the current track
Shift + O duplicates the current track
P removes the current track
Shift + P clears the current track
V copies the current track's pattern to the clipboard
Shift + V pastes the pattern on the clipboard to the current track
Control + V copies the entire pattern to the clipboard
Control + Shift + V pastes the pattern on the clipboard to the current track
--- Effect List ---
0XX - Panning?: 00 full left; FF full right; 80 center (not implemented yet)
1XX - Pitch Slide Up: XX sets slide speed
2XX - Pitch Slide Down: XX sets slide speed
3XY - Gain Envelope: X sets attack, Y sets release
4XY - Vibrato: X is offset in semitones, Y is the speed (Need to make this one)
5XX - Portamento: XX sets speed to following notes
6XX - Pattern Jump: Jump to pattern XX
7XX - Tempo: XX in BPM
8XX - Filter: Set filter to XX freq (00 - 7F is lowpass, 80 - FF is highpass)
9XY - Kill: Kill after Y ticks (6 ticks per 16th)/ X = 0 (no release), X = 1 (release)
*/
// --- To Do --- (stuff for me to do/fix)
// Fix noise track duplication
// Add panning functionality (StereoPannerNode i think?)
// Fix the issue with changing number of tracks and then trying to paste a pattern
// (specifically when you add tracks and try to paste a smaller pattern)
// Work on Save/Load feature for tracks
// Work on undo functionality
// Work on the design (Shit looks like butts yo)
// Add instruments (maybe add the stuff from the synthesizer project for each track?)
// Figure out timing constant for the Vibrato effect
// - Audio Context -
var ac = new AudioContext();
// - Vue Stuff -
var tracker = new Vue({
el: '#tracker',
data: {
cursor: { x: 0, y: 0 },
shiftHeld: false,
ctrlHeld: false,
masterVolume: 0.2,
tempo: 110, // in bpm
effects: {
'1': {
desc: 'Pitch Slide Up',
func: function (X, Y, i) {
if (!tracker.tracks[i].osc) {return false;}
if (X === '0' && Y === '0') {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.tracks[i].osc.frequency.value, ac.currentTime, 0);
} else {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(110), ac.currentTime, (1 - parseInt(X.toString() + Y.toString(), 16) / 255) * 3);
}
} },
'2': {
desc: 'Pitch Slide Down',
func: function (X, Y, i) {
if (!tracker.tracks[i].osc) {return false;}
if (X === '0' && Y === '0') {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.tracks[i].osc.frequency.value, ac.currentTime, 0);
} else {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(0), ac.currentTime, (1 - parseInt(X.toString() + Y.toString(), 16) / 255) * 3);
}
} },
'3': {
desc: 'Gain Envelope',
func: function (X, Y, i) {
tracker.tracks[i].gainAttack = parseInt(X.toString(), 16) / 15;
tracker.tracks[i].gainRelease = parseInt(Y.toString(), 16) / 15;
} },
'4': {
desc: 'Vibrato',
func: function (X, Y, i) {
if (!tracker.tracks[i].osc) {return false;}
clearInterval(tracker.tracks[i].vInterval);
if (X === '0' || Y === '0') {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(tracker.tracks[i].currentNote), ac.currentTime, 0);
} else {
var modArr = [8, 4, 2, 1, 0.75, 2 / 3, 0.5, 1 / 3, 0.25, 1 / 6, 0.125, 1 / 12, 1 / 16, 1 / 32, 1 / 64, 1 / 128];
var time = 15000 / tracker.tempo * modArr[parseInt(Y.toString(), 16)];
if (Math.floor(tracker.tracks[i].osc.frequency.value) <= Math.floor(tracker.freqFromNote(tracker.tracks[i].currentNote))) {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(tracker.tracks[i].currentNote + parseInt(X.toString(), 16)), ac.currentTime, 0.2);
} else {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(tracker.tracks[i].currentNote - parseInt(X.toString(), 16)), ac.currentTime, 0.2);
}
tracker.tracks[i].vInterval = setInterval(function () {
if (Math.floor(tracker.tracks[i].osc.frequency.value) <= Math.floor(tracker.freqFromNote(tracker.tracks[i].currentNote))) {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(tracker.tracks[i].currentNote + parseInt(X.toString(), 16)), ac.currentTime, 0.2);
} else {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(tracker.tracks[i].currentNote - parseInt(X.toString(), 16)), ac.currentTime, 0.2);
}
}, time);
}
} },
'5': {
desc: 'Portamento',
func: function (X, Y, i) {tracker.tracks[i].portaSpeed = (1 - parseInt(X.toString() + Y.toString(), 16) / 255) * 3;} },
'6': {
desc: 'Pattern Jump',
func: function (X, Y, i) {
if (parseInt(X.toString() + Y.toString(), 16) < tracker.patternNum) {
tracker.currentPattern = parseInt(X.toString() + Y.toString(), 16);
tracker.cursor.y = 0;
}
} },
'7': {
desc: 'Tempo',
func: function (X, Y, i) {if (parseInt(X.toString() + Y.toString(), 16) >= 1) {tracker.tempo = parseInt(X.toString() + Y.toString(), 16);tracker.resetPlay();}} },
'8': {
desc: 'Filter',
func: function (X, Y, i) {
var num = parseInt(X.toString() + Y.toString(), 16);
if (num <= 127) {
// lowpass (0 - 6000Hz)
tracker.setFilterType(i, 'lowpass');
tracker.setFilterFreq(i, num / 127 * 6000);
} else {
// highpass (0 - 10000Hz)
tracker.setFilterType(i, 'highpass');
tracker.setFilterFreq(i, (num - 128) / 127 * 10000);
}
} },
'9': {
desc: 'Kill Note',
func: function (X, Y, i) {
setTimeout(function () {
tracker.tracks[i].playing = false;
tracker.tracks[i].gainNode.gain.setTargetAtTime(0, ac.currentTime, X === '0' ? 0 : tracker.tracks[i].gainRelease);
}, 15000 / tracker.tempo / 6 * parseInt(Y.toString(), 16));
} } },
// For testing if an input's char code is a hexidecimal digit
hexArray: [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70],
editMode: false,
playing: false,
keyHeld: 0,
octaveMod: 0,
currentPattern: 0,
patternNum: 1,
tracks: [
{
trackName: 'Square 1',
trackVolume: 1,
muted: false,
playing: false,
currentNote: 0,
vInterval: '',
osc: ac.createOscillator(),
waveform: 'square',
gainNode: ac.createGain(),
gainAttack: 0,
gainRelease: 0,
filterNode: ac.createBiquadFilter(),
filterType: 'lowpass',
portaSpeed: 0,
pattern: [],
patternBank: [
[['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]] },
{
trackName: 'Square 2',
trackVolume: 1,
muted: false,
playing: false,
currentNote: 0,
vInterval: '',
osc: ac.createOscillator(),
waveform: 'square',
gainNode: ac.createGain(),
gainAttack: 0,
gainRelease: 0,
filterNode: ac.createBiquadFilter(),
filterType: 'lowpass',
portaSpeed: 0,
pattern: [],
patternBank: [
[['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]] },
{
trackName: 'Triangle',
trackVolume: 1,
muted: false,
playing: false,
currentNote: 0,
vInterval: '',
osc: ac.createOscillator(),
waveform: 'triangle',
gainNode: ac.createGain(),
gainAttack: 0,
gainRelease: 0,
filterNode: ac.createBiquadFilter(),
filterType: 'lowpass',
portaSpeed: 0,
pattern: [],
patternBank: [
[['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]] },
{
trackName: 'Sawtooth',
trackVolume: 1,
muted: false,
playing: false,
currentNote: 0,
vInterval: '',
osc: ac.createOscillator(),
waveform: 'sawtooth',
gainNode: ac.createGain(),
gainAttack: 0,
gainRelease: 0,
filterNode: ac.createBiquadFilter(),
filterType: 'lowpass',
portaSpeed: 0,
pattern: [],
patternBank: [
[['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]] },
{
trackName: 'Noise',
trackVolume: 1,
muted: false,
playing: false,
currentNote: 0,
vInterval: '',
osc: '',
waveform: '',
gainNode: ac.createGain(),
gainAttack: 0,
gainRelease: 0,
filterNode: ac.createBiquadFilter(),
filterType: 'lowpass',
portaSpeed: 0,
pattern: [],
patternBank: [
[['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]] }],
colorArray: ['#F00', '#FF8000', '#FF0', '#80FF00', '#0F0', '#00FF80', '#0FF', '#0080FF', '#F0F', '#FF0080'],
// Clipboards for copying and Pasting
trackClipboard: [],
patternClipboard: [],
// Event Capture Functions
keydownFunction: function (e) {
e.preventDefault();
var note = tracker.evalKeystroke(e.which);
switch (e.which) {
// Octave change and checks
case 90:tracker.octaveMod--;if (tracker.octaveMod < -4) tracker.octaveMod = -4;break;
case 88:tracker.octaveMod++;if (tracker.octaveMod > 4) tracker.octaveMod = 4;break;
// Edit cursor movement
case 38:
if (tracker.shiftHeld) {tracker.currentPattern--;tracker.checkPattern();} else
{tracker.cursor.y--;}
break;
case 40:
if (tracker.shiftHeld) {tracker.currentPattern++;tracker.checkPattern();} else
{tracker.cursor.y++;}
break;
case 37:tracker.cursor.x -= tracker.shiftHeld ? 5 : 1;break;
case 39:tracker.cursor.x += tracker.shiftHeld ? 5 : 1;break;
// Play/Stop on Enter
case 13:
if (tracker.playing) {tracker.stop();for (var i in tracker.tracks) {tracker.noteOff(i);tracker.tracks[i].portaSpeed = 0;}} else
{tracker.cursor.y = 0;tracker.play();}
break;
// Space
case 32:tracker.editMode = !tracker.editMode;break;
// Shift
case 16:tracker.shiftHeld = true;break;
// Control
case 17:tracker.ctrlHeld = true;break;
// Tab
case 9:tracker.cursor.x += tracker.shiftHeld ? -5 : 5;break;
// N - New pattern / Duplicate pattern (shifted)
case 78:tracker.shiftHeld ? tracker.duplicatePattern(tracker.currentPattern) :
tracker.addPattern(tracker.currentPattern);break;
// M - Remove pattern / Clear Pattern (shifted)
case 77:tracker.shiftHeld ? tracker.clearPattern(tracker.currentPattern) :
tracker.removePattern(tracker.currentPattern);break;
// O - New track / Duplicate track (shifted)
case 79:tracker.shiftHeld ? tracker.duplicateTrack(Math.floor(tracker.cursor.x / 5)) :
tracker.addTrack('New Track');break;
// P - Remove track / Clear track (shifted)
case 80:tracker.shiftHeld ? tracker.clearTrack(Math.floor(tracker.cursor.x / 5)) :
tracker.removeTrack(Math.floor(tracker.cursor.x / 5));break;
// V - copy track pattern / copy entire pattern (shifted)
// If ctrl held - paste track pattern / paste entire pattern (shifted)
case 86:
// Breaks when the number of tracks changes after pattern is copied. Need to fix (adjust size of the clipboard array?)
if (tracker.ctrlHeld) {
tracker.shiftHeld ? tracker.pastePattern(tracker.currentPattern) :
tracker.pasteTrackPattern(tracker.currentPattern, Math.floor(tracker.cursor.x / 5));
} else {
tracker.shiftHeld ? tracker.copyPattern(tracker.currentPattern) :
tracker.copyTrackPattern(tracker.currentPattern, Math.floor(tracker.cursor.x / 5));
}
break;}
;
var n = tracker.cursor.x % 5;
if (tracker.editMode) {
if (e.which === 46) {
if (n === 0 || n === 1) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][n] = '';
if (!tracker.playing) {tracker.cursor.y++;}
} else if (n === 2 || n === 3 || n === 4) {
for (var i = 2; i < 5; i++) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][i] = '';
}
if (!tracker.playing) {tracker.cursor.y++;}
}
} else {
if (n === 0) {
if (e.which === 81) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][n] = 'OFF';
if (!tracker.playing) {tracker.cursor.y++;}
} else if (note && note >= 17 && note <= 125) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][n] = note;
if (!tracker.playing) {tracker.cursor.y++;}
}
} else if (n === 1) {
if (tracker.hexArray.includes(e.which)) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][n] = String.fromCharCode(e.which);
if (!tracker.playing) {tracker.cursor.y++;}
}
} else if (n === 2) {
// Parse for Effect Command
if (tracker.effects[String.fromCharCode(e.which)]) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][2] = String.fromCharCode(e.which);
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][3] = '0';
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][4] = '0';
if (!tracker.playing) {tracker.cursor.y++;}
}
} else if (n === 3 || n === 4) {
if (tracker.hexArray.includes(e.which) && tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][2]) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][n] = String.fromCharCode(e.which);
if (!tracker.playing) {tracker.cursor.y++;}
}
}
}
}
if (note && note >= 17 && note <= 125 && n === 0) {
if (!tracker.keyHeld || tracker.keyHeld && tracker.keyHeld !== e.which) {
tracker.keyHeld = e.which;
tracker.noteOn(Math.floor(tracker.cursor.x / 5), note);
};
}
tracker.checkCursorPos();
return false;
},
keyupFunction: function (e) {
if (e.which === 16) {tracker.shiftHeld = false;}
if (e.which === 17) {tracker.ctrlHeld = false;}
if (tracker.playing && tracker.editMode && tracker.evalKeystroke(e.which)) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][0] = 'OFF';
} else {
if (tracker.keyHeld === e.which) {tracker.keyHeld = 0;tracker.noteOff(Math.floor(tracker.cursor.x / 5));};
}
return false;
},
// Play function
playInterval: '' },
methods: {
// - General Functions -
init: function () {
for (var t in this.tracks) {tracker.setupTrack(t);}
tracker.updatePatterns();
tracker.checkTempo();
tracker.captureInput();
},
checkTempo: function () {
if (tracker.tempo > 255) {tracker.tempo = 255;}
if (tracker.tempo < 1) {tracker.tempo = 1;}
},
checkCursorPos: function () {
if (tracker.cursor.y < 0) {tracker.cursor.y = 15;tracker.currentPattern--;tracker.checkPattern();}
if (tracker.cursor.y > 15) {tracker.cursor.y = 0;tracker.currentPattern++;tracker.checkPattern();}
if (tracker.cursor.x < 0) {tracker.cursor.x += tracker.tracks.length * 5;}
if (tracker.cursor.x >= tracker.tracks.length * 5) {tracker.cursor.x -= tracker.tracks.length * 5;}
},
// - Track Functions -
addTrack: function (name, dupIndex, noise) {
if (dupIndex || dupIndex === 0) {
var n = tracker.tracks[dupIndex],
newTN = n.trackName,
newTV = n.trackVolume,
newM = n.muted,
newPl = n.playing,
newCN = n.currentNote,
newW = n.waveform,
newGA = n.gainAttack,
newGR = n.gainRelease,
newFT = n.filterType,
newPS = n.portaSpeed,
newP = JSON.parse(JSON.stringify(n.pattern)),
newPB = JSON.parse(JSON.stringify(n.patternBank));
}
var newTrackInfo = {
trackName: newTN || name || 'Untitled',
trackVolume: newTV || 1,
muted: newM || false,
playing: newPl || false,
currentNote: newCN || 0,
vInterval: '',
osc: noise ? '' : ac.createOscillator(),
waveform: noise ? '' : newW || 'sine',
gainNode: ac.createGain(),
gainAttack: newGA || 0,
gainRelease: newGR || 0,
filterNode: ac.createBiquadFilter(),
filterType: newFT || 'lowpass',
portaSpeed: newPS || 0,
pattern: newP || [],
patternBank: newPB || [] };
if (!newTrackInfo.patternBank[0]) {
for (var i = 0; i < tracker.patternNum; i++) {
newTrackInfo.patternBank.push([['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]);
}
}
this.tracks.splice(dupIndex + 1 || tracker.tracks.length, 0, newTrackInfo);
tracker.setupTrack(dupIndex + 1 || this.tracks.length - 1, noise);
tracker.updatePatterns();
},
duplicateTrack: function (index) {tracker.addTrack('Copy', index);},
removeTrack: function (index) {if (this.tracks.length > 1) this.tracks.splice(index, 1);},
clearTrack: function (index) {
tracker.tracks[index].patternBank[tracker.currentPattern] = [['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']];
tracker.updatePatterns();
tracker.noteOff(index);
},
setupTrack: function (index, noise) {
// Gain Setup
this.tracks[index].gainNode.gain.setValueAtTime(0, ac.currentTime, 0);
this.tracks[index].gainNode.connect(ac.destination);
// Filter Setup
this.tracks[index].filterNode.type = this.tracks[index].filterType;
this.tracks[index].filterNode.connect(this.tracks[index].gainNode);
setTimeout(function () {
tracker.setFilterFreq(index, 5000);
tracker.setFilterQ(index, 0);
}, 10);
if (noise || !this.tracks[index].osc) {
var bufferSize = 2 * ac.sampleRate,
noiseBuffer = ac.createBuffer(1, bufferSize, ac.sampleRate);
var output = noiseBuffer.getChannelData(0);
for (var i = 0; i < bufferSize; i++) {output[i] = Math.random() * 2 - 1;}
this.tracks[index].audioSource = ac.createBufferSource();
this.tracks[index].audioSource.connect(this.tracks[index].filterNode);
this.tracks[index].audioSource.buffer = noiseBuffer;
this.tracks[index].audioSource.loop = true;
this.tracks[index].audioSource.start();
} else {
// Oscillater Setup
this.tracks[index].osc.type = this.tracks[index].waveform;
this.tracks[index].osc.connect(this.tracks[index].filterNode);
this.tracks[index].osc.start();
}
},
// - Pattern Functions -
addPattern: function (index, dupIndex) {
tracker.patternNum++;
tracker.currentPattern = index + 1;
for (var t in tracker.tracks) {
var b;
if (dupIndex || dupIndex === 0) b = JSON.parse(JSON.stringify(tracker.tracks[t].patternBank[dupIndex]));
tracker.tracks[t].patternBank.splice(index + 1, 0, b || [['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]);
}
tracker.updatePatterns();
},
duplicatePattern: function (index) {tracker.addPattern(index, index);},
removePattern: function (index) {
if (tracker.patternNum > 1) {
if (tracker.currentPattern === tracker.patternNum - 1) {tracker.currentPattern--;}
tracker.patternNum--;
for (var t in tracker.tracks) {tracker.tracks[t].patternBank.splice(index, 1);}
tracker.checkPattern();
tracker.updatePatterns();
}
},
clearPattern: function (index) {
for (var t in tracker.tracks) {
tracker.tracks[t].patternBank[index] = [['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']];
}
tracker.updatePatterns();
},
updatePatterns: function () {
for (var t in tracker.tracks) {tracker.tracks[t].pattern = tracker.tracks[t].patternBank[tracker.currentPattern];}
},
checkPattern: function () {
if (tracker.currentPattern < 0) {tracker.currentPattern = tracker.patternNum - 1;}
if (tracker.currentPattern >= tracker.patternNum) {tracker.currentPattern = 0;}
tracker.updatePatterns();
},
// - Copy/Paste Functions -
copyPattern: function (index) {
var output = [];
for (var i in tracker.tracks) {
output.push(tracker.tracks[i].patternBank[index]);
}
tracker.patternClipboard = JSON.parse(JSON.stringify(output));
},
pastePattern: function (index) {
if (tracker.patternClipboard[0]) {
for (var i in tracker.tracks) {
tracker.tracks[i].patternBank[tracker.currentPattern] = JSON.parse(JSON.stringify(tracker.patternClipboard[i]));
}
}
tracker.updatePatterns();
},
copyTrackPattern: function (pIndex, tIndex) {
tracker.trackClipboard = JSON.parse(JSON.stringify(tracker.tracks[tIndex].patternBank[pIndex]));
},
pasteTrackPattern: function (pIndex, tIndex) {
if (tracker.trackClipboard[0]) {
tracker.tracks[tIndex].patternBank[pIndex] = JSON.parse(JSON.stringify(tracker.trackClipboard));
}
tracker.updatePatterns();
},
// - Filter Functions -
setFilterType: function (index, type) {this.tracks[index].filterNode.type = type;this.tracks[index].filterType = type;},
setFilterFreq: function (index, freq) {this.tracks[index].filterNode.frequency.setValueAtTime(freq, ac.currentTime, 0);},
setFilterQ: function (index, q) {this.tracks[index].filterNode.Q.setValueAtTime(q, ac.currentTime, 0);},
// - Key Functions -
freqFromNote: function (note) {return 261.63 * Math.pow(2, (note - 65) / 12);},
evalKeystroke: function (keyNum) {
switch (keyNum) {
case 65:return 65 + 12 * this.octaveMod;break; // C ┐
case 87:return 66 + 12 * this.octaveMod;break; // C# │
case 83:return 67 + 12 * this.octaveMod;break; // D │
case 69:return 68 + 12 * this.octaveMod;break; // Eb │
case 68:return 69 + 12 * this.octaveMod;break; // E │
case 70:return 70 + 12 * this.octaveMod;break; // F │
case 84:return 71 + 12 * this.octaveMod;break; // F# ├── The Keyboard
case 71:return 72 + 12 * this.octaveMod;break; // G │
case 89:return 73 + 12 * this.octaveMod;break; // G# │
case 72:return 74 + 12 * this.octaveMod;break; // A │
case 85:return 75 + 12 * this.octaveMod;break; // Bb │
case 74:return 76 + 12 * this.octaveMod;break; // B │
case 75:return 77 + 12 * this.octaveMod;break; // C ┘
default:return false;}
;
},
keyFromNote: function (note) {
if (note === 'OFF') {return note;} else
if (note !== '') {
var keyArray = ['G-', 'G#', 'A-', 'A#', 'B-', 'C-', 'C#', 'D-', 'D#', 'E-', 'F-', 'F#'];
// if(note === 16)
return keyArray[note % keyArray.length] + (Math.floor((note - 5) / keyArray.length) - 1);
}
},
// - Gain Functions -
noteOn: function (trackNum, noteNum) {
this.tracks[trackNum].playing = true;
var gain = this.masterVolume * this.tracks[trackNum].trackVolume * !this.tracks[trackNum].muted,
freq = tracker.freqFromNote(noteNum);
if (this.tracks[trackNum].osc) {
this.tracks[trackNum].osc.frequency.setTargetAtTime(freq, ac.currentTime, this.tracks[trackNum].portaSpeed);
}
this.tracks[trackNum].gainNode.gain.setTargetAtTime(0, ac.currentTime, 0);
this.tracks[trackNum].gainNode.gain.setTargetAtTime(gain, ac.currentTime, this.tracks[trackNum].gainAttack);
},
noteOff: function (trackNum) {
this.tracks[trackNum].playing = false;
this.tracks[trackNum].gainNode.gain.setTargetAtTime(0, ac.currentTime, this.tracks[trackNum].gainRelease);
clearInterval(tracker.tracks[trackNum].vInterval);
},
// - Play Functions -
play: function () {
tracker.playInterval = setInterval(function () {
var y = tracker.cursor.y,jumpCheck = false;
for (var i in tracker.tracks) {
var row = tracker.tracks[i].pattern[y];
if (row[0] !== '' && row[0] !== 'OFF') {tracker.tracks[i].currentNote = row[0];}
var preEffects = ['3', '5', '6', '7', '8', '9'],postEffects = ['1', '2', '4'];
// Track Effects before note played
if (preEffects.includes(row[2])) {tracker.effects[row[2]].func(row[3], row[4], i);}
if (row[2] === '6') {jumpCheck = true;}
// Change track volume
if (row[1] !== '') {
tracker.tracks[i].trackVolume = parseInt(row[1], 16) / 16;
if (tracker.tracks[i].playing && row[0] === '') {
tracker.tracks[i].gainNode.gain.setTargetAtTime(tracker.tracks[i].trackVolume * tracker.masterVolume * !tracker.tracks[i].muted, ac.currentTime, 0);
}
}
// Play Note
if (row[0] === 'OFF') {tracker.noteOff(i);} else
if (row[0] !== '') {tracker.noteOn(i, row[0]);}
// Track Effects after note played
if (postEffects.includes(row[2])) {tracker.effects[row[2]].func(row[3], row[4], i);}
}
if (!jumpCheck) {tracker.cursor.y++;}
tracker.checkCursorPos();
}, 15000 / tracker.tempo);
tracker.playing = true;
},
stop: function () {
clearInterval(tracker.playInterval);
tracker.playing = false;
},
resetPlay: function () {tracker.stop();tracker.play();},
// - User Input Functions -
captureInput: function () {
window.addEventListener('keydown', this.keydownFunction);
window.addEventListener('keyup', this.keyupFunction);
},
stopInputCapture: function () {
window.removeEventListener('keydown', this.keydownFunction);
window.removeEventListener('keyup', this.keyupFunction);
} } });
tracker.init();
// --- MIDI STUFF --- (Not used yet)
/*
// Check for midi devices
if (navigator.requestMIDIAccess) { navigator.requestMIDIAccess().then(midiSuccess, midiFailure); };
// Fail MIDI Connection
function midiFailure () { console.error('No access to your MIDI devices.') };
// Successful MIDI Connection
function midiSuccess(midi) {
// listen for connect/disconnect message
midi.onstatechange = onStateChange;
var inputs = midi.inputs.values();
for (var input = inputs.next(); input && !input.done; input = inputs.next()) {
// each time there is a midi message call the onMIDIMessage function
input.value.onmidimessage = onMIDIMessage;
}
}
function onStateChange(event) {
// console.log(event, event.port)
}
function onMIDIMessage (msg) {
if(msg.data[2] === 127) {
// evalMidiPress(msg.data[1])
}
if(msg.data[2] === 0) {
// evalMidiRelease(msg.data[1])
}
};
function share() {
```
tion that:
function that(x) {
return x * x;
}
function that(x) {
return x * x;
}
function that(x) {
return x * x;
}
function that(x) {
return x * x;
}
function that(
echo=FALSE}
library(ggplot2)
library(dplyr)
library(tidyr)
library(stringr)
library(reshape2)
library(scales)
library(gridExtra)
library(grid)
library(gridBase)
library(gridExtra)
library(
translateFri, 19 Jan 2024 translate code:
function add(a, b) {
return a + b;
}
```python
def add(a, b):
return a + b
```
translate code: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(count) {
```Javascript
ript
function fillNumbers(startNum, endNum) {
var result = [];
for (var i = startNum; i <= endNum; i++) {
result.push(i);
}
return result;
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min
translateFri, 19 Jan 2024 translate code:
function add(a, b) {
return a + b;
}
```python
def add(a, b):
return a + b
```
translate code: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(count) {
```Javascript
ript
function playSound(sound) {
var audio = new Audio(sound);
audio.play();
}
function playSound2(sound) {
var audio = new Audio(sound);
audio.play();
}
function playSound3(sound) {
var audio = new Audio(sound);
audio.play();
}
ript
function getDuplicateCount(arr) {
var count = 0;
for (var i = 0; i < arr.length; i++) {
for (var j = i + 1; j < arr.length; j++) {
if (arr[i] === arr[j]) {
count++;
}
}
}
return count;
}
// getDuplicateCount([1,
regex that: match all words that start with "hello"
```
/hello\w+/
```
regex that: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(
```
You can use the following code to achieve what you want:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
$("#div").load(
ript
function duplicateCount(arr) {
var count = 0;
for (var i = 0; i < arr.length; i++) {
if (arr[i].duplicate) {
count++;
}
}
return count;
}
function getDuplicateCount(arr) {
var count = 0;
for (var i = 0; i < arr.length; i++) {
ript
function share(url) {
var win = window.open(url, '_blank');
win.focus();
}
function shareFacebook(url) {
var win = window.open('http://www.facebook.com/sharer.php?u='+url, '_blank');
win.focus();
}
function shareTwitter(
You can use the following code to achieve what you want:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
$("#div").load(
You can use the Bootstrap grid system to achieve this. You can use the following code to achieve this.
<div class="row">
<div class="col-md-4">
<div class="thumbnail">
<img src="img/thumb1.jpg" alt="...">
<div class="caption">
<h3>Thumbnail label</h3>
<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Don
l>
A:
You can use the following code to get the value of the input field and then use it to set the value of the hidden field.
$(document).ready(function(){
$('#myInput').on('change', function(){
$('#myHiddenField').val($(
ript
function getDuplicateCount(arr) {
var count = 0;
for (var i = 0; i < arr.length; i++) {
for (var j = i + 1; j < arr.length; j++) {
if (arr[i] === arr[j]) {
count++;
}
}
}
return count;
}
// getDuplicateCount([1,
ript
function fill(n) {
var result = "";
for (var i = 0; i < n; i++) {
result += " ";
}
return result;
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function getRandomColor() {
var
ript
function add(a, b):
return a + b
add(1, 2)
add(1, 2, 3)
add(1, 2, 3, 4)
Python
def add(a, b):
return a + b
add(1, 2)
add(1, 2, 3)
add(1, 2, 3, 4)
Ruby
translateFri, 19 Jan 2024 translate code:
function add(a, b) {
return a + b;
}
```python
def add(a, b):
return a + b
```
translate code: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(count) {
```Python
explanation of the code:
def add(a, b):
return a + b
```
The function add takes two arguments a and b and returns the sum of a and b.
```
explanation that:
function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(count) {
```
ript
function add(a, b) {
return a + b;
}
add(1, 2);
A:
You can use the following code to get the result you want:
function add(a, b) {
return a + b;
}
var result = add(1, 2);
console.log(result);
The reason why your
function that: add two numbers together
```python
def add(a, b):
return a + b
add(1, 2)
```
function that: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function
```Javascript
ript
function share(url) {
var win = window.open(url, 'Share', 'height=400,width=600,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');
win.focus();
}
// This function is called when the user clicks on the "share" link
echo=FALSE}
library(ggplot2)
library(dplyr)
library(tidyr)
library(stringr)
library(reshape2)
library(scales)
library(gridExtra)
library(grid)
library(gridBase)
library(gridExtra)
library(
tion getAll($where = '', $order = '', $limit = '', $offset = '') {
if ($limit != '') {
$limit = "LIMIT $limit";
}
if ($offset != '') {
$offset = "OFFSET $offset";
ript
function fillNumbers(n) {
var result = "";
for (var i = 0; i < n; i++) {
result += "#";
}
return result;
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function getRandomColor() {
regex that: match all words that start with "hello"
```
/hello\w+/
```
regex that: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
```
You can use the following code to get the desired output.
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
</style>
explanation of the code:
def add(a, b):
return a + b
```
The function add takes two arguments a and b and returns the sum of a and b.
```
explanation that:
function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
```
ript
function line(x1, y1, z1, x2, y2, z2) {
var line = new THREE.Line3(new THREE.Vector3(x1, y1, z1), new THREE.Vector3(x2, y2, z2), new THREE.LineBasicMaterial({ color: 0xff0000 }));
scene.add(line);
}
// create
;
});
});
A:
You can use the following code to get the data from the server:
$.ajax({
url: 'your url',
type: 'GET',
dataType: 'json',
success: function(data) {
console.log(data);
}
});
ript
function getDuplicateCount(arr) {
var count = 0;
for (var i = 0; i < arr.length; i++) {
for (var j = i + 1; j < arr.length; j++) {
if (arr[i] === arr[j]) {
count++;
}
}
}
return count;
}
// getDuplicateCount([1,
ript
function count(start, end) {
var count = 0;
for (var i = start; i <= end; i++) {
if (i % 2 === 0) {
count++;
}
}
return count;
}
console.log(count(1, 10));
A:
You can use a for loop and a modulo operator to get the count of
html code that: create a div with class "container" and id "main" and text "hello world"
```
<div class="container" id="main">hello world</div>
```
html code that:
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<link rel="apple-touch-icon" type="image/png" href="https://cpwebassets.codepen.io/assets/favicon/apple-touch-icon-5ae1a0698dcc2402e9712f7d01ed509a57814f994c660df9f7a952f3060705ee.png" />
<meta name="apple-mobile-web-app-title" content="CodePen">
<link rel="shortcut icon" type="image/x-icon" href="https://cpwebassets.codepen.io/assets/favicon/favicon-aec34940fbc1a6e787974dcd360f2c6b63348d4b1f4e06c77743096d55480f33.ico" />
<link rel="mask-icon" type="image/x-icon" href="https://cpwebassets.codepen.io/assets/favicon/logo-pin-b4b4269c16397ad2f0f7a01bcdf513a1994f4c94b8af2f191c09eb0d601762b1.svg" color="#111" />
<script src="https://cpwebassets.codepen.io/assets/common/stopExecutionOnTimeout-2c7831bb44f98c1391d6a4ffda0e1fd302503391ca806e7fcc7b9b87197aec26.js"></script>
<title>CodePen - js music tracker thing</title>
<link rel="canonical" href="https://codepen.io/mavrK/pen/GQJbYm">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<style>
* {
box-sizing: border-box;
transition: 0.3s cubic-bezier(0.6, 0, 0.2, 1);
}
.abs-center {
position: absolute;
top: 50%;
left: 50%;
right: ;
bottom: ;
transform: translate(-50%, -50%);
}
.vert-center {
position: absolute;
top: 50%;
left: ;
right: ;
bottom: ;
transform: translateY(-50%);
}
.horz-center {
position: absolute;
top: ;
left: 50%;
right: ;
bottom: ;
transform: translateX(-50%);
}
.rela-block {
display: block;
position: relative;
}
.rela-inline {
display: inline-block;
position: relative;
}
.left {
position: relative;
float: left;
}
.right {
position: relative;
float: right;
}
body {
transition: 0s;
background-color: #f1f1f1;
font-family: 'Ubuntu Mono', monospace;
}
h1 {
font-size: 30px;
margin-bottom: 20px;
}
input {
width: 45px;
border: none;
background-color: transparent;
color: inherit;
font: inherit;
}
input:focus {
outline: none;
}
.container {
width: 88%;
text-align: center;
}
.tracker {
padding: 20px;
background-color: #444;
color: #fff;
}
.info-container {
margin-bottom: 20px;
padding: 10px;
border: 1px solid #bbb;
}
.ui-container {
vertical-align: top;
}
.ui-container.left-container {
margin-right: 20px;
}
.track {
padding: 90px 0 10px;
border: 1px solid #bbb;
}
.track .row {
padding: 0 22px 0 20px;
}
.track-ruler {
border: 1px solid #bbb;
margin-right: -5px;
padding: 10px 0;
}
.track-header {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: ;
height: 80px;
line-height: 30px;
border-bottom: 1px solid #bbb;
}
.track-name-input {
height: 25px;
width: 100%;
text-align: center;
}
.option-select {
height: 24px;
width: 100%;
overflow: hidden;
}
.option-svg {
width: 22%;
margin: 0 -4px;
fill: none;
stroke: #999;
stroke-width: 5;
cursor: pointer;
transition: 0s;
}
.option-svg.active {
stroke: #fff;
}
.noise-label {
line-height: 24px;
}
.mute-button {
border: 1px solid;
padding: 0 5px;
height: 20px;
line-height: 19px;
cursor: pointer;
}
.mute-button.active {
border: 1px solid #fd2;
color: #fd2;
}
.info-cell,
.row {
transition: 0s;
}
.row {
padding: 0 10px;
cursor: default;
}
.row.highlight {
background-color: rgba(0,0,0,0.3);
}
.row.highlight.edit {
background-color: rgba(150,0,0,0.3);
}
.info-cell.highlight {
background-color: rgba(255,255,255,0.3);
}
.volume-info {
color: #49f;
}
.effect-command,
.effect-info {
margin: 0 -3px;
}
.effect-command {
margin-left: 0;
color: #c18;
}
.effect-info {
color: #f77;
}
.pattern-container,
.effect-container {
width: 140px;
margin: 0 auto 20px;
padding: 15px 5px;
border: 1px solid #bbb;
overflow: hidden;
}
.pattern-container p,
.effect-container p {
margin-bottom: 10px;
}
.effect-container {
width: 200px;
padding: 10px;
}
.effect-container div {
text-align: left;
}
.pattern {
width: 21%;
margin: 2%;
cursor: pointer;
}
.pattern.highlight {
background-color: rgba(255,255,255,0.3);
}
.control-container {
overflow: hidden;
padding: 10px;
}
.control-container p {
margin-bottom: 5px;
}
.control-container button {
margin: 0 5px 5px;
}
.add-button {
height: 20px;
width: 20px;
line-height: 18px;
border: 1px solid #bbb;
color: #bbb;
vertical-align: bottom;
cursor: pointer;
}
.add-button:hover {
border: 1px solid #fff;
color: #fff;
}
</style>
<script>
window.console = window.console || function(t) {};
</script>
</head>
<body translate="no">
<!-- FONTS -->
<link href="https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700" rel="stylesheet">
<!-- PAGE STUFF -->
<div id="tracker" @click="captureInput()">
<div class="abs-center container">
<div class="rela-inline tracker">
<h1>JS Tracker</h1>
<div class="rela-block info-container">
<pre>Octave: {{octaveMod + 4}} Tempo: <input v-model="tempo" type="number" min="1" max="255" @click="stopInputCapture(); event.stopPropagation();" @change="checkTempo(); if(playing){resetPlay()}"/></pre>
<div class="rela-block control-container">
<p>- Controls -</p>
<button class="left" @click="addTrack('New Track')">New Track</button>
<button class="left" @click="addTrack('New Track',undefined,true)">New Noise Track</button>
<button class="left" @click="duplicateTrack(Math.floor(cursor.x/5))">Duplicate Track</button>
<button class="left" @click="removeTrack(Math.floor(cursor.x/5));">Remove Track</button>
<button class="left" @click="clearTrack(Math.floor(cursor.x/5));">Clear Track</button>
<button class="left" @click="copyTrackPattern(currentPattern, Math.floor(cursor.x/5))">Copy Track</button>
<button class="left" @click="pasteTrackPattern(currentPattern, Math.floor(cursor.x/5))">Paste Track</button><br><br>
<button class="left" @click="addPattern(currentPattern)">New Pattern</button>
<button class="left" @click="duplicatePattern(currentPattern)">Duplicate Pattern</button>
<button class="left" @click="removePattern(currentPattern)">Remove Pattern</button>
<button class="left" @click="clearPattern(currentPattern);">Clear Pattern</button>
<button class="left" @click="copyPattern(currentPattern)">Copy Pattern</button>
<button class="left" @click="pastePattern(currentPattern)">Paste Pattern</button>
<button class="left" @click="ac.resume()">START AUDIO</button>
<button class="left" onclick="share()">Share</button>
</div>
</div>
<div class="rela-block editor-container">
<div class="rela-inline ui-container left-container">
<div class="rela-block pattern-container">
<p>- Patterns -</p>
<div v-for="p in patternNum" :class="['left', 'pattern', (p-1===currentPattern)?'highlight':'']"
@click="currentPattern=(p-1); updatePatterns();">{{((p-1 <= 15)?'0':'')+(p-1).toString(16).toUpperCase()}}</div>
</div>
<div class="rela-block effect-container">
<p>- Effects -</p>
<div v-for="(e,key) in effects">{{key}}XX - {{e.desc}}</div>
</div>
</div>
<div class="rela-inline ui-container right-container">
<div class="rela-inline track-ruler">
<div v-for="i in 16" class="rela-block row">0{{(i-1).toString(16).toUpperCase()}}</div>
</div>
<div v-for="(t,ind) in tracks" class="rela-inline track">
<div class="track-header">
<input class="rela-block track-name-input" placeholder="Track Name" type="text" v-model="t.trackName" @click="stopInputCapture(); event.stopPropagation();"/>
<div v-if="t.osc" class="rela-block option-select">
<svg viewbox="0 0 100 100" @click="t.waveform = 'sine'; t.osc.type = 'sine';"
:class="['rela-inline', 'option-svg', 'big', t.waveform==='sine'?'active':'']">
<path d="M 15 15 L 85 15 L 85 85 L 15 85 Z"/>
<path d="M 16 50 C 28 22, 38 22, 50 50 S 72 78, 84 50"/>
</svg>
<svg viewbox="0 0 100 100" @click="t.waveform = 'triangle'; t.osc.type = 'triangle';"
:class="['rela-inline', 'option-svg', 'big', t.waveform==='triangle'?'active':'']">
<path d="M 15 15 L 85 15 L 85 85 L 15 85 Z"/>
<path d="M 16 50 L 34 26 L 66 74 L 84 50"/>
</svg>
<svg viewbox="0 0 100 100" @click="t.waveform = 'square'; t.osc.type = 'square';"
:class="['rela-inline', 'option-svg', 'big', t.waveform==='square'?'active':'']">
<path d="M 15 15 L 85 15 L 85 85 L 15 85 Z"/>
<path d="M 16 30 L 50 30 L 50 70 L 84 70"/>
</svg>
<svg viewbox="0 0 100 100" @click="t.waveform = 'sawtooth'; t.osc.type = 'sawtooth';"
:class="['rela-inline', 'option-svg', 'big', t.waveform==='sawtooth'?'active':'']">
<path d="M 15 15 L 85 15 L 85 85 L 15 85 Z"/>
<path d="M 16 58 L 28 70 L 28 30 L 70 70 L 70 30 L 84 44"/>
</svg>
</div>
<div v-else class="rela-block noise-label">- NOISE -</div>
<div :class="['rela-inline', 'mute-button', t.muted?'active':'']" @click="t.muted = !t.muted">Mute</div>
</div>
<div v-for="(i,index) in t.pattern" :class="['rela-block', 'row', (index === cursor.y)?'highlight':'', editMode?'edit':'']">
<div :class="['rela-inline', 'info-cell', 'note-info', (cursor.x === ind*5 && index === cursor.y)?'highlight':'']"
@click="if(!playing) {cursor.y = index; cursor.x = ind*5;}">{{keyFromNote(i[0])||'---'}}</div>
<div :class="['rela-inline', 'info-cell', 'volume-info', (cursor.x === (ind*5)+1 && index === cursor.y)?'highlight':'']"
@click="if(!playing) {cursor.y = index; cursor.x = ind*5 + 1;}">{{i[1]||'-'}}</div>
<div :class="['rela-inline', 'info-cell', 'effect-command', (cursor.x === (ind*5)+2 && index === cursor.y)?'highlight':'']"
@click="if(!playing) {cursor.y = index; cursor.x = ind*5 + 2;}">{{i[2]||'-'}}</div>
<div :class="['rela-inline', 'info-cell', 'effect-info', (cursor.x === (ind*5)+3 && index === cursor.y)?'highlight':'']"
@click="if(!playing) {cursor.y = index; cursor.x = ind*5 + 3;}">{{i[3]||'-'}}</div>
<div :class="['rela-inline', 'info-cell', 'effect-info', (cursor.x === (ind*5)+4 && index === cursor.y)?'highlight':'']"
@click="if(!playing) {cursor.y = index; cursor.x = ind*5 + 4;}">{{i[4]||'-'}}</div>
</div>
</div>
<div class="rela-inline add-button" @click="addTrack('New Track')">+</div>
</div>
</div>
</div>
</div>
</div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.10/vue.min.js'></script>
<script id="rendered-js" >
// --- Notes ---
// Hey look it's a tracker thing.
// Definitely better in full screen mode
// JSON.parse(JSON.stringify( array||object )) is the best!
// Noise channel credit to Mike Foskett
/*
Note: The tracker takes value inputs in hexidecimal.
Meaning the blue volume columns and effect columns will take values from 0 - F
--- Controls ---
A - K is the keyboard while editting / playing
Z and X are octave up and down
Q is a Note Off
Space toggles Edit mode
Enter is Play / Stop
Arrow keys move the cursor around (or you can click around)
Shift + Up / Shift + Down will jump patterns
Tab / Shift + Tab will jump tracks
Shift + Left / Shift + Right will also jump tracks
(For preference options. May change later if new functionality requires it)
* - For the buttload of shortcuts below, there are also buttons on the top for lazy people -
N creates a new pattern after the current pattern
Shift + N duplicates the current pattern
M removes the current pattern
Shift + M clears the current pattern
O creates a new track after the current track
Shift + O duplicates the current track
P removes the current track
Shift + P clears the current track
V copies the current track's pattern to the clipboard
Shift + V pastes the pattern on the clipboard to the current track
Control + V copies the entire pattern to the clipboard
Control + Shift + V pastes the pattern on the clipboard to the current track
--- Effect List ---
0XX - Panning?: 00 full left; FF full right; 80 center (not implemented yet)
1XX - Pitch Slide Up: XX sets slide speed
2XX - Pitch Slide Down: XX sets slide speed
3XY - Gain Envelope: X sets attack, Y sets release
4XY - Vibrato: X is offset in semitones, Y is the speed (Need to make this one)
5XX - Portamento: XX sets speed to following notes
6XX - Pattern Jump: Jump to pattern XX
7XX - Tempo: XX in BPM
8XX - Filter: Set filter to XX freq (00 - 7F is lowpass, 80 - FF is highpass)
9XY - Kill: Kill after Y ticks (6 ticks per 16th)/ X = 0 (no release), X = 1 (release)
*/
// --- To Do --- (stuff for me to do/fix)
// Fix noise track duplication
// Add panning functionality (StereoPannerNode i think?)
// Fix the issue with changing number of tracks and then trying to paste a pattern
// (specifically when you add tracks and try to paste a smaller pattern)
// Work on Save/Load feature for tracks
// Work on undo functionality
// Work on the design (Shit looks like butts yo)
// Add instruments (maybe add the stuff from the synthesizer project for each track?)
// Figure out timing constant for the Vibrato effect
// - Audio Context -
var ac = new AudioContext();
// - Vue Stuff -
var tracker = new Vue({
el: '#tracker',
data: {
cursor: { x: 0, y: 0 },
shiftHeld: false,
ctrlHeld: false,
masterVolume: 0.2,
tempo: 110, // in bpm
effects: {
'1': {
desc: 'Pitch Slide Up',
func: function (X, Y, i) {
if (!tracker.tracks[i].osc) {return false;}
if (X === '0' && Y === '0') {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.tracks[i].osc.frequency.value, ac.currentTime, 0);
} else {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(110), ac.currentTime, (1 - parseInt(X.toString() + Y.toString(), 16) / 255) * 3);
}
} },
'2': {
desc: 'Pitch Slide Down',
func: function (X, Y, i) {
if (!tracker.tracks[i].osc) {return false;}
if (X === '0' && Y === '0') {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.tracks[i].osc.frequency.value, ac.currentTime, 0);
} else {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(0), ac.currentTime, (1 - parseInt(X.toString() + Y.toString(), 16) / 255) * 3);
}
} },
'3': {
desc: 'Gain Envelope',
func: function (X, Y, i) {
tracker.tracks[i].gainAttack = parseInt(X.toString(), 16) / 15;
tracker.tracks[i].gainRelease = parseInt(Y.toString(), 16) / 15;
} },
'4': {
desc: 'Vibrato',
func: function (X, Y, i) {
if (!tracker.tracks[i].osc) {return false;}
clearInterval(tracker.tracks[i].vInterval);
if (X === '0' || Y === '0') {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(tracker.tracks[i].currentNote), ac.currentTime, 0);
} else {
var modArr = [8, 4, 2, 1, 0.75, 2 / 3, 0.5, 1 / 3, 0.25, 1 / 6, 0.125, 1 / 12, 1 / 16, 1 / 32, 1 / 64, 1 / 128];
var time = 15000 / tracker.tempo * modArr[parseInt(Y.toString(), 16)];
if (Math.floor(tracker.tracks[i].osc.frequency.value) <= Math.floor(tracker.freqFromNote(tracker.tracks[i].currentNote))) {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(tracker.tracks[i].currentNote + parseInt(X.toString(), 16)), ac.currentTime, 0.2);
} else {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(tracker.tracks[i].currentNote - parseInt(X.toString(), 16)), ac.currentTime, 0.2);
}
tracker.tracks[i].vInterval = setInterval(function () {
if (Math.floor(tracker.tracks[i].osc.frequency.value) <= Math.floor(tracker.freqFromNote(tracker.tracks[i].currentNote))) {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(tracker.tracks[i].currentNote + parseInt(X.toString(), 16)), ac.currentTime, 0.2);
} else {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(tracker.tracks[i].currentNote - parseInt(X.toString(), 16)), ac.currentTime, 0.2);
}
}, time);
}
} },
'5': {
desc: 'Portamento',
func: function (X, Y, i) {tracker.tracks[i].portaSpeed = (1 - parseInt(X.toString() + Y.toString(), 16) / 255) * 3;} },
'6': {
desc: 'Pattern Jump',
func: function (X, Y, i) {
if (parseInt(X.toString() + Y.toString(), 16) < tracker.patternNum) {
tracker.currentPattern = parseInt(X.toString() + Y.toString(), 16);
tracker.cursor.y = 0;
}
} },
'7': {
desc: 'Tempo',
func: function (X, Y, i) {if (parseInt(X.toString() + Y.toString(), 16) >= 1) {tracker.tempo = parseInt(X.toString() + Y.toString(), 16);tracker.resetPlay();}} },
'8': {
desc: 'Filter',
func: function (X, Y, i) {
var num = parseInt(X.toString() + Y.toString(), 16);
if (num <= 127) {
// lowpass (0 - 6000Hz)
tracker.setFilterType(i, 'lowpass');
tracker.setFilterFreq(i, num / 127 * 6000);
} else {
// highpass (0 - 10000Hz)
tracker.setFilterType(i, 'highpass');
tracker.setFilterFreq(i, (num - 128) / 127 * 10000);
}
} },
'9': {
desc: 'Kill Note',
func: function (X, Y, i) {
setTimeout(function () {
tracker.tracks[i].playing = false;
tracker.tracks[i].gainNode.gain.setTargetAtTime(0, ac.currentTime, X === '0' ? 0 : tracker.tracks[i].gainRelease);
}, 15000 / tracker.tempo / 6 * parseInt(Y.toString(), 16));
} } },
// For testing if an input's char code is a hexidecimal digit
hexArray: [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70],
editMode: false,
playing: false,
keyHeld: 0,
octaveMod: 0,
currentPattern: 0,
patternNum: 1,
tracks: [
{
trackName: 'Square 1',
trackVolume: 1,
muted: false,
playing: false,
currentNote: 0,
vInterval: '',
osc: ac.createOscillator(),
waveform: 'square',
gainNode: ac.createGain(),
gainAttack: 0,
gainRelease: 0,
filterNode: ac.createBiquadFilter(),
filterType: 'lowpass',
portaSpeed: 0,
pattern: [],
patternBank: [
[['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]] },
{
trackName: 'Square 2',
trackVolume: 1,
muted: false,
playing: false,
currentNote: 0,
vInterval: '',
osc: ac.createOscillator(),
waveform: 'square',
gainNode: ac.createGain(),
gainAttack: 0,
gainRelease: 0,
filterNode: ac.createBiquadFilter(),
filterType: 'lowpass',
portaSpeed: 0,
pattern: [],
patternBank: [
[['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]] },
{
trackName: 'Triangle',
trackVolume: 1,
muted: false,
playing: false,
currentNote: 0,
vInterval: '',
osc: ac.createOscillator(),
waveform: 'triangle',
gainNode: ac.createGain(),
gainAttack: 0,
gainRelease: 0,
filterNode: ac.createBiquadFilter(),
filterType: 'lowpass',
portaSpeed: 0,
pattern: [],
patternBank: [
[['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]] },
{
trackName: 'Sawtooth',
trackVolume: 1,
muted: false,
playing: false,
currentNote: 0,
vInterval: '',
osc: ac.createOscillator(),
waveform: 'sawtooth',
gainNode: ac.createGain(),
gainAttack: 0,
gainRelease: 0,
filterNode: ac.createBiquadFilter(),
filterType: 'lowpass',
portaSpeed: 0,
pattern: [],
patternBank: [
[['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]] },
{
trackName: 'Noise',
trackVolume: 1,
muted: false,
playing: false,
currentNote: 0,
vInterval: '',
osc: '',
waveform: '',
gainNode: ac.createGain(),
gainAttack: 0,
gainRelease: 0,
filterNode: ac.createBiquadFilter(),
filterType: 'lowpass',
portaSpeed: 0,
pattern: [],
patternBank: [
[['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]] }],
colorArray: ['#F00', '#FF8000', '#FF0', '#80FF00', '#0F0', '#00FF80', '#0FF', '#0080FF', '#F0F', '#FF0080'],
// Clipboards for copying and Pasting
trackClipboard: [],
patternClipboard: [],
// Event Capture Functions
keydownFunction: function (e) {
e.preventDefault();
var note = tracker.evalKeystroke(e.which);
switch (e.which) {
// Octave change and checks
case 90:tracker.octaveMod--;if (tracker.octaveMod < -4) tracker.octaveMod = -4;break;
case 88:tracker.octaveMod++;if (tracker.octaveMod > 4) tracker.octaveMod = 4;break;
// Edit cursor movement
case 38:
if (tracker.shiftHeld) {tracker.currentPattern--;tracker.checkPattern();} else
{tracker.cursor.y--;}
break;
case 40:
if (tracker.shiftHeld) {tracker.currentPattern++;tracker.checkPattern();} else
{tracker.cursor.y++;}
break;
case 37:tracker.cursor.x -= tracker.shiftHeld ? 5 : 1;break;
case 39:tracker.cursor.x += tracker.shiftHeld ? 5 : 1;break;
// Play/Stop on Enter
case 13:
if (tracker.playing) {tracker.stop();for (var i in tracker.tracks) {tracker.noteOff(i);tracker.tracks[i].portaSpeed = 0;}} else
{tracker.cursor.y = 0;tracker.play();}
break;
// Space
case 32:tracker.editMode = !tracker.editMode;break;
// Shift
case 16:tracker.shiftHeld = true;break;
// Control
case 17:tracker.ctrlHeld = true;break;
// Tab
case 9:tracker.cursor.x += tracker.shiftHeld ? -5 : 5;break;
// N - New pattern / Duplicate pattern (shifted)
case 78:tracker.shiftHeld ? tracker.duplicatePattern(tracker.currentPattern) :
tracker.addPattern(tracker.currentPattern);break;
// M - Remove pattern / Clear Pattern (shifted)
case 77:tracker.shiftHeld ? tracker.clearPattern(tracker.currentPattern) :
tracker.removePattern(tracker.currentPattern);break;
// O - New track / Duplicate track (shifted)
case 79:tracker.shiftHeld ? tracker.duplicateTrack(Math.floor(tracker.cursor.x / 5)) :
tracker.addTrack('New Track');break;
// P - Remove track / Clear track (shifted)
case 80:tracker.shiftHeld ? tracker.clearTrack(Math.floor(tracker.cursor.x / 5)) :
tracker.removeTrack(Math.floor(tracker.cursor.x / 5));break;
// V - copy track pattern / copy entire pattern (shifted)
// If ctrl held - paste track pattern / paste entire pattern (shifted)
case 86:
// Breaks when the number of tracks changes after pattern is copied. Need to fix (adjust size of the clipboard array?)
if (tracker.ctrlHeld) {
tracker.shiftHeld ? tracker.pastePattern(tracker.currentPattern) :
tracker.pasteTrackPattern(tracker.currentPattern, Math.floor(tracker.cursor.x / 5));
} else {
tracker.shiftHeld ? tracker.copyPattern(tracker.currentPattern) :
tracker.copyTrackPattern(tracker.currentPattern, Math.floor(tracker.cursor.x / 5));
}
break;}
;
var n = tracker.cursor.x % 5;
if (tracker.editMode) {
if (e.which === 46) {
if (n === 0 || n === 1) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][n] = '';
if (!tracker.playing) {tracker.cursor.y++;}
} else if (n === 2 || n === 3 || n === 4) {
for (var i = 2; i < 5; i++) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][i] = '';
}
if (!tracker.playing) {tracker.cursor.y++;}
}
} else {
if (n === 0) {
if (e.which === 81) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][n] = 'OFF';
if (!tracker.playing) {tracker.cursor.y++;}
} else if (note && note >= 17 && note <= 125) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][n] = note;
if (!tracker.playing) {tracker.cursor.y++;}
}
} else if (n === 1) {
if (tracker.hexArray.includes(e.which)) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][n] = String.fromCharCode(e.which);
if (!tracker.playing) {tracker.cursor.y++;}
}
} else if (n === 2) {
// Parse for Effect Command
if (tracker.effects[String.fromCharCode(e.which)]) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][2] = String.fromCharCode(e.which);
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][3] = '0';
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][4] = '0';
if (!tracker.playing) {tracker.cursor.y++;}
}
} else if (n === 3 || n === 4) {
if (tracker.hexArray.includes(e.which) && tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][2]) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][n] = String.fromCharCode(e.which);
if (!tracker.playing) {tracker.cursor.y++;}
}
}
}
}
if (note && note >= 17 && note <= 125 && n === 0) {
if (!tracker.keyHeld || tracker.keyHeld && tracker.keyHeld !== e.which) {
tracker.keyHeld = e.which;
tracker.noteOn(Math.floor(tracker.cursor.x / 5), note);
};
}
tracker.checkCursorPos();
return false;
},
keyupFunction: function (e) {
if (e.which === 16) {tracker.shiftHeld = false;}
if (e.which === 17) {tracker.ctrlHeld = false;}
if (tracker.playing && tracker.editMode && tracker.evalKeystroke(e.which)) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][0] = 'OFF';
} else {
if (tracker.keyHeld === e.which) {tracker.keyHeld = 0;tracker.noteOff(Math.floor(tracker.cursor.x / 5));};
}
return false;
},
// Play function
playInterval: '' },
methods: {
// - General Functions -
init: function () {
for (var t in this.tracks) {tracker.setupTrack(t);}
tracker.updatePatterns();
tracker.checkTempo();
tracker.captureInput();
},
checkTempo: function () {
if (tracker.tempo > 255) {tracker.tempo = 255;}
if (tracker.tempo < 1) {tracker.tempo = 1;}
},
checkCursorPos: function () {
if (tracker.cursor.y < 0) {tracker.cursor.y = 15;tracker.currentPattern--;tracker.checkPattern();}
if (tracker.cursor.y > 15) {tracker.cursor.y = 0;tracker.currentPattern++;tracker.checkPattern();}
if (tracker.cursor.x < 0) {tracker.cursor.x += tracker.tracks.length * 5;}
if (tracker.cursor.x >= tracker.tracks.length * 5) {tracker.cursor.x -= tracker.tracks.length * 5;}
},
// - Track Functions -
addTrack: function (name, dupIndex, noise) {
if (dupIndex || dupIndex === 0) {
var n = tracker.tracks[dupIndex],
newTN = n.trackName,
newTV = n.trackVolume,
newM = n.muted,
newPl = n.playing,
newCN = n.currentNote,
newW = n.waveform,
newGA = n.gainAttack,
newGR = n.gainRelease,
newFT = n.filterType,
newPS = n.portaSpeed,
newP = JSON.parse(JSON.stringify(n.pattern)),
newPB = JSON.parse(JSON.stringify(n.patternBank));
}
var newTrackInfo = {
trackName: newTN || name || 'Untitled',
trackVolume: newTV || 1,
muted: newM || false,
playing: newPl || false,
currentNote: newCN || 0,
vInterval: '',
osc: noise ? '' : ac.createOscillator(),
waveform: noise ? '' : newW || 'sine',
gainNode: ac.createGain(),
gainAttack: newGA || 0,
gainRelease: newGR || 0,
filterNode: ac.createBiquadFilter(),
filterType: newFT || 'lowpass',
portaSpeed: newPS || 0,
pattern: newP || [],
patternBank: newPB || [] };
if (!newTrackInfo.patternBank[0]) {
for (var i = 0; i < tracker.patternNum; i++) {
newTrackInfo.patternBank.push([['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]);
}
}
this.tracks.splice(dupIndex + 1 || tracker.tracks.length, 0, newTrackInfo);
tracker.setupTrack(dupIndex + 1 || this.tracks.length - 1, noise);
tracker.updatePatterns();
},
duplicateTrack: function (index) {tracker.addTrack('Copy', index);},
removeTrack: function (index) {if (this.tracks.length > 1) this.tracks.splice(index, 1);},
clearTrack: function (index) {
tracker.tracks[index].patternBank[tracker.currentPattern] = [['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']];
tracker.updatePatterns();
tracker.noteOff(index);
},
setupTrack: function (index, noise) {
// Gain Setup
this.tracks[index].gainNode.gain.setValueAtTime(0, ac.currentTime, 0);
this.tracks[index].gainNode.connect(ac.destination);
// Filter Setup
this.tracks[index].filterNode.type = this.tracks[index].filterType;
this.tracks[index].filterNode.connect(this.tracks[index].gainNode);
setTimeout(function () {
tracker.setFilterFreq(index, 5000);
tracker.setFilterQ(index, 0);
}, 10);
if (noise || !this.tracks[index].osc) {
var bufferSize = 2 * ac.sampleRate,
noiseBuffer = ac.createBuffer(1, bufferSize, ac.sampleRate);
var output = noiseBuffer.getChannelData(0);
for (var i = 0; i < bufferSize; i++) {output[i] = Math.random() * 2 - 1;}
this.tracks[index].audioSource = ac.createBufferSource();
this.tracks[index].audioSource.connect(this.tracks[index].filterNode);
this.tracks[index].audioSource.buffer = noiseBuffer;
this.tracks[index].audioSource.loop = true;
this.tracks[index].audioSource.start();
} else {
// Oscillater Setup
this.tracks[index].osc.type = this.tracks[index].waveform;
this.tracks[index].osc.connect(this.tracks[index].filterNode);
this.tracks[index].osc.start();
}
},
// - Pattern Functions -
addPattern: function (index, dupIndex) {
tracker.patternNum++;
tracker.currentPattern = index + 1;
for (var t in tracker.tracks) {
var b;
if (dupIndex || dupIndex === 0) b = JSON.parse(JSON.stringify(tracker.tracks[t].patternBank[dupIndex]));
tracker.tracks[t].patternBank.splice(index + 1, 0, b || [['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]);
}
tracker.updatePatterns();
},
duplicatePattern: function (index) {tracker.addPattern(index, index);},
removePattern: function (index) {
if (tracker.patternNum > 1) {
if (tracker.currentPattern === tracker.patternNum - 1) {tracker.currentPattern--;}
tracker.patternNum--;
for (var t in tracker.tracks) {tracker.tracks[t].patternBank.splice(index, 1);}
tracker.checkPattern();
tracker.updatePatterns();
}
},
clearPattern: function (index) {
for (var t in tracker.tracks) {
tracker.track
```
l>
A:
You can use the following code to get the value of the input field and then use it to set the value of the hidden field.
$(document).ready(function(){
$('#myInput').on('change', function(){
$('#myHiddenField').val($(
CairoRenderContext::renderImage(const CairoImageWrapper& img, int srcX, int srcY)
{
cairo_save(_cr);
cairo_translate(_cr, _width * srcX, _height * srcY);
cairo_set_source
translateFri, 19 Jan 2024 translate code:
function add(a, b) {
return a + b;
}
```python
def add(a, b):
return a + b
```
translate code: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(count) {
```Javascript
You can use the following code to get the current date and time in the format you want:
NSDate *date = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *dateString =
You can use the following code to achieve what you want:
HTML:
<div class="wrapper">
<div class="box">
<div class="box__content">
<div class="box__content__inner">
<div class="box__content__inner__left">
<div class="box__content__inner__left__inner">
<div class="box__content__inner__left__inner
function that: add two numbers together
```python
def add(a, b):
return a + b
add(1, 2)
```
function that: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(
```Javascript
#main {
width: 100%;
height: 100%;
background-color: #000000;
color: #ffffff;
text-align: center;
}
#main .container {
width: 100%;
height: 100%;
background-color: #000000;
color: #ffffff;
text-align: center;
}
#main .container .row {
width: 100%;
height: 100%;
background-color: #000000;
color: #ffffff;
l>
A:
You can use the following code to get the value of the input field and then use it to set the value of the hidden field.
$(document).ready(function(){
$('#myInput').on('change', function(){
$('#myHiddenField').val($(
You can use the following code to get the desired result.
<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: collapse;
}
td, th {
border: 1px solid black;
}
</style>
</head>
<body>
<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>Gender</th>
</tr>
<tr>
<td>John</td>
echo=FALSE}
library(ggplot2)
library(dplyr)
library(tidyr)
library(stringr)
library(reshape2)
library(scales)
library(gridExtra)
library(grid)
library(gridBase)
library(gridExtra)
library(
html code that: create a div with class "container" and id "main" and text "hello world"
```
<div class="container" id="main">hello world</div>
```
html code that:
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<link rel="apple-touch-icon" type="image/png" href="https://cpwebassets.codepen.io/assets/favicon/apple-touch-icon-5ae1a0698dcc2402e9712f7d01ed509a57814f994c660df9f7a952f3060705ee.png" />
<meta name="apple-mobile-web-app-title" content="CodePen">
<link rel="shortcut icon" type="image/x-icon" href="https://cpwebassets.codepen.io/assets/favicon/favicon-aec34940fbc1a6e787974dcd360f2c6b63348d4b1f4e06c77743096d55480f33.ico" />
<link rel="mask-icon" type="image/x-icon" href="https://cpwebassets.codepen.io/assets/favicon/logo-pin-b4b4269c16397ad2f0f7a01bcdf513a1994f4c94b8af2f191c09eb0d601762b1.svg" color="#111" />
<script src="https://cpwebassets.codepen.io/assets/common/stopExecutionOnTimeout-2c7831bb44f98c1391d6a4ffda0e1fd302503391ca806e7fcc7b9b87197aec26.js"></script>
<title>CodePen - js music tracker thing</title>
<link rel="canonical" href="https://codepen.io/mavrK/pen/GQJbYm">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<style>
* {
box-sizing: border-box;
transition: 0.3s cubic-bezier(0.6, 0, 0.2, 1);
}
.abs-center {
position: absolute;
top: 50%;
left: 50%;
right: ;
bottom: ;
transform: translate(-50%, -50%);
}
.vert-center {
position: absolute;
top: 50%;
left: ;
right: ;
bottom: ;
transform: translateY(-50%);
}
.horz-center {
position: absolute;
top: ;
left: 50%;
right: ;
bottom: ;
transform: translateX(-50%);
}
.rela-block {
display: block;
position: relative;
}
.rela-inline {
display: inline-block;
position: relative;
}
.left {
position: relative;
float: left;
}
.right {
position: relative;
float: right;
}
body {
transition: 0s;
background-color: #f1f1f1;
font-family: 'Ubuntu Mono', monospace;
}
h1 {
font-size: 30px;
margin-bottom: 20px;
}
input {
width: 45px;
border: none;
background-color: transparent;
color: inherit;
font: inherit;
}
input:focus {
outline: none;
}
.container {
width: 88%;
text-align: center;
}
.tracker {
padding: 20px;
background-color: #444;
color: #fff;
}
.info-container {
margin-bottom: 20px;
padding: 10px;
border: 1px solid #bbb;
}
.ui-container {
vertical-align: top;
}
.ui-container.left-container {
margin-right: 20px;
}
.track {
padding: 90px 0 10px;
border: 1px solid #bbb;
}
.track .row {
padding: 0 22px 0 20px;
}
.track-ruler {
border: 1px solid #bbb;
margin-right: -5px;
padding: 10px 0;
}
.track-header {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: ;
height: 80px;
line-height: 30px;
border-bottom: 1px solid #bbb;
}
.track-name-input {
height: 25px;
width: 100%;
text-align: center;
}
.option-select {
height: 24px;
width: 100%;
overflow: hidden;
}
.option-svg {
width: 22%;
margin: 0 -4px;
fill: none;
stroke: #999;
stroke-width: 5;
cursor: pointer;
transition: 0s;
}
.option-svg.active {
stroke: #fff;
}
.noise-label {
line-height: 24px;
}
.mute-button {
border: 1px solid;
padding: 0 5px;
height: 20px;
line-height: 19px;
cursor: pointer;
}
.mute-button.active {
border: 1px solid #fd2;
color: #fd2;
}
.info-cell,
.row {
transition: 0s;
}
.row {
padding: 0 10px;
cursor: default;
}
.row.highlight {
background-color: rgba(0,0,0,0.3);
}
.row.highlight.edit {
background-color: rgba(150,0,0,0.3);
}
.info-cell.highlight {
background-color: rgba(255,255,255,0.3);
}
.volume-info {
color: #49f;
}
.effect-command,
.effect-info {
margin: 0 -3px;
}
.effect-command {
margin-left: 0;
color: #c18;
}
.effect-info {
color: #f77;
}
.pattern-container,
.effect-container {
width: 140px;
margin: 0 auto 20px;
padding: 15px 5px;
border: 1px solid #bbb;
overflow: hidden;
}
.pattern-container p,
.effect-container p {
margin-bottom: 10px;
}
.effect-container {
width: 200px;
padding: 10px;
}
.effect-container div {
text-align: left;
}
.pattern {
width: 21%;
margin: 2%;
cursor: pointer;
}
.pattern.highlight {
background-color: rgba(255,255,255,0.3);
}
.control-container {
overflow: hidden;
padding: 10px;
}
.control-container p {
margin-bottom: 5px;
}
.control-container button {
margin: 0 5px 5px;
}
.add-button {
height: 20px;
width: 20px;
line-height: 18px;
border: 1px solid #bbb;
color: #bbb;
vertical-align: bottom;
cursor: pointer;
}
.add-button:hover {
border: 1px solid #fff;
color: #fff;
}
</style>
<script>
window.console = window.console || function(t) {};
</script>
</head>
<body translate="no">
<!-- FONTS -->
<link href="https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700" rel="stylesheet">
<!-- PAGE STUFF -->
<div id="tracker" @click="captureInput()">
<div class="abs-center container">
<div class="rela-inline tracker">
<h1>JS Tracker</h1>
<div class="rela-block info-container">
<pre>Octave: {{octaveMod + 4}} Tempo: <input v-model="tempo" type="number" min="1" max="255" @click="stopInputCapture(); event.stopPropagation();" @change="checkTempo(); if(playing){resetPlay()}"/></pre>
<div class="rela-block control-container">
<p>- Controls -</p>
<button class="left" @click="addTrack('New Track')">New Track</button>
<button class="left" @click="addTrack('New Track',undefined,true)">New Noise Track</button>
<button class="left" @click="duplicateTrack(Math.floor(cursor.x/5))">Duplicate Track</button>
<button class="left" @click="removeTrack(Math.floor(cursor.x/5));">Remove Track</button>
<button class="left" @click="clearTrack(Math.floor(cursor.x/5));">Clear Track</button>
<button class="left" @click="copyTrackPattern(currentPattern, Math.floor(cursor.x/5))">Copy Track</button>
<button class="left" @click="pasteTrackPattern(currentPattern, Math.floor(cursor.x/5))">Paste Track</button><br><br>
<button class="left" @click="addPattern(currentPattern)">New Pattern</button>
<button class="left" @click="duplicatePattern(currentPattern)">Duplicate Pattern</button>
<button class="left" @click="removePattern(currentPattern)">Remove Pattern</button>
<button class="left" @click="clearPattern(currentPattern);">Clear Pattern</button>
<button class="left" @click="copyPattern(currentPattern)">Copy Pattern</button>
<button class="left" @click="pastePattern(currentPattern)">Paste Pattern</button>
<button class="left" @click="ac.resume()">START AUDIO</button>
<button class="left" onclick="share()">Share</button>
</div>
</div>
<div class="rela-block editor-container">
<div class="rela-inline ui-container left-container">
<div class="rela-block pattern-container">
<p>- Patterns -</p>
<div v-for="p in patternNum" :class="['left', 'pattern', (p-1===currentPattern)?'highlight':'']"
@click="currentPattern=(p-1); updatePatterns();">{{((p-1 <= 15)?'0':'')+(p-1).toString(16).toUpperCase()}}</div>
</div>
<div class="rela-block effect-container">
<p>- Effects -</p>
<div v-for="(e,key) in effects">{{key}}XX - {{e.desc}}</div>
</div>
</div>
<div class="rela-inline ui-container right-container">
<div class="rela-inline track-ruler">
<div v-for="i in 16" class="rela-block row">0{{(i-1).toString(16).toUpperCase()}}</div>
</div>
<div v-for="(t,ind) in tracks" class="rela-inline track">
<div class="track-header">
<input class="rela-block track-name-input" placeholder="Track Name" type="text" v-model="t.trackName" @click="stopInputCapture(); event.stopPropagation();"/>
<div v-if="t.osc" class="rela-block option-select">
<svg viewbox="0 0 100 100" @click="t.waveform = 'sine'; t.osc.type = 'sine';"
:class="['rela-inline', 'option-svg', 'big', t.waveform==='sine'?'active':'']">
<path d="M 15 15 L 85 15 L 85 85 L 15 85 Z"/>
<path d="M 16 50 C 28 22, 38 22, 50 50 S 72 78, 84 50"/>
</svg>
<svg viewbox="0 0 100 100" @click="t.waveform = 'triangle'; t.osc.type = 'triangle';"
:class="['rela-inline', 'option-svg', 'big', t.waveform==='triangle'?'active':'']">
<path d="M 15 15 L 85 15 L 85 85 L 15 85 Z"/>
<path d="M 16 50 L 34 26 L 66 74 L 84 50"/>
</svg>
<svg viewbox="0 0 100 100" @click="t.waveform = 'square'; t.osc.type = 'square';"
:class="['rela-inline', 'option-svg', 'big', t.waveform==='square'?'active':'']">
<path d="M 15 15 L 85 15 L 85 85 L 15 85 Z"/>
<path d="M 16 30 L 50 30 L 50 70 L 84 70"/>
</svg>
<svg viewbox="0 0 100 100" @click="t.waveform = 'sawtooth'; t.osc.type = 'sawtooth';"
:class="['rela-inline', 'option-svg', 'big', t.waveform==='sawtooth'?'active':'']">
<path d="M 15 15 L 85 15 L 85 85 L 15 85 Z"/>
<path d="M 16 58 L 28 70 L 28 30 L 70 70 L 70 30 L 84 44"/>
</svg>
</div>
<div v-else class="rela-block noise-label">- NOISE -</div>
<div :class="['rela-inline', 'mute-button', t.muted?'active':'']" @click="t.muted = !t.muted">Mute</div>
</div>
<div v-for="(i,index) in t.pattern" :class="['rela-block', 'row', (index === cursor.y)?'highlight':'', editMode?'edit':'']">
<div :class="['rela-inline', 'info-cell', 'note-info', (cursor.x === ind*5 && index === cursor.y)?'highlight':'']"
@click="if(!playing) {cursor.y = index; cursor.x = ind*5;}">{{keyFromNote(i[0])||'---'}}</div>
<div :class="['rela-inline', 'info-cell', 'volume-info', (cursor.x === (ind*5)+1 && index === cursor.y)?'highlight':'']"
@click="if(!playing) {cursor.y = index; cursor.x = ind*5 + 1;}">{{i[1]||'-'}}</div>
<div :class="['rela-inline', 'info-cell', 'effect-command', (cursor.x === (ind*5)+2 && index === cursor.y)?'highlight':'']"
@click="if(!playing) {cursor.y = index; cursor.x = ind*5 + 2;}">{{i[2]||'-'}}</div>
<div :class="['rela-inline', 'info-cell', 'effect-info', (cursor.x === (ind*5)+3 && index === cursor.y)?'highlight':'']"
@click="if(!playing) {cursor.y = index; cursor.x = ind*5 + 3;}">{{i[3]||'-'}}</div>
<div :class="['rela-inline', 'info-cell', 'effect-info', (cursor.x === (ind*5)+4 && index === cursor.y)?'highlight':'']"
@click="if(!playing) {cursor.y = index; cursor.x = ind*5 + 4;}">{{i[4]||'-'}}</div>
</div>
</div>
<div class="rela-inline add-button" @click="addTrack('New Track')">+</div>
</div>
</div>
</div>
</div>
</div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.10/vue.min.js'></script>
<script id="rendered-js" >
// --- Notes ---
// Hey look it's a tracker thing.
// Definitely better in full screen mode
// JSON.parse(JSON.stringify( array||object )) is the best!
// Noise channel credit to Mike Foskett
/*
Note: The tracker takes value inputs in hexidecimal.
Meaning the blue volume columns and effect columns will take values from 0 - F
--- Controls ---
A - K is the keyboard while editting / playing
Z and X are octave up and down
Q is a Note Off
Space toggles Edit mode
Enter is Play / Stop
Arrow keys move the cursor around (or you can click around)
Shift + Up / Shift + Down will jump patterns
Tab / Shift + Tab will jump tracks
Shift + Left / Shift + Right will also jump tracks
(For preference options. May change later if new functionality requires it)
* - For the buttload of shortcuts below, there are also buttons on the top for lazy people -
N creates a new pattern after the current pattern
Shift + N duplicates the current pattern
M removes the current pattern
Shift + M clears the current pattern
O creates a new track after the current track
Shift + O duplicates the current track
P removes the current track
Shift + P clears the current track
V copies the current track's pattern to the clipboard
Shift + V pastes the pattern on the clipboard to the current track
Control + V copies the entire pattern to the clipboard
Control + Shift + V pastes the pattern on the clipboard to the current track
--- Effect List ---
0XX - Panning?: 00 full left; FF full right; 80 center (not implemented yet)
1XX - Pitch Slide Up: XX sets slide speed
2XX - Pitch Slide Down: XX sets slide speed
3XY - Gain Envelope: X sets attack, Y sets release
4XY - Vibrato: X is offset in semitones, Y is the speed (Need to make this one)
5XX - Portamento: XX sets speed to following notes
6XX - Pattern Jump: Jump to pattern XX
7XX - Tempo: XX in BPM
8XX - Filter: Set filter to XX freq (00 - 7F is lowpass, 80 - FF is highpass)
9XY - Kill: Kill after Y ticks (6 ticks per 16th)/ X = 0 (no release), X = 1 (release)
*/
// --- To Do --- (stuff for me to do/fix)
// Fix noise track duplication
// Add panning functionality (StereoPannerNode i think?)
// Fix the issue with changing number of tracks and then trying to paste a pattern
// (specifically when you add tracks and try to paste a smaller pattern)
// Work on Save/Load feature for tracks
// Work on undo functionality
// Work on the design (Shit looks like butts yo)
// Add instruments (maybe add the stuff from the synthesizer project for each track?)
// Figure out timing constant for the Vibrato effect
// - Audio Context -
var ac = new AudioContext();
// - Vue Stuff -
var tracker = new Vue({
el: '#tracker',
data: {
cursor: { x: 0, y: 0 },
shiftHeld: false,
ctrlHeld: false,
masterVolume: 0.2,
tempo: 110, // in bpm
effects: {
'1': {
desc: 'Pitch Slide Up',
func: function (X, Y, i) {
if (!tracker.tracks[i].osc) {return false;}
if (X === '0' && Y === '0') {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.tracks[i].osc.frequency.value, ac.currentTime, 0);
} else {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(110), ac.currentTime, (1 - parseInt(X.toString() + Y.toString(), 16) / 255) * 3);
}
} },
'2': {
desc: 'Pitch Slide Down',
func: function (X, Y, i) {
if (!tracker.tracks[i].osc) {return false;}
if (X === '0' && Y === '0') {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.tracks[i].osc.frequency.value, ac.currentTime, 0);
} else {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(0), ac.currentTime, (1 - parseInt(X.toString() + Y.toString(), 16) / 255) * 3);
}
} },
'3': {
desc: 'Gain Envelope',
func: function (X, Y, i) {
tracker.tracks[i].gainAttack = parseInt(X.toString(), 16) / 15;
tracker.tracks[i].gainRelease = parseInt(Y.toString(), 16) / 15;
} },
'4': {
desc: 'Vibrato',
func: function (X, Y, i) {
if (!tracker.tracks[i].osc) {return false;}
clearInterval(tracker.tracks[i].vInterval);
if (X === '0' || Y === '0') {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(tracker.tracks[i].currentNote), ac.currentTime, 0);
} else {
var modArr = [8, 4, 2, 1, 0.75, 2 / 3, 0.5, 1 / 3, 0.25, 1 / 6, 0.125, 1 / 12, 1 / 16, 1 / 32, 1 / 64, 1 / 128];
var time = 15000 / tracker.tempo * modArr[parseInt(Y.toString(), 16)];
if (Math.floor(tracker.tracks[i].osc.frequency.value) <= Math.floor(tracker.freqFromNote(tracker.tracks[i].currentNote))) {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(tracker.tracks[i].currentNote + parseInt(X.toString(), 16)), ac.currentTime, 0.2);
} else {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(tracker.tracks[i].currentNote - parseInt(X.toString(), 16)), ac.currentTime, 0.2);
}
tracker.tracks[i].vInterval = setInterval(function () {
if (Math.floor(tracker.tracks[i].osc.frequency.value) <= Math.floor(tracker.freqFromNote(tracker.tracks[i].currentNote))) {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(tracker.tracks[i].currentNote + parseInt(X.toString(), 16)), ac.currentTime, 0.2);
} else {
tracker.tracks[i].osc.frequency.setTargetAtTime(tracker.freqFromNote(tracker.tracks[i].currentNote - parseInt(X.toString(), 16)), ac.currentTime, 0.2);
}
}, time);
}
} },
'5': {
desc: 'Portamento',
func: function (X, Y, i) {tracker.tracks[i].portaSpeed = (1 - parseInt(X.toString() + Y.toString(), 16) / 255) * 3;} },
'6': {
desc: 'Pattern Jump',
func: function (X, Y, i) {
if (parseInt(X.toString() + Y.toString(), 16) < tracker.patternNum) {
tracker.currentPattern = parseInt(X.toString() + Y.toString(), 16);
tracker.cursor.y = 0;
}
} },
'7': {
desc: 'Tempo',
func: function (X, Y, i) {if (parseInt(X.toString() + Y.toString(), 16) >= 1) {tracker.tempo = parseInt(X.toString() + Y.toString(), 16);tracker.resetPlay();}} },
'8': {
desc: 'Filter',
func: function (X, Y, i) {
var num = parseInt(X.toString() + Y.toString(), 16);
if (num <= 127) {
// lowpass (0 - 6000Hz)
tracker.setFilterType(i, 'lowpass');
tracker.setFilterFreq(i, num / 127 * 6000);
} else {
// highpass (0 - 10000Hz)
tracker.setFilterType(i, 'highpass');
tracker.setFilterFreq(i, (num - 128) / 127 * 10000);
}
} },
'9': {
desc: 'Kill Note',
func: function (X, Y, i) {
setTimeout(function () {
tracker.tracks[i].playing = false;
tracker.tracks[i].gainNode.gain.setTargetAtTime(0, ac.currentTime, X === '0' ? 0 : tracker.tracks[i].gainRelease);
}, 15000 / tracker.tempo / 6 * parseInt(Y.toString(), 16));
} } },
// For testing if an input's char code is a hexidecimal digit
hexArray: [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70],
editMode: false,
playing: false,
keyHeld: 0,
octaveMod: 0,
currentPattern: 0,
patternNum: 1,
tracks: [
{
trackName: 'Square 1',
trackVolume: 1,
muted: false,
playing: false,
currentNote: 0,
vInterval: '',
osc: ac.createOscillator(),
waveform: 'square',
gainNode: ac.createGain(),
gainAttack: 0,
gainRelease: 0,
filterNode: ac.createBiquadFilter(),
filterType: 'lowpass',
portaSpeed: 0,
pattern: [],
patternBank: [
[['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]] },
{
trackName: 'Square 2',
trackVolume: 1,
muted: false,
playing: false,
currentNote: 0,
vInterval: '',
osc: ac.createOscillator(),
waveform: 'square',
gainNode: ac.createGain(),
gainAttack: 0,
gainRelease: 0,
filterNode: ac.createBiquadFilter(),
filterType: 'lowpass',
portaSpeed: 0,
pattern: [],
patternBank: [
[['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]] },
{
trackName: 'Triangle',
trackVolume: 1,
muted: false,
playing: false,
currentNote: 0,
vInterval: '',
osc: ac.createOscillator(),
waveform: 'triangle',
gainNode: ac.createGain(),
gainAttack: 0,
gainRelease: 0,
filterNode: ac.createBiquadFilter(),
filterType: 'lowpass',
portaSpeed: 0,
pattern: [],
patternBank: [
[['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]] },
{
trackName: 'Sawtooth',
trackVolume: 1,
muted: false,
playing: false,
currentNote: 0,
vInterval: '',
osc: ac.createOscillator(),
waveform: 'sawtooth',
gainNode: ac.createGain(),
gainAttack: 0,
gainRelease: 0,
filterNode: ac.createBiquadFilter(),
filterType: 'lowpass',
portaSpeed: 0,
pattern: [],
patternBank: [
[['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]] },
{
trackName: 'Noise',
trackVolume: 1,
muted: false,
playing: false,
currentNote: 0,
vInterval: '',
osc: '',
waveform: '',
gainNode: ac.createGain(),
gainAttack: 0,
gainRelease: 0,
filterNode: ac.createBiquadFilter(),
filterType: 'lowpass',
portaSpeed: 0,
pattern: [],
patternBank: [
[['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]] }],
colorArray: ['#F00', '#FF8000', '#FF0', '#80FF00', '#0F0', '#00FF80', '#0FF', '#0080FF', '#F0F', '#FF0080'],
// Clipboards for copying and Pasting
trackClipboard: [],
patternClipboard: [],
// Event Capture Functions
keydownFunction: function (e) {
e.preventDefault();
var note = tracker.evalKeystroke(e.which);
switch (e.which) {
// Octave change and checks
case 90:tracker.octaveMod--;if (tracker.octaveMod < -4) tracker.octaveMod = -4;break;
case 88:tracker.octaveMod++;if (tracker.octaveMod > 4) tracker.octaveMod = 4;break;
// Edit cursor movement
case 38:
if (tracker.shiftHeld) {tracker.currentPattern--;tracker.checkPattern();} else
{tracker.cursor.y--;}
break;
case 40:
if (tracker.shiftHeld) {tracker.currentPattern++;tracker.checkPattern();} else
{tracker.cursor.y++;}
break;
case 37:tracker.cursor.x -= tracker.shiftHeld ? 5 : 1;break;
case 39:tracker.cursor.x += tracker.shiftHeld ? 5 : 1;break;
// Play/Stop on Enter
case 13:
if (tracker.playing) {tracker.stop();for (var i in tracker.tracks) {tracker.noteOff(i);tracker.tracks[i].portaSpeed = 0;}} else
{tracker.cursor.y = 0;tracker.play();}
break;
// Space
case 32:tracker.editMode = !tracker.editMode;break;
// Shift
case 16:tracker.shiftHeld = true;break;
// Control
case 17:tracker.ctrlHeld = true;break;
// Tab
case 9:tracker.cursor.x += tracker.shiftHeld ? -5 : 5;break;
// N - New pattern / Duplicate pattern (shifted)
case 78:tracker.shiftHeld ? tracker.duplicatePattern(tracker.currentPattern) :
tracker.addPattern(tracker.currentPattern);break;
// M - Remove pattern / Clear Pattern (shifted)
case 77:tracker.shiftHeld ? tracker.clearPattern(tracker.currentPattern) :
tracker.removePattern(tracker.currentPattern);break;
// O - New track / Duplicate track (shifted)
case 79:tracker.shiftHeld ? tracker.duplicateTrack(Math.floor(tracker.cursor.x / 5)) :
tracker.addTrack('New Track');break;
// P - Remove track / Clear track (shifted)
case 80:tracker.shiftHeld ? tracker.clearTrack(Math.floor(tracker.cursor.x / 5)) :
tracker.removeTrack(Math.floor(tracker.cursor.x / 5));break;
// V - copy track pattern / copy entire pattern (shifted)
// If ctrl held - paste track pattern / paste entire pattern (shifted)
case 86:
// Breaks when the number of tracks changes after pattern is copied. Need to fix (adjust size of the clipboard array?)
if (tracker.ctrlHeld) {
tracker.shiftHeld ? tracker.pastePattern(tracker.currentPattern) :
tracker.pasteTrackPattern(tracker.currentPattern, Math.floor(tracker.cursor.x / 5));
} else {
tracker.shiftHeld ? tracker.copyPattern(tracker.currentPattern) :
tracker.copyTrackPattern(tracker.currentPattern, Math.floor(tracker.cursor.x / 5));
}
break;}
;
var n = tracker.cursor.x % 5;
if (tracker.editMode) {
if (e.which === 46) {
if (n === 0 || n === 1) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][n] = '';
if (!tracker.playing) {tracker.cursor.y++;}
} else if (n === 2 || n === 3 || n === 4) {
for (var i = 2; i < 5; i++) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][i] = '';
}
if (!tracker.playing) {tracker.cursor.y++;}
}
} else {
if (n === 0) {
if (e.which === 81) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][n] = 'OFF';
if (!tracker.playing) {tracker.cursor.y++;}
} else if (note && note >= 17 && note <= 125) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][n] = note;
if (!tracker.playing) {tracker.cursor.y++;}
}
} else if (n === 1) {
if (tracker.hexArray.includes(e.which)) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][n] = String.fromCharCode(e.which);
if (!tracker.playing) {tracker.cursor.y++;}
}
} else if (n === 2) {
// Parse for Effect Command
if (tracker.effects[String.fromCharCode(e.which)]) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][2] = String.fromCharCode(e.which);
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][3] = '0';
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][4] = '0';
if (!tracker.playing) {tracker.cursor.y++;}
}
} else if (n === 3 || n === 4) {
if (tracker.hexArray.includes(e.which) && tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][2]) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][n] = String.fromCharCode(e.which);
if (!tracker.playing) {tracker.cursor.y++;}
}
}
}
}
if (note && note >= 17 && note <= 125 && n === 0) {
if (!tracker.keyHeld || tracker.keyHeld && tracker.keyHeld !== e.which) {
tracker.keyHeld = e.which;
tracker.noteOn(Math.floor(tracker.cursor.x / 5), note);
};
}
tracker.checkCursorPos();
return false;
},
keyupFunction: function (e) {
if (e.which === 16) {tracker.shiftHeld = false;}
if (e.which === 17) {tracker.ctrlHeld = false;}
if (tracker.playing && tracker.editMode && tracker.evalKeystroke(e.which)) {
tracker.tracks[Math.floor(tracker.cursor.x / 5)].pattern[tracker.cursor.y][0] = 'OFF';
} else {
if (tracker.keyHeld === e.which) {tracker.keyHeld = 0;tracker.noteOff(Math.floor(tracker.cursor.x / 5));};
}
return false;
},
// Play function
playInterval: '' },
methods: {
// - General Functions -
init: function () {
for (var t in this.tracks) {tracker.setupTrack(t);}
tracker.updatePatterns();
tracker.checkTempo();
tracker.captureInput();
},
checkTempo: function () {
if (tracker.tempo > 255) {tracker.tempo = 255;}
if (tracker.tempo < 1) {tracker.tempo = 1;}
},
checkCursorPos: function () {
if (tracker.cursor.y < 0) {tracker.cursor.y = 15;tracker.currentPattern--;tracker.checkPattern();}
if (tracker.cursor.y > 15) {tracker.cursor.y = 0;tracker.currentPattern++;tracker.checkPattern();}
if (tracker.cursor.x < 0) {tracker.cursor.x += tracker.tracks.length * 5;}
if (tracker.cursor.x >= tracker.tracks.length * 5) {tracker.cursor.x -= tracker.tracks.length * 5;}
},
// - Track Functions -
addTrack: function (name, dupIndex, noise) {
if (dupIndex || dupIndex === 0) {
var n = tracker.tracks[dupIndex],
newTN = n.trackName,
newTV = n.trackVolume,
newM = n.muted,
newPl = n.playing,
newCN = n.currentNote,
newW = n.waveform,
newGA = n.gainAttack,
newGR = n.gainRelease,
newFT = n.filterType,
newPS = n.portaSpeed,
newP = JSON.parse(JSON.stringify(n.pattern)),
newPB = JSON.parse(JSON.stringify(n.patternBank));
}
var newTrackInfo = {
trackName: newTN || name || 'Untitled',
trackVolume: newTV || 1,
muted: newM || false,
playing: newPl || false,
currentNote: newCN || 0,
vInterval: '',
osc: noise ? '' : ac.createOscillator(),
waveform: noise ? '' : newW || 'sine',
gainNode: ac.createGain(),
gainAttack: newGA || 0,
gainRelease: newGR || 0,
filterNode: ac.createBiquadFilter(),
filterType: newFT || 'lowpass',
portaSpeed: newPS || 0,
pattern: newP || [],
patternBank: newPB || [] };
if (!newTrackInfo.patternBank[0]) {
for (var i = 0; i < tracker.patternNum; i++) {
newTrackInfo.patternBank.push([['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]);
}
}
this.tracks.splice(dupIndex + 1 || tracker.tracks.length, 0, newTrackInfo);
tracker.setupTrack(dupIndex + 1 || this.tracks.length - 1, noise);
tracker.updatePatterns();
},
duplicateTrack: function (index) {tracker.addTrack('Copy', index);},
removeTrack: function (index) {if (this.tracks.length > 1) this.tracks.splice(index, 1);},
clearTrack: function (index) {
tracker.tracks[index].patternBank[tracker.currentPattern] = [['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']];
tracker.updatePatterns();
tracker.noteOff(index);
},
setupTrack: function (index, noise) {
// Gain Setup
this.tracks[index].gainNode.gain.setValueAtTime(0, ac.currentTime, 0);
this.tracks[index].gainNode.connect(ac.destination);
// Filter Setup
this.tracks[index].filterNode.type = this.tracks[index].filterType;
this.tracks[index].filterNode.connect(this.tracks[index].gainNode);
setTimeout(function () {
tracker.setFilterFreq(index, 5000);
tracker.setFilterQ(index, 0);
}, 10);
if (noise || !this.tracks[index].osc) {
var bufferSize = 2 * ac.sampleRate,
noiseBuffer = ac.createBuffer(1, bufferSize, ac.sampleRate);
var output = noiseBuffer.getChannelData(0);
for (var i = 0; i < bufferSize; i++) {output[i] = Math.random() * 2 - 1;}
this.tracks[index].audioSource = ac.createBufferSource();
this.tracks[index].audioSource.connect(this.tracks[index].filterNode);
this.tracks[index].audioSource.buffer = noiseBuffer;
this.tracks[index].audioSource.loop = true;
this.tracks[index].audioSource.start();
} else {
// Oscillater Setup
this.tracks[index].osc.type = this.tracks[index].waveform;
this.tracks[index].osc.connect(this.tracks[index].filterNode);
this.tracks[index].osc.start();
}
},
// - Pattern Functions -
addPattern: function (index, dupIndex) {
tracker.patternNum++;
tracker.currentPattern = index + 1;
for (var t in tracker.tracks) {
var b;
if (dupIndex || dupIndex === 0) b = JSON.parse(JSON.stringify(tracker.tracks[t].patternBank[dupIndex]));
tracker.tracks[t].patternBank.splice(index + 1, 0, b || [['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]);
}
tracker.updatePatterns();
},
duplicatePattern: function (index) {tracker.addPattern(index, index);},
removePattern: function (index) {
if (tracker.patternNum > 1) {
if (tracker.currentPattern === tracker.patternNum - 1) {tracker.currentPattern--;}
tracker.patternNum--;
for (var t in tracker.tracks) {tracker.tracks[t].patternBank.splice(index, 1);}
tracker.checkPattern();
tracker.updatePatterns();
}
},
clearPattern: function (index) {
for (var t in tracker.tracks) {
tracker.track
```
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
dy {
font-family: monospace;
font-size: 12px;
margin: 0;
padding: 0;
}
#container {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
overflow: hidden;
}
#container > div {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom:
regex that: match all words that start with "hello"
```
/hello\w+/
```
regex that: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(count) {
```
ript
function add(a, b):
return a + b
add(1, 2)
add(1, 2, 3)
add(1, 2, 3, 4)
Python
def add(a, b):
return a + b
add(1, 2)
add(1, 2, 3)
add(1, 2, 3, 4)
Ruby
ript
function fill(startNum, endNum) {
for (var i = startNum; i <= endNum; i++) {
document.getElementById("demo").innerHTML += i + "<br>";
}
}
fill(1, 10);
A:
You can use the following code to get the desired output.
function fill(startNum, endNum) {
l>
A:
You can use the following code to get the value of the input field and then use it to set the value of the hidden field.
$(document).ready(function(){
$('#myInput').on('change', function(){
$('#myHiddenField').val($(
ript
function fillNumbers(startNum, endNum) {
for (var i = startNum; i <= endNum; i++) {
document.getElementById("number").innerHTML += i;
}
}
function fillNumbers2(startNum, endNum) {
for (var i = startNum; i <= endNum; i++) {
document.getElementById("
You can use the following code to get the desired output.
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
</style>
You can use the following code to achieve what you want:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
$("#div").load(
ript
function duplicateCount(arr) {
var count = 0;
for (var i = 0; i < arr.length; i++) {
if (arr[i].duplicate) {
count++;
}
}
return count;
}
function getDuplicateCount(arr) {
var count = 0;
for (var i = 0; i < arr.length; i++) {
You can use the following code to achieve what you want:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
$("#div").load(
ript
function add(a, b):
return a + b
add(1, 2)
add(1, 2, 3)
add(1, 2, 3, 4)
Python
def add(a, b):
return a + b
add(1, 2)
add(1, 2, 3)
add(1, 2, 3, 4)
Ruby
function that: add two numbers together
```python
def add(a, b):
return a + b
add(1, 2)
```
function that: function that: add two numbers together
```python
def add(a, b):
return a + b
add(1, 2)
```
function that: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(count) {
```Javascript
```Javascript
You can use the following CSS:
#main .container .row {
width: 100%;
}
#main .container .row .col-md-12 {
width: 100%;
}
#main .container .row .col-md-6 {
width: 50%;
}
#main .container .row .col-md-4 {
width: 33.33%;
}
#main
You can use the following code to achieve what you want:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
$("#div").load(
You can use the following CSS:
#main .container .row .col-md-3 {
width: 100%;
}
#main .container .row .col-md-3 .col-md-3 {
width: 50%;
}
#main .container .row .col-md-3 .col-md-3 .col-md-3 {
width: 33.33%;
}
#main .
function that: add two numbers together
```python
def add(a, b):
return a + b
add(1, 2)
```
function that: function that: add two numbers together
```python
def add(a, b):
return a + b
add(1, 2)
```
function that: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(count) {
```Javascript
;
});
});
A:
You can use the following code to get the data from the server:
$.ajax({
url: 'your url',
type: 'GET',
dataType: 'json',
success: function(data) {
console.log(data);
}
});
function that: add two numbers together
```python
def add(a, b):
return a + b
add(1, 2)
```
function that: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(count) {
```Javascript
You can use the following code to get the desired output.
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export
You can use the following code to achieve what you want:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
$("#div").load(
ript
function getDuplicateCount(arr) {
var count = 0;
for (var i = 0; i < arr.length; i++) {
for (var j = i + 1; j < arr.length; j++) {
if (arr[i] === arr[j]) {
count++;
}
}
}
return count;
}
// getDuplicateCount([1,
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
`
explanation of the code:
def add(a, b):
return a + b
```
The function add takes two arguments a and b and returns the sum of a and b.
```
explanation that:
function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(count) {
```
regex that: match all words that start with "hello"
```
/hello\w+/
```
regex that: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(
```
tests that: add(1, 2) returns 3
```
import unittest
class TestAdd(unittest.TestCase):
def test_add(self):
self.assertEqual(add(1, 2), 3)
```
tests that: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(count) {
```
function that: add two numbers together
```python
def add(a, b):
return a + b
add(1, 2)
```
function that: function hcyl(bottom, height, radius, id) {
let radsq = radius * radius
let innerRadsq = (radius - 1.2) * (radius - 1.2)
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq && d >= innerRadsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cyl(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x * x + z * z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function cube(bottom, height, radius, id) {
let radsq = radius * radius
height += bottom
for (let x = -radius; x <= radius; x++) {
for (let y = bottom; y < height; y++) {
for (let z = -radius; z <= radius; z++) {
let d = x + z
if (d < radsq) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sphereoid(w, h, d, id) {
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(p2.x + x, p2.y + y, p2.z + z, id)
}
}
}
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
async function asphereoid(w, h, d, id) {
let px = p2.x
let py = p2.y
let pz = p2.z
let w2 = w * w
let h2 = h * h
let d2 = d * d
let w3 = (w - 1.5) * (w - 1.5)
let h3 = (h - 1.5) * (h - 1.5)
let d3 = (d - 1.5) * (d - 1.5)
for (let y = -h; y < h; y++) {
for (let x = -w; x <= w; x++) {
for (let z = -d; z <= d; z++) {
let n = x * x / w2 + y * y / h2 + z * z / d2
let n2 = x * x / w3 + y * y / h3 + z * z / d3
if (n < 1 && n2 >= 1) {
world.setBlock(px + x, py + y, pz + z, id)
await sleep(10)
}
}
}
}
}
function line(x1, y1, z1, x2, y2, z2, id) {
let dx = Math.abs(x2 - x1);
let dy = Math.abs(y2 - y1);
let dz = Math.abs(z2 - z1);
let sx = (x1 < x2) ? 1 : -1;
let sy = (y1 < y2) ? 1 : -1;
let sz = (z1 < z2) ? 1 : -1;
let err1 = dx - dy;
let err2 = dx - dz;
let err3 = dy - dz;
while (true) {
world.setBlock(x1, y1, z1, id);
if (x1 === x2 && y1 === y2 && z1 === z2) break;
let e2 = 2 * err1;
let e3 = 2 * err2;
let e4 = 2 * err3;
if (e2 > -dy) {
err1 -= dy;
err2 -= dz;
x1 += sx;
}
if (e2 < dx) {
err1 += dx;
err3 -= dz;
y1 += sy;
}
if (e3 > -dz) {
err2 += dy;
err3 += dx;
z1 += sz;
}
}
}
function cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + z, block);
}
}
}
}
function duplicateBlock(sx, sy, sz, dx, dy, dz, w, h, l, offsetX, offsetY, offsetZ, num) {
for (let i = 0; i < num; i++) {
cloneBlock(sx, sy, sz, dx + offsetX * i, dy + offsetY * i, dz + offsetZ * i, w, h, l);
}
}
function rotateBlock(sx, sy, sz, dx, dy, dz, w, h, l, angle) {
let rad = angle * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let nx = Math.round(x * cos - z * sin);
let nz = Math.round(x * sin + z * cos);
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + nx, dy + y, dz + nz, block);
}
}
}
}
function fillBlock(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
function moveBlock(sx, sy, sz, dx, dy, dz, w, h, l) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
fillBlock(sx, sy, sz, sx + w - 1, sy + h - 1, sz + l - 1, 0);
}
function paintBlock(sx, sy, sz, dx, dy, dz, w, h, l, colorId) {
cloneBlock(sx, sy, sz, dx, dy, dz, w, h, l);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(dx + x, dy + y, dz + z, colorId);
}
}
}
}
function replaceBlock(sx, sy, sz, dx, dy, dz, id, newId) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (world.getBlock(startX + x, startY + y, startZ + z) === id) {
world.setBlock(startX + x, startY + y, startZ + z, newId);
}
}
}
}
}
function mirrorBlock(sx, sy, sz, dx, dy, dz, w, h, l, axis) {
if (axis === "x") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + w - x - 1, dy + y, dz + z, block);
}
}
}
} else if (axis === "y") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + h - y - 1, dz + z, block);
}
}
}
} else if (axis === "z") {
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
let block = world.getBlock(sx + x, sy + y, sz + z);
world.setBlock(dx + x, dy + y, dz + l - z - 1, block);
}
}
}
}
}
function clearBlock(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
world.setBlock(startX + x, startY + y, startZ + z, 0);
}
}
}
}
function circleBlock(x, y, z, height, radius, thickness, startDeg, endDeg, id) {
for (let deg = startDeg; deg <= endDeg; deg++) {
let rad = deg * (Math.PI / 180);
let sin = Math.sin(rad);
let cos = Math.cos(rad);
for (let h = 0; h < height; h++) {
for (let r = radius - thickness; r <= radius; r++) {
let dx = Math.round(r * cos);
let dz = Math.round(r * sin);
world.setBlock(x + dx, y + h, z + dz, id);
}
}
}
}
function detectSize(sx, sy, sz, dx, dy, dz) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
return {
width: w,
height: h,
length: l
};
}
function hollowCube(sx, sy, sz, dx, dy, dz, id) {
let w = Math.abs(dx - sx) + 1;
let h = Math.abs(dy - sy) + 1;
let l = Math.abs(dz - sz) + 1;
let startX = Math.min(sx, dx);
let startY = Math.min(sy, dy);
let startZ = Math.min(sz, dz);
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let z = 0; z < l; z++) {
if (x === 0 || x === w - 1 || y === 0 || y === h - 1 || z === 0 || z === l - 1) {
world.setBlock(startX + x, startY + y, startZ + z, id);
}
}
}
}
}
function undo(count) {
```Javascript
l>
A:
You can use the following code to get the value of the input field and then use it to set the value of the hidden field.
$(document).ready(function(){
$('#myInput').on('change', function(){
$('#myHiddenField').val($(
ript
function playSound(sound) {
var audio = new Audio(sound);
audio.play();
}
function playSound2(sound) {
var audio = new Audio(sound);
audio.play();
}
function playSound3(sound) {
var audio = new Audio(sound);
audio.play();
}
body {
background-color: #f2f2f2;
margin: 0;
padding: 0;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
#container {
width: 800px;
margin: 0 auto;
}
#header {
width: 100%;
height: 100px;
background-color: #333;
}
#content {
width: 100%;
height: 500px;
ript
function fill(n) {
var result = "";
for (var i = 0; i < n; i++) {
result += " ";
}
return result;
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function getRandomColor() {
var
ript
function line(x1, y1, z1, x2, y2, z2) {
var line = new THREE.Line3(new THREE.Vector3(x1, y1, z1), new THREE.Vector3(x2, y2, z2), new THREE.LineBasicMaterial({ color: 0xff0000 }));
scene.add(line);
}
// create