# Tixy, a way to get better at PB

**URL:** <https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735>\
**Category:** Patterns and Code\
**Created:** [November 12, 2020, 11:22pm UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735 "2020-11-12T23:22:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [November 12, 2020, 11:22pm UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/1 "2020-11-12T23:22:53Z")

</div>

> **[r/FastLED - Play tixy.land templates on your matrices](https://www.reddit.com/r/FastLED/comments/jsrrgd/play_tixyland_templates_on_your_matrices)**
>
> 2 votes and 2 comments so far on Reddit

I suspect a Tixy function is mostly trivial for PB.  
The 0-15 values need to be adjusted for the 0…1 values of PB, T will be adjusted perhaps, and negative values going red (or whatever).

But it’s neat and for newbies who don’t quite grasp how math patterns can be used, this is a good starting point, with just one line to understand.

---

<div class="post-metadata">

**Author:** ![wizard](https://forum.electromage.com/user_avatar/forum.electromage.com/wizard/32/4_2.png) [@wizard](https://forum.electromage.com/u/wizard)\
**Post date:** [November 13, 2020, 12:21am UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/2 "2020-11-13T00:21:33Z")

</div>

For sure!

These are some other minimalist graphical math heavy systems that were inspiration for PB:

[http://maxbittker.github.io/Mojulo](http://maxbittker.github.io/Mojulo)

[https://www.dwitter.net/](https://www.dwitter.net/)

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [December 3, 2020, 1:24pm UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/3 "2020-12-03T13:24:08Z")

</div>

Some more Tixy (and other math/graphic) links.  
If nobody beats me to it, I’ll have to do a Tixy pattern for PB. [So many good patterns](https://tixy.land/gallery/) including [Mandelbrot](https://tixy.land/?code=x%3D%283.5*x%2F16-2.5%29%2Ft%2B.42884%2Cy%3D%282*y%2F16-1%29%2Ft-.231345%2Cm%3D10*t%7C0%2Cit%3D%28p%2Cq%2Cj%29%3D%3E%28p*p%2Bq*q%3C%3D4%26%26j%3Cm%3Fit%28p*p-q*q%2Bx%2C2*p*q%2By%2Cj%2B1%29%3Aj%29%2C2*it%280%2C0%2C0%29%2Fm-1) zooms, [Conway Life](https://tixy.land/?code=%27a%27in+this%3F255+in+a%5B0%5D%3F%28p%3Dt*4%261%2Cs%3Df%28i%2B239%29%2Bf%28i%2B240%29%2Bf%28i%2B241%29%2Bf%28i%2B255%29%2Bf%28i%2B1%29%2Bf%28i%2B15%29%2Bf%28i%2B16%29%2Bf%28i%2B17%29%2Ca%5B1-p%5D%5Bi%5D%3Ds%3D%3D3%3F1%3As%3D%3D2%3Fa%5Bp%5D%5Bi%5D%3A0%29%3Aa%5B0%5D.push%28random%28%29%3E.5%29%3A%28a%3D%5B%5B%5D%2CArray%28256%29%5D%2Cf%3D%28i%29%3D%3Ea%5Bp%5D%5Bi%25256%5D%29), [text scrollers](https://tixy.land/?code=dx%3D10*t%2Cdy%3Dsin%28x%2F3%29%2Ck%3D.5%2Cfx%3D%28a%3D%3Efloor%28k*a%2Bdx%29%2564%29%2Cfy%3D%28a%3D%3Efloor%28k*a%2B9.5%2Fk%2Bdy%29%2520%29%2Ca%3D%5B%2200000000%22%2C%22e0020000%22%2C%224aaa0aaa%22%2C%2249280000%22%2C%224a920000%22%2C%2200100000%22%5D%2Cb%3D%28%28f%2Cr%29%3D%3EparseInt%28%28a%5Bfy%28r%29%5D%7C%7C%5B%5D%29%5Bfx%28f%29%3E%3E2%5D%7C%7C%220%22%2C16%29%268%3E%3Efx%28f%29%254%3F1%3A0%29%2Cc%3D%28%28a%2Cf%29%3D%3E%7Bv%3D0%2Csum%3D0%3Bfor%28let+r%3D-2%3Br%3C%3D2%3Br%2B%2B%29for%28let+x%3D-2%3Bx%3C%3D2%3Bx%2B%2B%29%7Blet+o%3D1%2F%281%2B%28r*r%2Bx*x%29**6%29%3Bsum%2B%3Do%2Cv%2B%3Db%28a%2Bx%2Cf%2Br%29*o%7Dreturn+v%2F%3Dsum%2Cv%3C%3D.1%26%26%28v%3D-abs%28.2*random%28%29%2B.4*sin%28%28a%2Bdx%29%2F5%29%29%29%2Cv%7D%29%2Ca%2Cc%28x%2Cy%29), [fire](http://maettig.com/code/canvas/tixy.land-fire.html), and more. Considering how small most are (one line of JavaScript), you could easily pack dozens into a single PB pattern.

Tixy related:

Twitter search, cause so many good patterns  
[https://mobile.twitter.com/search?q=Tixy.land](https://mobile.twitter.com/search?q=Tixy.land)

3d:

> **[(t,i,x,y,z) =\> "creative code golfing"](https://doersino.github.io/tixyz/)**
>
> A minimalist three-dimensional coding environment. Control 8x8x8 dots with a single JavaScript function. By @doersino, based on tixy by @aemkei.

  

> **[Tixy3d](https://fxi.gitlab.io/tixy3d/)**

Hidef:

> **[tixy.land high-resolution renderer](http://maettig.com/code/canvas/tixy.land-hd.html)**

Non-tixy:

> **[brubsby/cozyvec](https://github.com/brubsby/cozyvec)**
>
> Cozy Plotter Art Terminal. Contribute to brubsby/cozyvec development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [December 6, 2020, 8:21pm UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/4 "2020-12-06T20:21:25Z")

</div>

So I got a basic Tixy clone working despite a storm related power outage at home. I grabbed the new 16x16 matrix, a PB, 10a power supply, and my laptop and went to my in-laws (much warmer). I adjust the white to be bluish, but that’s just a setting anyway. Some examples needed hypot(), but that’s an easy function to add. A few used arrays, and I’ll have to play with those more. I also need to add a gamma correction to make the low levels of light easier to notice.

I’ll post it tomorrow, if I get power back. It’ll work on smaller matrixes too since the map just works as expected.

Taking a break, then I’m going to add a full color mode, so instead of white for any positive value and red for negative values where size of the value is used as brightness, I’ll use the value as the hue.

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [December 8, 2020, 8:34pm UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/5 "2020-12-08T20:34:32Z")

</div>

I’ve just uploaded to the electromage pattern repo an alpha of my Tixy pattern. It’s functional but I’ll be adding more formulas (there are only 60 now…) to it, as well as bug fixes and more comments, etc. It’ll also be on GitHub. New formulas welcomed gladly. Documentation for how tixy.land works in the first handful of formulas in the commented code. (Or visit tixy.land itself, same documented walk thru there, slightly different order of later examples)

And of course as soon as I pull the trigger, I see bugs to fix. It starts on pattern 15, cycles every 3 seconds (should be longer or adjustable), and won’t start over once it hits 60. Oops.

I was debugging the Mondrian pattern. @wizard, I am correct that that’s a math overflow causing the corners to not be solid? (Also appears on moving cross formula, similarly). It’s multiplying two small numbers, I wouldn’t think it was too big but…

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [December 8, 2020, 9:07pm UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/6 "2020-12-08T21:07:47Z")

</div>

Just downloaded and played with this. It looks good, and shows a bunch of really cool things you can do with just a little math. Nice!!

(and yeah, could use a `pattern = pattern % numPatterns` or something like that in there – I got hypnotized watching the whole thing, so was actually kind of glad it didn’t start over that first time…)

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [December 8, 2020, 9:19pm UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/7 "2020-12-08T21:19:40Z")

</div>

Yeah, exactly, I meant to add that before upload but…  
and will probably add a “greatest hits option” that only cycles thru a select group (array of which ones) so you can pick and choose your favorites, and just get those cycling. Given that I expect easily over 100 patterns

I’m enjoying the challenge of porting some, due to PBs limited language that isn’t 100% JavaScript complete, for example, no on the fly arrays, no .map, limited assignments, etc. I want to get the mandelbrot, life, space invader, and some others working, plus every day I see a few new ones.

I’ll be making a demo video for this, I think, once I’m happy with the basics.

I also plan on adding R/Polar support, for more “swirly” patterns. (Thrixy ? Adding Th+R). And I still need to build my 3D and add 3D support.

---

<div class="post-metadata">

**Author:** ![wizard](https://forum.electromage.com/user_avatar/forum.electromage.com/wizard/32/4_2.png) [@wizard](https://forum.electromage.com/u/wizard)\
**Post date:** [December 8, 2020, 10:07pm UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/8 "2020-12-08T22:07:30Z")

</div>

@Scruffynerf,  
Neat! Fun!

If you are looking for an accurate replica, I tweaked the render function to more [closely match tixy’s](https://github.com/aemkei/tixy/blob/0e852b65eda5b6da43fc5f54685cfb176119403f/src/index.js#L102) for mono mode.

```auto
export function render2D(index,xo,yo) {
  x = floor(xo * 16)
  y = floor(yo * 16)
  result = tixy[pattern](t1,index,x,y);
  if (MonoOrColor) { //Color
    h = result * ColorShift;
    v = abs(result) + BrightShift
    hsv(h,1,v)
  } else { // Mono
    if (result < 0) {
      result = -result
      h = Negative
    } else {
      h = Positive
    }
  
    v = clamp(result , 0, 1) //clamp to range
    hsv(h,1,v*v)
  }
}

```

They take the result and scale it up to a radius, clamping to max size. The result’s already in an appropriate scale in our case, but should still clamp before squaring to avoid overflows. I square for better detail at the low end, instead of cube it.

In some places, tixy uses sneaky side effects to reduce character count. This is a good example in moving cross:

```auto
(y-4*t|0) * (x-2-t|0)

```

The bitwise or `|` happens last, and in JavaScript implicitly converts the number to a 32 bit signed integer. In Pixelblaze, this doesn’t happen and you get a bitwise or across the whole number.

For positive numbers, `floor` does the same thing, but it makes negative numbers more negative, unlike bitwise OR with 0. You can’t just logical AND away the fractional bits on a fixed point negative number either (removing them makes negative numbers more negative, two’s compliment and all that).

This can do the trick:

```auto
function toInt(v) {
  return v - (v % 1)
}

```

Applying this to the moving cross pattern:

```auto
toInt(y-4*t) * toInt(x-2-t) 

```

Gives similar results to tixy (2 pixel wide bars).

* * *

BTW, Pixelblaze supports the same lambda expressions as JS / tixy.

```auto
tixy[10] = (t,i,x,y) => { return y - x }; // simple triangle

```

Can be written like this as well

```auto
tixy[10] = (t,i,x,y) => y - x // simple triangle

```

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [December 8, 2020, 10:17pm UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/9 "2020-12-08T22:17:38Z")

</div>

Oh excellent, so I can clean up a lot of code. Thanks.

Thanks for clarifying lots of small bits about how PB as a language/parser works!

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [December 9, 2020, 1:24am UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/10 "2020-12-09T01:24:05Z")

</div>

It looks like even in PB, double tilde does the same as your toInt… Yes? (I haven’t tested it fully but I see a case where it looks like it is)

Two NOT bitwise operators in a row?

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [December 9, 2020, 2:14am UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/11 "2020-12-09T02:14:32Z")

</div>

I just played with this a bit… I don’t have an easy way to see bit values for the .16 portion, so I can’t see exactly what’s going on, but it looks like ~ only preserves the integer portion.

So you can use that trick to ditch the fractional part on positive numbers, but it doesn’t work quite the same way on negatives. It makes them more negative. For example, ~~1.234 returns 1,~~ -1.234 returns -2.

If you can live with this, it’s faster than a function call. Though unless I was seriously hurting for fps and it was in a critical inner loop, I’d try never ever to do this in production code. Too likely to be misread later, or to break if somebody ever accidentally “fixed” the interpreter.

@wizard, I was going to ask at some point, but this seems like a good time: Can you consider giving us nice fast whole() and frac() functions to do these jobs?

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [December 9, 2020, 2:42am UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/12 "2020-12-09T02:42:12Z")

</div>

Interesting, cause this says ~~ shouldn’t do that

> <https://stackoverflow.com/questions/5971645/what-is-the-double-tilde-operator-in-javascript>

I mean it’s not JavaScript, so if it’s equal to floor on PB, that’s fine. I just was curious. If it’s not the same as in JavaScript, worth documenting.

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [December 9, 2020, 7:03pm UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/13 "2020-12-09T19:03:29Z")

</div>

@wizard got another PB logic operator question:

[x-=8,y-=8,f=(k)=\>hypot(x_cos(t+k)+y_sin(t+k),x_sin(t+k)/2-y_cos(t+k)/2)/4\<1,f(0)^f(-1.05)^f(1.05)](https://tixy.land/?code=x-%3D8%2Cy-%3D8%2Cf%3D%28k%29%3D%3Ehypot%28x*cos%28t%2Bk%29%2By*sin%28t%2Bk%29%2Cx*sin%28t%2Bk%29%2F2-y*cos%28t%2Bk%29%2F2%29%2F4%3C1%2Cf%280%29%5Ef%28-1.05%29%5Ef%281.05%29)

even after some rewriting, I realized the issue is the end:  
a^b^c  
that’s using ^ as XOR, but I think it’s doing exponent on PB, since I’ve been using that elsewhere…  
so what is the bitwise XOR operator on PB?

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [May 6, 2021, 4:36am UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/14 "2021-05-06T04:36:51Z")

</div>

3D Tixy… Meaning a 3D map on PB could do this…

[![](https://img.youtube.com/vi/ywseUMpg6IY/maxresdefault.jpg "ZYXIT demo reel") ](https://www.youtube.com/watch?v=ywseUMpg6IY)

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [May 6, 2021, 5:01am UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/15 "2021-05-06T05:01:26Z")

</div>

And a free resource for 2D and 3D math before I forget it:

[https://gamemath.com](https://gamemath.com)

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [May 7, 2021, 3:44am UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/16 "2021-05-07T03:44:12Z")

</div>

pretty sure ^ is XOR on PB – we used a lot of it when messing around with the XORShift PRNG back in a couple of the early exercises.

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [May 7, 2021, 9:22am UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/17 "2021-05-07T09:22:34Z")

</div>

I’ll have to play with that one again. I have a handful of tixy lines to port over collected and should scour the net for newer ones too. Time for TixyPB 2.0.

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [May 13, 2021, 2:44pm UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/18 "2021-05-13T14:44:08Z")

</div>

So the guy behind [G’MIC](https://gmic.eu/) added tixy support to gmic  
And then he did it one [better](https://discuss.pixls.us/t/discovering-tixy-land/21175/3), he added a Z that is a complex number represented by x+iy (that i is the squareroot of -1, not pixel index, so really he used j for clarity)

[![](https://img.youtube.com/vi/KX3DSDHzlPM/hqdefault.jpg "Extension of tixy.land to complex-valued expressions") ](https://www.youtube.com/watch?v=KX3DSDHzlPM)

In this case he’s using Z this way:

If you have a complex number, x+iy, it can also be expressed by a polar conversion, which yields a radius and angle. The radius is used to define the size of the circle (which for PB purposes is akin to brightness) and the angle is used to define color by hue.

This is brilliant and I really want to add this to my tixy Port. But of course that means adding complex number support to do it right.

Coming soonish hopefully.

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [May 13, 2021, 10:33pm UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/19 "2021-05-13T22:33:32Z")

</div>

well, hot damn, I’m 90% done with the core of the port of complex.js to PB, still testing, but I’ve got some nice patterns already, just testing my complex functions.

[Now posted here](https://forum.electromage.com/t/complex-numbers/1236)

This is a game changer, I think. I’m limiting it to a fixed 2 element array (real, and imaginary), to keep it within PB language limits.

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [May 14, 2021, 11:21am UTC](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735/20 "2021-05-14T11:21:44Z")

</div>

one gotcha I found in porting this, recording so others might find it helpful:

if you try to use ===, you get an error  
“Cannot read property ‘stack’ of undefined”

No pointer to where the error is, it’s just a blocker, can’t save the pattern, etc.  
Search for ===, and replace with == (which should work most of the time)

[Next page](https://forum.electromage.com/t/tixy-a-way-to-get-better-at-pb/735.md?page=2)
