Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- JWildfire - an image and animation processor written in Java
- Copyright (C) 1995-2011 Andreas Maschke
- This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
- General Public License as published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
- This software 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
- Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License along with this software;
- if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
- package org.jwildfire.create.tina.variation;
- import org.jwildfire.create.tina.base.Layer;
- import org.jwildfire.create.tina.base.XForm;
- import org.jwildfire.create.tina.base.XYZPoint;
- import static org.jwildfire.base.mathlib.MathLib.*;
- public class NestedCirclesFunc extends VariationFunc {
- private static final long serialVersionUID = 1L;
- private static final String PARAM_LEVELS = "levels";
- private static final String[] paramNames = {PARAM_LEVELS};
- private int levels = 6;
- @Override
- public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
- int level = (int) (sqrt(pContext.random()) * levels);
- int n = 1 << level;
- double radius = pAmount / n;
- double x = topLeftx + radius / sqrt(2.0) + ((int) pContext.random(n)) * radius * sqrt(2.0);
- double y = topLefty + radius / sqrt(2.0) + ((int) pContext.random(n)) * radius * sqrt(2.0);
- double theta = pContext.random() * M_2PI;
- pVarTP.x += radius * cos(theta) + x;
- pVarTP.y += radius * sin(theta) + y;
- if (pContext.isPreserveZCoordinate()) {
- pVarTP.z += pAmount * pAffineTP.z;
- }
- }
- @Override
- public String[] getParameterNames() {
- return paramNames;
- }
- @Override
- public Object[] getParameterValues() {
- return new Object[]{levels};
- }
- @Override
- public void setParameter(String pName, double pValue) {
- if (PARAM_LEVELS.equalsIgnoreCase(pName))
- levels = (int) limitVal(pValue, 1, 10);
- else
- throw new IllegalArgumentException(pName);
- }
- @Override
- public String getName() {
- return "nested_circles";
- }
- private double topLeftx, topLefty;
- @Override
- public void init(FlameTransformationContext pContext, Layer pLayer, XForm pXForm, double pAmount) {
- topLeftx = topLefty = -pAmount / sqrt(2.0);
- }
- @Override
- public VariationFuncType[] getVariationTypes() {
- return new VariationFuncType[]{VariationFuncType.VARTYPE_BASE_SHAPE};
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement