This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-06-03 17:18:29

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Mandelbrot Mishaps

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?


All your base are belong to us

Offline

 

#2 2008-06-04 11:08:57

Canthiar
Scratcher
Registered: 2007-05-16
Posts: 100+

Re: Mandelbrot Mishaps

If you're using Scratch's x and y position then your values are most likely too large.  You should try to scale your x and y so that they are in the range of -2 to 2.

Offline

 

#3 2008-06-04 15:05:56

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: Mandelbrot Mishaps

Could you please clarify upon how to do this?


All your base are belong to us

Offline

 

#4 2008-06-04 15:13:27

Cyfarwyddyd
Scratcher
Registered: 2008-06-04
Posts: 17

Re: Mandelbrot Mishaps

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

 

#5 2008-06-04 15:14:39

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Mandelbrot Mishaps

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.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#6 2008-06-04 15:51:34

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: Mandelbrot Mishaps

Thanks! I will  attempt to implement this now!


All your base are belong to us

Offline

 

#7 2008-06-04 15:57:15

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: Mandelbrot Mishaps

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!


All your base are belong to us

Offline

 

#8 2008-06-04 16:21:36

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: Mandelbrot Mishaps

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.....


All your base are belong to us

Offline

 

#9 2008-06-04 17:03:10

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: Mandelbrot Mishaps

um, here it is. still not workin........ http://scratch.mit.edu/projects/Cyclone103/180591 thanks for at least trying  tongue


All your base are belong to us

Offline

 

#10 2008-06-06 23:07:43

Cyfarwyddyd
Scratcher
Registered: 2008-06-04
Posts: 17

Re: Mandelbrot Mishaps

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

 

#11 2008-06-07 11:49:27

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: Mandelbrot Mishaps

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..........


All your base are belong to us

Offline

 

#12 2008-06-07 12:30:11

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: Mandelbrot Mishaps

http://scratch.mit.edu/projects/Cyclone103/182788 it works!


All your base are belong to us

Offline

 

Board footer