# My projects library #2! - CodeMasterX's gallery megathread

**URL:** <https://discourse.processing.org/t/my-projects-library-2-codemasterxs-gallery-megathread/27161>\
**Category:** Gallery\
**Created:** [January 18, 2021, 4:06pm UTC](https://discourse.processing.org/t/my-projects-library-2-codemasterxs-gallery-megathread/27161 "2021-01-18T16:06:00Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [March 8, 2021, 4:29pm UTC](https://discourse.processing.org/t/my-projects-library-2-codemasterxs-gallery-megathread/27161/21 "2021-03-08T16:29:51Z")

</div>

**#34 Triangular spiral** Java mode

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/49074c757ecba4c9010ade70480ad3686e52ad07.png) ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/eb587b9f00fc9e12009d89b5114e4ed8460dc191.png)  
My 10th attempt at this.

> **Code**
>
> ```auto
> ArrayList<tri> tris = new ArrayList<tri>();
> float lrp = 0.6;
> void setup() {
> size(600,600);
> tris.add(new tri(100,500,300,500));
> }
> void draw() {
> background(0);
> for(int i = 0; i < tris.size(); i++) tris.get(i).show();
> }
> 
> class tri {
> float x1,y1,x2,y2,x3,y3,x4,y4;
> boolean last=true;
> tri(float x1_, float y1_, float x2_, float y2_) {
> x1 = x1_; y1 = y1_; x2 = x2_; y2 = y2_;
> float dir = atan2(y2-y1,x2-x1)-PI/2, r = dist(x1,y1,x2,y2);
> x3 = x1 + cos(dir)*r;
> y3 = y1 + sin(dir)*r;
> x4 = lerp(x3,x2,lrp);
> y4 = lerp(y3,y2,lrp);
> }
> void show() {
> display(x1,y1,x2,y2);
> }
> void dupe() {
> if(last) tris.add(new tri(x3,y3,x4,y4));
> last=false;
> }
> }
> void keyPressed() { if(key == ' ') for(int i = 0, m = tris.size(); i < m; i++) tris.get(i).dupe(); }
> void display(float x1, float y1, float x2, float y2) {
> float dir = atan2(y2-y1,x2-x1)-PI/2, r = dist(x1,y1,x2,y2);
> float x3 = x1 + cos(dir)*r,y3 = y1 + sin(dir)*r;
> triangle(x1,y1,x2,y2,x3,y3);
> }
> 
> ```

**#34.5 Triangular spiral - interactive** Java mode

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/4c22675221849e294d331f946fb461ed6c4e6afc.png)  
version 2 - interactive. You can draw the first rectangle. You can also set the lrp variable mid game

> **Version 2**
>
> ```auto
> float lrp = 0.55, iter = 15;
> float sx = -1, sy=-1, ex=-1, ey=-1;
> boolean done = false, started = false, outOfBounds = false;
> void setup() {
> size(600, 650);
> textAlign(3,3);
> }
> void draw() {
> background(0);
> if (done) display(sx, sy, ex, ey, iter);
> else if (started) display(sx, sy, mouseX, mouseY, iter);
> rect(0, 600, width, 50);
> fill(0);
> text(lrp,map(lrp,0,1,0,width),625);
> if(mousePressed && mouseY > 600) lrp = map(mouseX,0,width,0,1);
> fill(255); 
> }
> void mousePressed() {
> if (mouseY < 600) {
> sx=mouseX;
> sy=mouseY;
> done=false;
> started = true;
> outOfBounds = false;
> } else outOfBounds = true;
> }
> void mouseReleased() {
> if (!outOfBounds) {
> ex=mouseX;
> ey=mouseY;
> done=true;
> }
> }
> void display(float x1, float y1, float x2, float y2, float it) {
> float dir = atan2(y2-y1, x2-x1)-PI/2, r = dist(x1, y1, x2, y2);
> float x3 = x1 + cos(dir)*r, y3 = y1 + sin(dir)*r;
> triangle(x1, y1, x2, y2, x3, y3);
> float x4 = lerp(x3, x2, lrp);
> float y4 = lerp(y3, y2, lrp);
> if (it > 0) display(x3, y3, x4, y4, it-1);
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [May 12, 2021, 9:47am UTC](https://discourse.processing.org/t/my-projects-library-2-codemasterxs-gallery-megathread/27161/22 "2021-05-12T09:47:20Z")

</div>

This is the third library  
[Project Library #3](https://discourse.processing.org/t/my-projects-library-3-gallery-megathread/29696)

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [July 7, 2021, 11:54am UTC](https://discourse.processing.org/t/my-projects-library-2-codemasterxs-gallery-megathread/27161/23 "2021-07-07T11:54:40Z")

</div>

Fourth library is out!  
[Project library #4](https://discourse.processing.org/t/my-projects-library-4-gallery-megathread/31103)

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [November 19, 2021, 5:05pm UTC](https://discourse.processing.org/t/my-projects-library-2-codemasterxs-gallery-megathread/27161/24 "2021-11-19T17:05:31Z")

</div>

Fifth library is here!  
[Project library #5](https://discourse.processing.org/t/my-project-library-5-gallery-megathread/33623)

[Previous page](https://discourse.processing.org/t/my-projects-library-2-codemasterxs-gallery-megathread/27161.md?page=1)
