/** Marvin Project <2007-2010> Initial version by: Danilo Rosetto Munoz Fabio Andrijauskas Gabriel Ambrosio Archanjo site: http://marvinproject.sourceforge.net GPL Copyright (C) <2007> 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 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. */ package org.marvinproject.image.render.iteratedFunctionSystem; import java.awt.Color; import java.util.ArrayList; import java.util.List; import marvin.gui.MarvinFilterWindow; import marvin.image.MarvinImage; import marvin.image.MarvinImageMask; import marvin.plugin.MarvinAbstractImagePlugin; import marvin.util.MarvinAttributes; public class IteratedFunctionSystem extends MarvinAbstractImagePlugin{ private MarvinAttributes attributes; private List rules; // Testing String private final static String EXAMPLE_RULES = "0,0,0,0.16,0,0,0.01\n"+ "0.85,0.04,-0.04,0.85,0,1.6,0.85\n"+ "0.2,-0.26,0.23,0.22,0,1.6,0.07\n"+ "-0.15,0.28,0.26,0.24,0,0.44,0.07\n"; @Override public void load() { attributes = getAttributes(); attributes.set("rules", EXAMPLE_RULES); attributes.set("iterations", 1000000); rules = new ArrayList(); } @Override public void process ( MarvinImage imageIn, MarvinImage imageOut, MarvinAttributes out2, MarvinImageMask a_mask, boolean previewMode ){ loadRules(); int iterations = (Integer)attributes.get("iterations"); double x0 = 0; double y0 = 0; double x,y; int startX; int startY; double factor; double minX=999999999,minY=999999999,maxX=-999999999,maxY=-99999999; Rule tempRule; double point[] = {x0,y0}; imageOut.clearImage(0xFFFFFFFF); for(int i=0; i maxX){ maxX = x; }; if(y < minY){ minY = y; }; if(y > maxY){ maxY = y; }; } int width = imageOut.getWidth(); int height = imageOut.getHeight(); double deltaX = Math.abs(maxX-minX); double deltaY = Math.abs(maxY-minY); if(deltaX > deltaY){ factor = (width/deltaX); if(deltaY * factor > height){ factor = factor * (height/(deltaY * factor)); } } else{ factor = (height/deltaY); if(deltaX * factor > width){ factor = factor * (width/(deltaX * factor)); } } factor *= 0.9; startX = (int)((width/2)-((minX+((deltaX)/2))*factor)); startY = (int)(height-((height/2)-((minY+(deltaY/2))*factor))); point[0] = x0; point[1] = y0; for(int i=0; i= 0 && x= 0 && y < height){ imageOut.setIntColor((int)x,(int)y , 0); } } } @Override public void show() { MarvinFilterWindow filterWindow = new MarvinFilterWindow("Iterated Funcion System", 500,500, getImagePanel(), this); filterWindow.addLabel("lblRules","Rules:"); filterWindow.newComponentRow(); filterWindow.addTextArea("txtRules","rules", 8, 40, attributes); filterWindow.setVisible(true); } private void loadRules(){ String r[] = ((String)(attributes.get("rules"))).split("\n"); for(int i=0; i