User:Decimus Schomer/Scripts/Fractal viewer
Decimus' user page | Decimus' talk page | Decimus' scripts | Decimus' script libraries | Decimus' projects
Main scripts page | Toggling Rotate script | UUID-getter scripts | Texture changer | Channel spier | Chatbot | Jump slab | Emailer | Fractal viewer | Grammar analyser | SPD viewer
This script, written by Decimus, is a basic fractal viewer, with a simple 'zoom'-like feature and easily customisable fractal and colouring.
Comments will be added later.
# Fractal viewer - display and zoom a fractal # Copyright (C) 2007 Decimus Schomer # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # (you can find version 2 of the GPL at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) import pygame, math pygame.init() psz = 1. / (1 << 3) sd = 512 sc = pygame.display.set_mode((sd, sd)) pygame.event.set_allowed(None) pygame.event.set_allowed(pygame.QUIT) def n2c(a): b, c, d = a & 255, (a >> 8) & 255, (a >> 16) & 255 return b, c, d def getpx(x, y): ox, oy = x, y i = 0 while ((x*x) + (y*y) < 4096) and (i < 255): x += 1 + (x*y) - (ox*oy) y -= x i += 1 return (i, 0, 0) def drawpx(x, y): xc = (x - sd//2) * psz yc = (sd//2 - y) * psz c = getpx(xc, yc) sc.set_at((x, y), c) xp = yp = 0 while 1: if pygame.event.get(pygame.QUIT): break drawpx(xp, yp) xp += 1 if xp == sd: pygame.display.update((0, yp, sd, 1)) xp = 0 yp += 1 if yp == sd: psz /= 2 xp = yp = 0