Sub Mandelbrot() Dim colour(256, 256) As Long Dim Row As Long, Col As Long Dim xcenter As Long, ycenter As Long, span As Long, imax As Long Dim startx As Double, starty As Double, endx As Double, endy As Double Dim Delta As Double Dim cx As Double, cy As Double, x As Double, y As Double, xtemp As Double Dim i As Long, Colmax As Long, Colscale As Double 'Formata a ?rea de c?lulas Columns("A:IV").Select Selection.ColumnWidth = 0.2 Rows("1:257").Select Selection.RowHeight = 2 Range(Cells(1, 1), Cells(256, 256)).Interior.Color = RGB(0, 255, 255) Range("a1").Select 'Atribui o cenntro da figura xcenter = 0 ycenter = 0 ' Le a escala e a resolu??o da figura span = Range("IX260") imax = Range("IX261") 'Definime o limite inicial e final de cada dimens?o startx = xcenter - span / 2 endx = xcenter + span / 2 starty = ycenter - span / 2 endy = ycenter + span / 2 Delta = span / 256 'Calcula para cada c?lula a itera??o de Mandelbrot at? a resolu??o definida em imax For Row = 1 To 256 For Col = 1 To 256 cx = startx + Delta * Col cy = starty + Delta * Row x = cx y = cy i = 0 While i < imax And (x * x + y * y <= 4) xtemp = x * x - y * y + cx y = 2 * x * y + cy x = xtemp i = i + 1 Wend colour(Row, Col) = IIf(i = imax, 0, i) DoEvents Next Col Next Row 'Descolbre o valor m?ximo associado (o m?nimo ? zero) Colmax = 0 For Row = 1 To 256 For Col = 1 To 256 If Colmax < colour(Row, Col) Then Colmax = colour(Row, Col) Next Next 'Se todos o svalores forem zero, deu pau! If Colmax = 0 Then Exit Sub 'Ajusta a escala de cores a ser utilizada Colscale = RGB(0, 0, 255) / Colmax ' aqui no cas ser? o verde e o azul For Row = 1 To 256 For Col = 1 To 256 Cells(Row, Col).Interior.Color = Int(Colscale * colour(Row, Col)) Next DoEvents Next End Sub Sub Samambaia() Dim colour(256, 256) As Long Columns("A:IV").Select Selection.ColumnWidth = 0.2 Rows("1:257").Select Selection.RowHeight = 2 Range(Cells(1, 1), Cells(256, 256)).Interior.Color = RGB(255, 255, 255) Range("a1").Select 'Read user inputs xcenter = 0 'Range("EP259") ycenter = 0 'Range("EP260") span = Range("IX260") imax = Range("IX261") 'Fix the starting and ending co-ordinates startx = xcenter - span / 2 endx = xcenter + span / 2 starty = ycenter - span / 2 endy = ycenter + span / 2 Delta = span / 256 'For each cell in the image, run the iteration for the Mandelbrot set For Row = 1 To 256 For Col = 1 To 256 cx = startx + Delta * Col cy = starty + Delta * Row x = cx y = cy i = 0 While i < imax And (x * x + y * y <= 4) xtemp = x * x - y * y - 0.15 y = 2 * x * y - 0.17 x = xtemp i = i + 1 Wend colour(Row, Col) = IIf(i = imax, 0, i) DoEvents Next Next Colmax = 0 'Find the max value of the colour, this will be mapped to white and the other colours 'will be scaled accordingly For Row = 1 To 256 For Col = 1 To 256 If Colmax < colour(Row, Col) Then Colmax = colour(Row, Col) Next Next 'If its all black, there is nothing to do If Colmax = 0 Then Exit Sub 'Set the colour scale and colour the cells accordingly Colscale = RGB(255, 255, 255) / Colmax For Row = 1 To 256 For Col = 1 To 256 Cells(Row, Col).Interior.Color = Int(Colscale * colour(Row, Col)) Next DoEvents Next End Sub