void turtle() { P5JSExtension.background(51); P5JSExtension.resetMatrix(); P5JSExtension.translate(P5JSExtension.width / 2, P5JSExtension.height); P5JSExtension.stroke(255); for (int i = 0; i < sentence.Length; i++) { var current = sentence[i]; if (current == 'F') { P5JSExtension.line(0, 0, 0, -len); P5JSExtension.translate(0, -len); } else if (current == '+') { P5JSExtension.rotate(angle); } else if (current == '-') { P5JSExtension.rotate(-angle); } else if (current == '[') { P5JSExtension.push(); } else if (current == ']') { P5JSExtension.pop(); } } }
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(); }
public Tree() { leaves = new List <Leaf>(); branches = new List <Branch>(); for (var i = 0; i < 1500; i++) { this.leaves.Add(new Leaf()); } pos = new Vector2(P5JSExtension.width / 2, P5JSExtension.height); dir = new Vector2(0, -1); root = new Branch(null, pos, dir); branches.Add(root); var current = root; var found = false; while (!found) { for (var i = 0; i < leaves.Count; i++) { var d = P5JSExtension.dist(current.pos, leaves[i].pos); if (d < Fractal_Trees_Space_Colonization.max_dist) { found = true; } } if (!found) { var branch = current.next(); current = branch; branches.Add(current); } } }
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 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 pickLocation() { int cols = P5JSExtension.floor(P5JSExtension.width / scl); int rows = P5JSExtension.floor(P5JSExtension.height / scl); food = new Vector2(P5JSExtension.random(0, cols), P5JSExtension.random(0, rows)); food.Scale(new Vector2(scl, scl)); }
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); }
public void show() { if (parent != null) { P5JSExtension.stroke(255); P5JSExtension.line(this.pos.x, this.pos.y, this.parent.pos.x, this.parent.pos.y); } }
public Star() { P5JSExtension.background(0); x = P5JSExtension.random(-P5JSExtension.width, P5JSExtension.width); y = P5JSExtension.random(-P5JSExtension.height, P5JSExtension.height); z = P5JSExtension.random(0, P5JSExtension.width); pz = z; }
void OnGUI() { P5JSExtension.resetMatrix(); P5JSExtension.background(51); angle = slider.value; P5JSExtension.stroke(255); P5JSExtension.translate(P5JSExtension.width / 2, P5JSExtension.height); branch(100); }
void OnGUI() { P5JSExtension.background(51); s.Show(); P5JSExtension.fill(255, 0, 100); P5JSExtension.rect(food.x, food.y, scl, scl); }
void OnGUI() { P5JSExtension.background(230, 230, 250); for (int i = 0; i < drops.Length; i++) { drops[i].fall(); drops[i].show(); } }
void OnGUI() { P5JSExtension.background(200); for (var i = 0; i < cells.Count; i++) { cells[i].move(); cells[i].show(); } }
public void Show() { P5JSExtension.fill(255); for (int i = 0; i < tail.Count; i++) { P5JSExtension.rect(tail[i].x, tail[i].y, TheSnakeGame.scl, TheSnakeGame.scl); } P5JSExtension.rect(x, y, TheSnakeGame.scl, TheSnakeGame.scl); }
void Start() { rules[0] = new Rule { a = "F", b = "FF+[+F-F-F]-[-F+F+F]" }; angle = P5JSExtension.radians(25); P5JSExtension.background(51); }
public void Update() { z = z - Starfield.speed; if (z < 1) { z = P5JSExtension.width; x = P5JSExtension.random(-P5JSExtension.width, P5JSExtension.width); y = P5JSExtension.random(-P5JSExtension.height, P5JSExtension.height); pz = z; } }
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 grow() { for (var i = 0; i < leaves.Count; i++) { var leaf = leaves[i]; Branch closestBranch = null; var record = Fractal_Trees_Space_Colonization.max_dist; for (var j = 0; j < branches.Count; j++) { var branch = branches[j]; var d = P5JSExtension.dist(leaf.pos, branch.pos); if (d < Fractal_Trees_Space_Colonization.min_dist) { leaf.reached = true; closestBranch = null; break; } else if (d < record) { closestBranch = branch; record = d; } } if (closestBranch != null) { var newDir = leaf.pos - closestBranch.pos; newDir.Normalize(); closestBranch.dir += newDir; closestBranch.count++; } } for (var i = leaves.Count - 1; i >= 0; i--) { if (leaves[i].reached) { leaves.RemoveAt(i); } } for (var i = branches.Count - 1; i >= 0; i--) { var branch = branches[i]; if (branch.count > 0) { branch.dir /= branch.count + 1; Vector3 rand = P5JSExtension.random3D(); rand.setMag(0.3f); branch.dir += rand; this.branches.Add(branch.next()); branch.reset(); } } }
public bool hits(Flower flower) { var d = P5JSExtension.dist(x, y, flower.x, flower.y); if (d < r + flower.r) { return(true); } else { return(false); } }
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 bool clicked(float x, float y) { var d = P5JSExtension.dist(pos.x, pos.y, x, y); if (d < r) { return(true); } else { return(false); } }
public bool eat(Vector2 pos) { float d = P5JSExtension.dist(x, y, pos.x, pos.y); if (d < 1) { total++; return(true); } else { return(false); } }
public void death() { for (int i = 0; i < tail.Count; i++) { Vector2 pos = tail[i]; var d = P5JSExtension.dist(x, y, pos.x, pos.y); if (d < 1) { Debug.Log("starting over"); total = 0; tail.Clear(); } } }
void OnGUI() { P5JSExtension.background(51); ship.show(); ship.move(); for (var i = 0; i < drops.Count; i++) { drops[i].show(); drops[i].move(); for (var j = 0; j < flowers.Count; j++) { if (drops[i].hits(flowers[j])) { flowers[j].grow(); drops[i].evaporate(); } } } var edge = false; for (var i = 0; i < flowers.Count; i++) { flowers[i].show(); flowers[i].move(); if (flowers[i].x > P5JSExtension.width || flowers[i].x < 0) { edge = true; } } if (edge) { for (var i = 0; i < flowers.Count; i++) { flowers[i].shiftDown(); } } for (var i = drops.Count - 1; i >= 0; i--) { if (drops[i].toDelete) { drops.RemoveAt(i); } } }
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); }
void branch(float len) { P5JSExtension.line(0, 0, 0, -len); P5JSExtension.translate(0, -len); if (len > 4) { P5JSExtension.push(); P5JSExtension.rotate(angle); branch(len * 0.67f); P5JSExtension.pop(); P5JSExtension.push(); P5JSExtension.rotate(-angle); branch(len * 0.67f); P5JSExtension.pop(); } }
void OnGUI() { P5JSExtension.resetMatrix(); P5JSExtension.background(51); for (int i = 0; i < tree.Count; i++) { tree[i].show(); //tree[i].jitter(); } for (var i = 0; i < leaves.Count; i++) { P5JSExtension.fill(255, 0, 100, 100); P5JSExtension.noStroke(); //cause error for somereason P5JSExtension.ellipse(leaves[i].x, leaves[i].y, 8, 8); leaves[i].y += P5JSExtension.random(0, 2); } }
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); }