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 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(); }
public void show() { float thick = P5JSExtension.map(z, 0, 20, 1, 3); P5JSExtension.strokeWeight(thick); P5JSExtension.stroke(138, 43, 226); P5JSExtension.line(x, y, x, y + len); }
void OnGUI() { int maxiterations = 100; for (var x = 0; x < texture.width; x++) { for (var y = 0; y < texture.height; y++) { var a = P5JSExtension.map(x, 0, P5JSExtension.width, -2, 2); var b = P5JSExtension.map(y, 0, P5JSExtension.height, -2, 2); //var ca = P5JSExtension.map(Input.mousePosition.x, 0, P5JSExtension.width,-1,1); //var cb = P5JSExtension.map(Input.mousePosition.y, 0, P5JSExtension.height, -1, 1); float ca = Mathf.Cos(angle * 0.03213f * Mathf.Deg2Rad); float cb = Mathf.Sin(angle * Mathf.Deg2Rad); angle += 0.0002f; var n = 0; while (n < maxiterations) { var aa = a * a; var bb = b * b; if (a * a + b * b > 4) { break; } float twoab = 2 * a * b; a = aa - bb + ca; b = twoab + cb; n++; } if (n == maxiterations) { texture.SetPixel(x, y, Color.black); } else { var hu = P5JSExtension.map(n, 0, maxiterations, 0, 1); hu = P5JSExtension.map(Mathf.Sqrt(hu), 0, 1, 0, 255); texture.SetPixel(x, y, Color.HSVToRGB(hu / 255f, 255 / 255f, 150 / 255f)); } } } texture.Apply(); if (Event.current.type.Equals(EventType.Repaint)) { Graphics.DrawTexture(new Rect(0, 0, texture.width, texture.height), texture); } }
void OnGUI() { speed = P5JSExtension.map(Input.mousePosition.x, 0, P5JSExtension.width, 0, 20); P5JSExtension.background(0); for (int i = 0; i < 800; i++) { stars[i].Update(); stars[i].Show(); } }
public void fall() { y = y + yspeed; float grav = P5JSExtension.map(z, 0, 20, 0, 0.2f); yspeed = yspeed + 0.2f + grav; if (y > P5JSExtension.height) { y = P5JSExtension.random(-200, -100); yspeed = P5JSExtension.random(4, 10); } }
public void Show() { float sx = P5JSExtension.map(x / z, 0, 1, 0, P5JSExtension.width); float sy = P5JSExtension.map(y / z, 0, 1, 0, P5JSExtension.height); float r = P5JSExtension.map(z, 0, P5JSExtension.width, 16, 0); //translate canvas sx += P5JSExtension.width / 2; sy += P5JSExtension.height / 2; P5JSExtension.ellipse(sx, sy, r, r); float px = P5JSExtension.map(x / pz, 0, 1, 0, P5JSExtension.width); float py = P5JSExtension.map(y / pz, 0, 1, 0, P5JSExtension.height); pz = z; //translate canvas px += P5JSExtension.width / 2; py += P5JSExtension.height / 2; P5JSExtension.line(px, py, sx, sy); }
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(); }
public Drop() { len = P5JSExtension.map(z, 0, 20, 10, 20); yspeed = P5JSExtension.map(z, 0, 20, 1, 20); }