Q. Generating 2D "waves" (but let's start with a checkerboard)

25 views
Skip to first unread message

Oertl

unread,
Feb 16, 2018, 6:54:34 PM2/16/18
to MathMap
Hi, all,

I'm interested in creating 2D patterns by, somehow, defining an "intensity" function of the xy location of pixels on the screen.

From the demo and a little reading, I bumbled up this attachment, among others:
  grayColor(0.5+0.5*sin(scale(x,-W/2,W/2,0,7*pi))*cos(scale(y,-H/2,H/2,0,pi*7)))
which, I think, does create the semblance of sinusoidal variation along the x direction being modulated by a similar behavior along the y.

I'm having a hard time wrapping my head around how MathMap works, particularly inasmuch as it appears that it generated an entire screen-full of output with a single line of code: no looping through x,y.

To address this, I decided to back up and try to start with something straightforward, a checkerboard. I had come across the inintv() function in a polar application and figured it would likely help paint appropriate squares.

However, I quickly was hoist upon my own petard when I realized that the only approach I could come up with was "looping" which I had already decided MathMap doesn't rely upon.

My general question is: how can I(x, y) be implemented in a general form?

And specifically, have you any suggestions for how to approach the checkerboard problem?

My bones tell me both can be done, but they ain't brains.

Thank you.
Mathematically-computed2Dwaves_attempt.png

Tom Rathborne

unread,
Mar 30, 2018, 10:14:22 AM3/30/18
to mat...@googlegroups.com
Hi Oertl,

On Wed, Feb 14, 2018 at 06:08:32AM -0800, Oertl wrote:
> I'm interested in creating 2D patterns by, somehow, defining an "intensity"
> function of the xy location of pixels on the screen.
>
> From the demo and a little reading, I bumbled up this attachment, among
> others:
>   grayColor(0.5+0.5*sin(scale(x,-W/2,W/2,0,7*pi))*cos(scale(y,-H/2,H/2,0,pi*7
> )))
> which, I think, does create the semblance of sinusoidal variation along the x
> direction being modulated by a similar behavior along the y.
>
> I'm having a hard time wrapping my head around how MathMap works,
> particularly inasmuch as it appears that it generated an entire
> screen-full of output with a single line of code: no looping through
> x,y.

Right, MathMap does the looping for you. The expression is evaluated
for each pixel with (x,y) set.

> To address this, I decided to back up and try to start with
> something straightforward, a checkerboard. I had come across the
> inintv() function in a polar application and figured it would likely
> help paint appropriate squares.
>
> However, I quickly was hoist upon my own petard when I realized that
> the only approach I could come up with was "looping" which I had
> already decided MathMap doesn't rely upon.
>
> My general question is: how can I(x, y) be implemented in a general
> form?
>
> And specifically, have you any suggestions for how to approach the
> checkerboard problem?

Below is a simple checkerboard (probably not a winner in MathMap golf,
but made to help you get your head around it!)

For free, you get various constants like x,y and X,Y. x and y are the
current pixel coordinates and X and Y are constants, the maximum x
andy values in the image (so the top right I guess).

In a square image, X and Y go from -1 to 1. So to map the (-1,-1) to
(1,1) space to (0,0) to (1,1), I divide by X or Y, add 1 and divide by 2.

I added two user parameters xcount and ycount which are how many
checkers you want (they appear as sliders in the User Values tab) and
multiply these by my adjusted (myx,myy) values.

Then I return (which is to say, fall out of the expression) with black
or white depending on the parity of myx+myy.

----
unit filter checkerboard (int xcount: 2-100 (20), int ycount: 2-100 (20))
myx = floor(((x/X)+1.0)/2.0 * xcount);
myy = floor(((y/Y)+1.0)/2.0 * ycount);

if (myx + myy) % 2 == 1 then
rgba:[0,0,0,1]
else
rgba:[1,1,1,0]
end
end
----

Again, this is run for every pixel so like you said ... no looping in
your code!

http://www.complang.tuwien.ac.at/schani/mathmap/language.html
http://www.complang.tuwien.ac.at/schani/mathmap/reference.html

Sorry for taking so long to reply. I have a toddler. Write back if you
have more questions. :)

Cheers,

Tom

--
-- Tom Rathborne ------------------------------ Independent Nutrition Hacker --
Who in the rainbow can draw the line where the violet tint ends and the
orange tint begins? Distinctly we see the difference of the colors, but
where exactly does the one first blendingly enter into the other?
So with sanity and insanity. -- Herman Melville, Billy Budd
Reply all
Reply to author
Forward
0 new messages