-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trigonometric sinusoidal strings changing colour across the screen.
- Loading branch information
1 parent
c93f156
commit a248d63
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
let t = 0; | ||
|
||
function make_eq() { | ||
const elements = ["Math.sin(i)","Math.cos(i)"]; | ||
const symbols = [" + ", " - "]; | ||
let eq = ""; | ||
for (let i = 0; i < 1+parseInt(Math.random()*3); i++) { | ||
let tr = "(i/" + (1+parseInt(Math.random()*3)) + ")"; | ||
eq += elements[parseInt(Math.random()*elements.length)].replace("(i)",tr); | ||
eq += symbols[parseInt(Math.random()*symbols.length)]; | ||
} | ||
return eq.substring(0,eq.length-3); | ||
} | ||
|
||
let eqx = make_eq(); | ||
let eqy = make_eq(); | ||
|
||
return class TheStrings { | ||
constructor(display) { | ||
this.display = display; | ||
|
||
this.#clear(); | ||
} | ||
|
||
#clear() { | ||
this.display.flush(); | ||
} | ||
|
||
dist(a,b) { | ||
return (((this.display.width/2)-a)**2 + ((this.display.height/2)-b)**2); | ||
} | ||
|
||
update() { | ||
t+=0.1; | ||
let length = 3; | ||
for (let i = t; i < t+length; i+=0.005) { | ||
let tx = (this.display.width /2)+(parseInt(eval(eqx)*(this.display.width )/4)); | ||
let ty = (this.display.height/2)+(parseInt(eval(eqy)*(this.display.height)/4)); | ||
if (tx > 0 && tx < this.display.width && ty > 0 && ty < this.display.width) { | ||
let val = ((i/10)*255)%(255*2); | ||
if (val > 255) { | ||
val = 255-(val-255); | ||
} | ||
let val2 = ((i/15)*255)%(255*2); | ||
if (val2 > 255) { | ||
val2 = 255-(val2-255); | ||
} | ||
this.display.setPixel(tx, ty, [val,val2,255-val]); | ||
} | ||
} | ||
this.display.flush(); | ||
} | ||
} |