/* Copyright (c) 2004 Joseph Gleason Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Current versions of this and other code can be downloaded at: http://gleason.cc/ */ package cc.glsn.randomimage; import java.awt.image.BufferedImage; import java.util.Random; import javax.imageio.ImageIO; import java.io.File; import java.util.*; public class RandomImage { public static void main(String Args[]) throws Exception { new RandomImage(Args); } double MaxDist; double PFactor; HashMap PullCache; public RandomImage(String Args[]) throws Exception { Random PRNG=new Random(); int Width=new Integer(Args[0]).intValue(); int Height=new Integer(Args[1]).intValue(); int DPoints=new Integer(Args[2]).intValue(); PFactor=new Double(Args[3]).doubleValue(); System.out.println("Factor: " + PFactor); String Target=Args[4]; MaxDist=dist(0,0,Width,Height); LinkedList PL=new LinkedList(); PullCache=new HashMap(1024,0.5f); for(int i=0; i0) //Pull=Math.pow( 1.0-(Dist/MaxDist),PFactor); Pull=pull(Dist); if (Pull>1.0) Pull=1.0; //System.out.println("Dist:" + Dist + " Pull: " + Pull); RMin+=Pull*(DP.RMin-RMin); BMin+=Pull*(DP.BMin-BMin); GMin+=Pull*(DP.GMin-GMin); RMax+=Pull*(DP.RMax-RMax); BMax+=Pull*(DP.BMax-BMax); GMax+=Pull*(DP.GMax-GMax); /*assert(RMin=0.0); assert(Pull<=1.0);*/ } int R=PRNG.nextInt(RMax-RMin)+RMin; int B=PRNG.nextInt(BMax-BMin)+BMin; int G=PRNG.nextInt(GMax-GMin)+GMin; V=R*256*256+G*256+B; BI.setRGB(i,j,V); } } File F=new File(Target); ImageIO.write(BI,"png",F); } double dist(int x1, int y1, int x2, int y2) { return Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)); } class DPoint { int LocX; int LocY; int RMin; int BMin; int GMin; int RMax; int BMax; int GMax; void print() { System.out.println("DPoint{" + "LocX:" + LocX + " LocY:" + LocY + " Min:" + RMin + " " + BMin + " " + GMin + " Max:" + RMax + " " + BMax + " " + GMax + "}"); } } double pull(double a) { a=Math.round(a); Double A=new Double(a); Double Ans=(Double)PullCache.get(A); if (Ans==null) { double p=Math.pow( 1.0-(a/MaxDist),PFactor); PullCache.put(A,new Double(p)); return p; } else { return Ans.doubleValue(); } } }