This program allows you to graph functions that have both a complex number input and output. (link at the bottom).
How It works
The input is on a regular 2d plane, where the vertical axis is the imaginary part of the input and the horizontal axis the real part, so the input 1+2i would be here:
Each input point is colored to represent the output. The hue of the color is determined by the angle of the complex output (in radians) on a scale like this:
For example, the point 1+1i would be colored orange, since it has an angle of :
The the magnitude of the output is colored, where the smaller the value, the darker it is, and the larger it is the lighter it is.
This actually produces some really beautiful results. For example, here is a graph of , where z is the complex number used as input:
You can see the zero on the left, where the outputs become very small, and the pole on the right, where they spike towards infinity.
or this :
You can also graph Binet's Formula, which gives the Fibonacci numbers (discussed here), which produces these repeating spikes:
All of these were drawn at full resolution, which takes around 30 seconds to draw. At a lower resolution, you get almost *real time* results, with about 3 seconds a frame. You can pan by clicking and dragging, and zoom by scrolling or using +/-, and there is an auto-updating axis and an output tooltip:
Check it out here, and see what cool functions you can find. Press
o to hide and show the overlay,
r to reset the program, and
h to render render a high quality version.
Look inside and see! ;) (The link is at the bottom of my first post, if you missed it).
(It uses the bignums library for the complex numbers, then just runs the function for each block on the screen and colors it accordingly.)
interesting, I never thought that it was even possible to make an graph like this! How do you name the colors?
I assume you mean how it decides what color each point should be. It does that by finding the angle of the complex number using , which gives the angle in radians, which are just another way to represent angles. Then it just uses that in the block.
There are tons of comments in the project that (I think) do a pretty good job of explaining what's going on.
This is a very interesting project, I think @helicoptur should see this!
You don't have to mention me, I'm on the forum a lot and chances are I will see it at some point.
Totally cool! I like how you use hue and lightness to encode both dimensions of the output value.
wait, there is "LIGHTNESS" how does that work @legoman3.14
I think bh meant the brightness of the actual color, which you set using the saturation and the brightness blocks in Snap.
Or you use the colors library:
("Brightness" is from the unpleasant HSV color space; lightness, from the better HSL space, ranges from 0 for black through 50 for full intensity color to 100 for white. So you can just stick the complex magnitude right into the block.)
The problem with using any of the library blocks is this:
Built in = 6 ms
Library = 2013 ms
So they are much to slow to use per-pixel, like they are in my project.
Ah. That's good to know. I'll have to see if that's solvable. Thanks.
Well, yes, and also, the code is long and complicated. Honestly, I didn't think at all about efficiency as I was writing it, in accord with the principle that it's easier to speed up correct code than to debug fast code.
So here's what that block does each time:
That's 20 IF blocks in addition to the actual work of setting the lightness. I'll have to invent a better way of dispatching on the dimension you're setting.
The alternative, of course, would be to have separate blocks for each possibility: SET PEN LIGHTNESS TO..., SET PEN BLUE TO..., and so on. And some of those blocks are in the library as helpers, but the design goal was not to intimidate users with a zillion different blocks. As it is, there are nine blocks for users in the library.
I'm thinking something like
to replace most of the IF blocks. But we have an upload coming, so I'm not going to start mucking with the library until it's clear that it works
for people at all.
That's a strategy that usually works in scratch, not the best for .
Sorry, what is the antecedent of "that"? What usually works in Scratch but not Snap!?
if-then statements. Snap seems to like code like what you suggested:
Stacking 5 billion octodecillion googloplexes of if-then statments inside each other.