void Update() { flying -= 0.1f; float yoff = flying; for (int y = 0; y < rows; y++) { float xoff = 0; for (int x = 0; x < cols; x++) { terrain[x][y] = P5JSExtension.map(P5JSExtension.noise(xoff, yoff), 0, 1, -100, 100); xoff += 0.2f; } yoff += 0.2f; } gameObject.transform.position = new Vector3(-w / 2, -h / 2 + 50, 0); gameObject.transform.rotation = Quaternion.Euler(180 / 3, 0, 0); for (int y = 0; y < rows - 1; y++) { P5JSExtension.beginShape(MeshTopology.LineStrip); for (int x = 0; x < cols; x++) { P5JSExtension.vertex(x * scl, y * scl, terrain[x][y]); P5JSExtension.vertex(x * scl, (y + 1) * scl, terrain[x][y + 1]); } } gameObject.GetComponent <MeshFilter>().mesh = P5JSExtension.endShape(); }
void Update() { //Note not using background clear float dt = 0.01f; float dx = (a * (y - x)) * dt; float dy = (x * (b - z) - y) * dt; float dz = (x * y - c * z) * dt; x = x + dx; y = y + dy; z = z + dz; points.Add(new Vector3(x, y, z)); //Note Could not add Hue change overtime, P5JSExtension.beginShape(MeshTopology.LineStrip); foreach (Vector3 v in points) { Vector3 offset = P5JSExtension.random3D(); offset *= 0.1f; Vector3 a = v + offset; P5JSExtension.vertex(a.x, a.y, a.z); } gameObject.GetComponent <MeshFilter>().mesh = P5JSExtension.endShape(); }
void OnGUI() { //P5JSExtension.background(0); float r = 200; for (int i = 0; i < total + 1; i++) { float lat = P5JSExtension.map(i, 0, total, 0, Mathf.PI); for (int j = 0; j < total + 1; j++) { float lon = P5JSExtension.map(j, 0, total, 0, 2 * Mathf.PI); float x = r * Mathf.Sin(lat) * Mathf.Cos(lon); float y = r * Mathf.Sin(lat) * Mathf.Sin(lon); float z = r * Mathf.Cos(lat); globe[i][j] = new Vector3(x, y, z); } } P5JSExtension.beginShape(MeshTopology.Triangles); for (int i = 0; i < total; i++) { for (int j = 0; j < total + 1; j++) { Vector3 v1 = globe[i][j]; P5JSExtension.vertex(v1.x, v1.y, v1.z); Vector3 v2 = globe[i + 1][j]; P5JSExtension.vertex(v2.x, v2.y, v2.z); } } gameObject.GetComponent <MeshFilter>().mesh = P5JSExtension.endShape(); }
void OnGUI() { var a = 100; var b = 100; var n = slider.value; P5JSExtension.beginShape(MeshTopology.LineStrip); for (float angle = 0; angle < 2 * Mathf.PI; angle += 0.1f) { var na = 2 / n; var x = Mathf.Pow(Mathf.Abs(Mathf.Cos(angle)), na) * a * sgn(Mathf.Cos(angle)); var y = Mathf.Pow(Mathf.Abs(Mathf.Sin(angle)), na) * b * sgn(Mathf.Sin(angle)); P5JSExtension.vertex(x, y); } gameObject.GetComponent <MeshFilter>().mesh = P5JSExtension.endShape(P5JSExtension.CLOSED); }
public void show() { for (var i = 0; i < leaves.Count; i++) { //leaves[i].show(); } P5JSExtension.beginShape(MeshTopology.Lines); for (var i = 0; i < branches.Count; i++) { Branch b = branches[i]; if (b.parent != null) { P5JSExtension.vertex(b.pos.x, b.pos.y, b.pos.z); P5JSExtension.vertex(b.parent.pos.x, b.parent.pos.y, b.parent.pos.z); } } meshfilter.mesh = P5JSExtension.endShape(); }
void OnGUI() { m = slider.value; P5JSExtension.background(51); var radius = 100; var total = 100; var increment = (2 * Mathf.PI) / total; P5JSExtension.beginShape(MeshTopology.LineStrip); for (float angle = 0; angle < 2 * Mathf.PI; angle += increment) { var r = supershape(angle); var x = radius * r * Mathf.Cos(angle); var y = radius * r * Mathf.Sin(angle); P5JSExtension.vertex(x, y); } gameObject.GetComponent <MeshFilter>().mesh = P5JSExtension.endShape(P5JSExtension.CLOSED); }
void OnGUI() { m = P5JSExtension.map(Mathf.Sin(mchange), -1, 1, 0, 7); mchange += 0.02f; //P5JSExtension.background(0); float r = 200; for (int i = 0; i < total + 1; i++) { float lat = P5JSExtension.map(i, 0, total, -Mathf.PI / 2, Mathf.PI / 2); float r2 = supershape(lat, m, 0.2f, 1.7f, 1.7f); for (int j = 0; j < total + 1; j++) { float lon = P5JSExtension.map(j, 0, total, -Mathf.PI, Mathf.PI); float r1 = supershape(lon, m, 0.2f, 1.7f, 1.7f); float x = r * r1 * Mathf.Cos(lon) * r2 * Mathf.Cos(lat); float y = r * r1 * Mathf.Sin(lon) * r2 * Mathf.Cos(lat); float z = r * r2 * Mathf.Sin(lat); globe[i][j] = new Vector3(x, y, z); } } P5JSExtension.beginShape(MeshTopology.Triangles); for (int i = 0; i < total; i++) { for (int j = 0; j < total + 1; j++) { Vector3 v1 = globe[i][j]; P5JSExtension.vertex(v1.x, v1.y, v1.z); Vector3 v2 = globe[i + 1][j]; P5JSExtension.vertex(v2.x, v2.y, v2.z); } } gameObject.GetComponent <MeshFilter>().mesh = P5JSExtension.endShape(); }