Skip to content

Instantly share code, notes, and snippets.

@GoSubRoutine
Last active September 7, 2022 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GoSubRoutine/0e87585b329421c24451cb42260ec311 to your computer and use it in GitHub Desktop.
Save GoSubRoutine/0e87585b329421c24451cb42260ec311 to your computer and use it in GitHub Desktop.
Trig Pixel Colors
height: 600
scrolling: no
border: yes
license: cc-by-4.0
/**
* Trig Pixel Colors (v1.0.5) [JS/p5js] (Char Code Challenge)
* by Sunt (2022/Sep/03)
* mod GoToLoop (2022/Sep/04)
*
* https://Bl.ocks.org/GoSubRoutine/0e87585b329421c24451cb42260ec311
*
* https://Discourse.Processing.org/t/pixels-array-p5-js-vs-java/38623/8
* https://OpenProcessing.org/sketch/1637961
*/
<script async src=https://cdn.JsDelivr.net/npm/p5></script>
<script defer src=sketch.js></script>
R=42,G=84,B=128,V=600,S=32
I=Int32Array,A=new I(V*V),K=new I(B),f=0
setup=_=>{createCanvas(V,V)
pixelDensity(1).loadPixels(s=sin)
p=new I(pixels.buffer)
for(y=0;y<V;++y)for(x=0;x<V;)A[V*y+x]=B/4*(s(x/S)+cos(y/S)+s(sqrt(x*x+++y*y)/S))
for(i=0;i<B;)u=B*s(.12*i),
K[i]=color(R+u,G+B*s(PI/50*i+++.79),B+u).levels.reduce((a,v,i)=>v<<i*8|a,0)}
draw=_=>{++f
for(i=0;i<V*V;)p[i]=K[f+A[i++]&B-1]
updatePixels()}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment