In my attempts to program a Mandelbrot, I made a program that does not work. Could somebody please help? Here is the code I used PER PIXEL:
When green flag clicked
{Set X to (x position)
Set Y to (y position)
Set x0 to (X)
set y0 to (Y)
Set Iteration to (0)
Set Max_Iteration to (1000)}
{Repeat until not [(X*X+Y*X) is less than or equal to (2*2) and (Iteration < Max_Iteration)]
Set xtemp to X*X-Y*Y+x0
Set Y to 2*X*Y+y0
Change Iteration by 1}
{If (Iteration=Max_Iteration)
set pen color to black
else
set pen color to iteration}
I did this code, with motion scripts to move the pen sprite, and I wound up with a dark red screen with a black dot in the middle. What did I do wrong in my code?
Offline
Could you please clarify upon how to do this?
Offline
maybe something like for the first two lines:
Set X to (x position)/120
Set Y to (y position)/90
Last edited by Cyfarwyddyd (2008-06-04 15:13:39)
Offline
Cyclone103 wrote:
Could you please clarify upon how to do this?
For each X and Y value,
set X_scale to X / 120
set Y_scale to Y/ 90
and use X_scale, Y_scale in the equation but plot the result at screen position X, Y
I chose 120 and 90 as the scaling constants because they are half the value of the maximum screen dimensions so I know that X_scale and Y_scale will be in the range of -2 to 2. Of course, having different scale factors will result in some distortion of the figure. If this bothers you, you can use 120 for both the X and Y axes.
Offline
Thanks! I will attempt to implement this now!
Offline
Wow! That worked well! I guess I could also implement a zoom feature based on scale.........Thanks everyone! Ill post it in a few minutes!
Offline
Aha! I was having coloration problems, meaning once it reached max_iterations it stayed black even for lesser values, so I solved that by adding in a bright set pen color to yellow right inside my pen scripts. It is still mostly ok, I probably just need to scale in a bit more. Now the black dot is a bit larger and strangely shaped, so I will scale in further.....
Offline
um, here it is. still not workin........ http://scratch.mit.edu/projects/Cyclone103/180591 thanks for at least trying
Offline
I made a Mandelbrot project that kinda follows the way you did it in your script, with some modifications:
http://scratch.mit.edu/projects/Cyfarwyddyd/182464
Maybe this would be helpful.
Offline
ok, I got it working. I will post a link when it is online. I am just waiting for it to fill in at a high enough focus so the preview window looks cool..........
Offline
http://scratch.mit.edu/projects/Cyclone103/182788 it works!
Offline