Search in sources :

Example 36 with Flame

use of org.jwildfire.create.tina.base.Flame in project JWildfire by thargor6.

the class IFlamesController method createNewFlame.

private Flame createNewFlame() {
    Flame flame = new Flame();
    flame.setBGTransparency(prefs.isTinaDefaultBGTransparency());
    flame.setCamRoll(0);
    flame.setCamPitch(0);
    flame.setCamYaw(0);
    flame.setCamPerspective(0);
    flame.setWidth(800);
    flame.setHeight(600);
    flame.setCamZoom(1);
    {
        Layer layer = flame.getFirstLayer();
        new RandomGradientMutation().execute(layer);
        XForm xForm = new XForm();
        layer.getXForms().add(xForm);
        xForm.setWeight(0.5);
        IFlamesFunc iflames = (IFlamesFunc) VariationFuncList.getVariationFuncInstance("iflames_wf", true);
        if (imageLibrary.size() > 0) {
            String imgFilename = imageLibrary.get((int) (Math.random() * imageLibrary.size())).getFilename();
            iflames.getImageParams().setImageFilename(imgFilename);
        }
        if (flameLibrary.size() > 0) {
            for (int i = 0; i < IFlamesFunc.MAX_FLAME_COUNT; i++) {
                if (i > 1 && Math.random() < 0.33) {
                    iflames.getFlameParams(i).setFlameXML(null);
                } else if (Math.random() < 0.50) {
                    Flame libFlame = flameLibrary.get((int) (Math.random() * flameLibrary.size())).getFlame();
                    String libFlameXML;
                    try {
                        libFlameXML = new FlameWriter().getFlameXML(libFlame);
                    } catch (Exception e) {
                        libFlameXML = null;
                        e.printStackTrace();
                    }
                    iflames.getFlameParams(i).setFlameXML(libFlameXML);
                }
            }
        }
        if (Math.random() < 0.5) {
            iflames.getImageParams().setShape_distribution(ShapeDistribution.HUE);
        } else {
            iflames.getImageParams().setShape_distribution(ShapeDistribution.RANDOM);
        }
        for (int i = 0; i < IFlamesFunc.MAX_FLAME_COUNT; i++) {
            iflames.getFlameParams(i).setSize(2.0 + Math.random() * 4.0);
        }
        iflames.getMotionParams().setPreview(previewButton.isSelected() ? 1 : 0);
        xForm.addVariation(1.0, iflames);
    }
    return flame.makeCopy();
}
Also used : FlameWriter(org.jwildfire.create.tina.io.FlameWriter) XForm(org.jwildfire.create.tina.base.XForm) RandomGradientMutation(org.jwildfire.create.tina.mutagen.RandomGradientMutation) Layer(org.jwildfire.create.tina.base.Layer) IFlamesFunc(org.jwildfire.create.tina.variation.iflames.IFlamesFunc) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 37 with Flame

use of org.jwildfire.create.tina.base.Flame in project JWildfire by thargor6.

the class IFlamesController method importFromFlameLibrary.

public void importFromFlameLibrary(int pIdx) {
    if (pIdx >= 0 && pIdx < flameLibrary.size() && getIFlamesFunc() != null) {
        Flame flame = flameLibrary.get(pIdx).getFlame();
        saveUndoPoint();
        try {
            String flameXML = new FlameWriter().getFlameXML(flame);
            getIFlamesFunc().getFlameParams(getCurrFlameIndex()).setFlameXML(flameXML);
        } catch (Exception e) {
            errorHandler.handleError(e);
        }
        enableControls();
        baseFlameCmb_changed();
        refreshIFlame();
    }
}
Also used : FlameWriter(org.jwildfire.create.tina.io.FlameWriter) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 38 with Flame

use of org.jwildfire.create.tina.base.Flame in project JWildfire by thargor6.

the class FlameMorphService method morphFlames_morph.

private static Flame morphFlames_morph(Prefs pPrefs, Flame pFlame1, Flame pFlame2, int pFrame, int pFrames) {
    if (pFrame < 1 || pFrames < 2)
        return pFlame1;
    double fScl = (double) (pFrame - 1) / (pFrames - 1);
    if (fScl <= MathLib.EPSILON) {
        return pFlame1;
    } else if (fScl >= 1.0 - MathLib.EPSILON) {
        return pFlame2;
    }
    Flame res = pFlame1.makeCopy();
    res.getLayers().clear();
    int layerSize1 = pFlame1.getLayers().size();
    int layerSize2 = pFlame2.getLayers().size();
    int maxLayerSize = layerSize1 > layerSize2 ? layerSize1 : layerSize2;
    for (int lIdx = 0; lIdx < maxLayerSize; lIdx++) {
        Layer layer = new Layer();
        res.getLayers().add(layer);
        // Morph layers
        if (lIdx < layerSize1 && lIdx < layerSize2) {
            Layer layer1 = pFlame1.getLayers().get(lIdx);
            Layer layer2 = pFlame2.getLayers().get(lIdx);
            layer.assign(layer1);
            layer.getXForms().clear();
            layer.getFinalXForms().clear();
            layer.setWeight(morphValue(layer1.getWeight(), layer2.getWeight(), fScl));
            // morph XForms
            {
                int size1 = layer1.getXForms().size();
                int size2 = layer2.getXForms().size();
                int maxSize = size1 > size2 ? size1 : size2;
                for (int i = 0; i < maxSize; i++) {
                    XForm xForm1 = i < size1 ? layer1.getXForms().get(i) : null;
                    if (xForm1 == null) {
                        xForm1 = new XForm();
                        xForm1.addVariation(0.0, VariationFuncList.getVariationFuncInstance("linear3D", true));
                        xForm1.setWeight(0.0);
                    }
                    XForm xForm2 = i < size2 ? layer2.getXForms().get(i) : null;
                    if (xForm2 == null) {
                        xForm2 = new XForm();
                        xForm2.addVariation(0.0, VariationFuncList.getVariationFuncInstance("linear3D", true));
                        xForm2.setWeight(0.0);
                    }
                    XForm morphedXForm = morphXForms(pPrefs, xForm1, xForm2, fScl, pFrame, pFrames);
                    layer.getXForms().add(morphedXForm);
                }
            }
            // morph final XForms
            {
                int size1 = layer1.getFinalXForms().size();
                int size2 = layer2.getFinalXForms().size();
                int maxSize = size1 > size2 ? size1 : size2;
                for (int i = 0; i < maxSize; i++) {
                    XForm xForm1 = i < size1 ? layer1.getFinalXForms().get(i) : null;
                    if (xForm1 == null) {
                        xForm1 = new XForm();
                        xForm1.addVariation(0.0, VariationFuncList.getVariationFuncInstance("linear3D", true));
                        xForm1.setWeight(0.0);
                    }
                    XForm xForm2 = i < size2 ? layer2.getFinalXForms().get(i) : null;
                    if (xForm2 == null) {
                        xForm2 = new XForm();
                        xForm2.addVariation(0.0, VariationFuncList.getVariationFuncInstance("linear3D", true));
                        xForm2.setWeight(0.0);
                    }
                    XForm morphedXForm = morphXForms(pPrefs, xForm1, xForm2, fScl, pFrame, pFrames);
                    layer.getFinalXForms().add(morphedXForm);
                }
            }
            // morph colors
            RGBPalette palette1 = layer1.getPalette();
            RGBPalette palette2 = layer2.getPalette();
            for (int i = 0; i < RGBPalette.PALETTE_SIZE; i++) {
                RGBColor color1 = palette1.getColor(i);
                RGBColor color2 = palette2.getColor(i);
                int red = Tools.roundColor(color1.getRed() + (color2.getRed() - color1.getRed()) * fScl);
                int green = Tools.roundColor(color1.getGreen() + (color2.getGreen() - color1.getGreen()) * fScl);
                int blue = Tools.roundColor(color1.getBlue() + (color2.getBlue() - color1.getBlue()) * fScl);
                layer.getPalette().setColor(i, red, green, blue);
            }
        } else // fade out layer1 to black
        if (lIdx < layerSize1) {
            Layer layer1 = pFlame1.getLayers().get(lIdx);
            layer.assign(layer1);
            layer.setWeight(morphValue(layer1.getWeight(), 0.0, fScl));
        } else // fade in layer2 from black
        if (lIdx < layerSize2) {
            Layer layer2 = pFlame2.getLayers().get(lIdx);
            layer.assign(layer2);
            layer.setWeight(morphValue(0.0, layer2.getWeight(), fScl));
        }
    }
    // morph camera settings etc.
    morphFlameValues(pFlame1, pFlame2, fScl, res);
    return res;
}
Also used : XForm(org.jwildfire.create.tina.base.XForm) RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) RGBColor(org.jwildfire.create.tina.palette.RGBColor) Layer(org.jwildfire.create.tina.base.Layer) Flame(org.jwildfire.create.tina.base.Flame)

Example 39 with Flame

use of org.jwildfire.create.tina.base.Flame in project JWildfire by thargor6.

the class FlameMorphService method morphFlames_fade.

private static Flame morphFlames_fade(Prefs pPrefs, Flame pFlame1, Flame pFlame2, int pFrame, int pFrames) {
    if (pFrame < 1 || pFrames < 2)
        return pFlame1;
    double fScl = (double) (pFrame - 1) / (pFrames - 1);
    if (fScl <= MathLib.EPSILON) {
        return pFlame1;
    } else if (fScl >= 1.0 - MathLib.EPSILON) {
        return pFlame2;
    }
    // fade out layerz of the source flame
    Flame res = pFlame1.makeCopy();
    morphFlameValues(pFlame1, pFlame2, fScl, res);
    for (Layer layer : res.getLayers()) {
        layer.setWeight(layer.getWeight() * (1.0 - fScl));
    }
    // add and fade in layerz of the dest flame
    for (Layer layer : pFlame2.getLayers()) {
        Layer copy = layer.makeCopy();
        copy.setWeight(copy.getWeight() * fScl);
        res.getLayers().add(copy);
    }
    return res;
}
Also used : Layer(org.jwildfire.create.tina.base.Layer) Flame(org.jwildfire.create.tina.base.Flame)

Example 40 with Flame

use of org.jwildfire.create.tina.base.Flame in project JWildfire by thargor6.

the class FlameMorphService method morphXForms.

private static XForm morphXForms(Prefs pPrefs, XForm pXForm1, XForm pXForm2, double pFScl, int pFrame, int pFrames) {
    pXForm1 = pXForm1.makeCopy();
    pXForm2 = pXForm2.makeCopy();
    prepareMorphXForm(pXForm1);
    prepareMorphXForm(pXForm2);
    XForm res = new XForm();
    res.setWeight(morphValue(pXForm1.getWeight(), pXForm2.getWeight(), pFScl));
    res.setColor(morphValue(pXForm1.getColor(), pXForm2.getColor(), pFScl));
    res.setColorSymmetry(morphValue(pXForm1.getColorSymmetry(), pXForm2.getColorSymmetry(), pFScl));
    res.setMaterial(morphValue(pXForm1.getMaterial(), pXForm2.getMaterial(), pFScl));
    res.setMaterialSpeed(morphValue(pXForm1.getMaterialSpeed(), pXForm2.getMaterialSpeed(), pFScl));
    res.setXYCoeff00(morphValue(pXForm1.getXYCoeff00(), pXForm2.getXYCoeff00(), pFScl));
    res.setXYCoeff01(morphValue(pXForm1.getXYCoeff01(), pXForm2.getXYCoeff01(), pFScl));
    res.setXYCoeff10(morphValue(pXForm1.getXYCoeff10(), pXForm2.getXYCoeff10(), pFScl));
    res.setXYCoeff11(morphValue(pXForm1.getXYCoeff11(), pXForm2.getXYCoeff11(), pFScl));
    res.setXYCoeff20(morphValue(pXForm1.getXYCoeff20(), pXForm2.getXYCoeff20(), pFScl));
    res.setXYCoeff21(morphValue(pXForm1.getXYCoeff21(), pXForm2.getXYCoeff21(), pFScl));
    res.setYZCoeff00(morphValue(pXForm1.getYZCoeff00(), pXForm2.getYZCoeff00(), pFScl));
    res.setYZCoeff01(morphValue(pXForm1.getYZCoeff01(), pXForm2.getYZCoeff01(), pFScl));
    res.setYZCoeff10(morphValue(pXForm1.getYZCoeff10(), pXForm2.getYZCoeff10(), pFScl));
    res.setYZCoeff11(morphValue(pXForm1.getYZCoeff11(), pXForm2.getYZCoeff11(), pFScl));
    res.setYZCoeff20(morphValue(pXForm1.getYZCoeff20(), pXForm2.getYZCoeff20(), pFScl));
    res.setYZCoeff21(morphValue(pXForm1.getYZCoeff21(), pXForm2.getYZCoeff21(), pFScl));
    res.setZXCoeff00(morphValue(pXForm1.getZXCoeff00(), pXForm2.getZXCoeff00(), pFScl));
    res.setZXCoeff01(morphValue(pXForm1.getZXCoeff01(), pXForm2.getZXCoeff01(), pFScl));
    res.setZXCoeff10(morphValue(pXForm1.getZXCoeff10(), pXForm2.getZXCoeff10(), pFScl));
    res.setZXCoeff11(morphValue(pXForm1.getZXCoeff11(), pXForm2.getZXCoeff11(), pFScl));
    res.setZXCoeff20(morphValue(pXForm1.getZXCoeff20(), pXForm2.getZXCoeff20(), pFScl));
    res.setZXCoeff21(morphValue(pXForm1.getZXCoeff21(), pXForm2.getZXCoeff21(), pFScl));
    res.setOpacity(morphValue(pXForm1.getOpacity(), pXForm2.getOpacity(), pFScl));
    res.setXYPostCoeff00(morphValue(pXForm1.getXYPostCoeff00(), pXForm2.getXYPostCoeff00(), pFScl));
    res.setXYPostCoeff01(morphValue(pXForm1.getXYPostCoeff01(), pXForm2.getXYPostCoeff01(), pFScl));
    res.setXYPostCoeff10(morphValue(pXForm1.getXYPostCoeff10(), pXForm2.getXYPostCoeff10(), pFScl));
    res.setXYPostCoeff11(morphValue(pXForm1.getXYPostCoeff11(), pXForm2.getXYPostCoeff11(), pFScl));
    res.setXYPostCoeff20(morphValue(pXForm1.getXYPostCoeff20(), pXForm2.getXYPostCoeff20(), pFScl));
    res.setXYPostCoeff21(morphValue(pXForm1.getXYPostCoeff21(), pXForm2.getXYPostCoeff21(), pFScl));
    res.setYZPostCoeff00(morphValue(pXForm1.getYZPostCoeff00(), pXForm2.getYZPostCoeff00(), pFScl));
    res.setYZPostCoeff01(morphValue(pXForm1.getYZPostCoeff01(), pXForm2.getYZPostCoeff01(), pFScl));
    res.setYZPostCoeff10(morphValue(pXForm1.getYZPostCoeff10(), pXForm2.getYZPostCoeff10(), pFScl));
    res.setYZPostCoeff11(morphValue(pXForm1.getYZPostCoeff11(), pXForm2.getYZPostCoeff11(), pFScl));
    res.setYZPostCoeff20(morphValue(pXForm1.getYZPostCoeff20(), pXForm2.getYZPostCoeff20(), pFScl));
    res.setYZPostCoeff21(morphValue(pXForm1.getYZPostCoeff21(), pXForm2.getYZPostCoeff21(), pFScl));
    res.setZXPostCoeff00(morphValue(pXForm1.getZXPostCoeff00(), pXForm2.getZXPostCoeff00(), pFScl));
    res.setZXPostCoeff01(morphValue(pXForm1.getZXPostCoeff01(), pXForm2.getZXPostCoeff01(), pFScl));
    res.setZXPostCoeff10(morphValue(pXForm1.getZXPostCoeff10(), pXForm2.getZXPostCoeff10(), pFScl));
    res.setZXPostCoeff11(morphValue(pXForm1.getZXPostCoeff11(), pXForm2.getZXPostCoeff11(), pFScl));
    res.setZXPostCoeff20(morphValue(pXForm1.getZXPostCoeff20(), pXForm2.getZXPostCoeff20(), pFScl));
    res.setZXPostCoeff21(morphValue(pXForm1.getZXPostCoeff21(), pXForm2.getZXPostCoeff21(), pFScl));
    res.setOpacity(morphValue(pXForm1.getOpacity(), pXForm2.getOpacity(), pFScl));
    res.setDrawMode(pFScl >= 0.5 ? pXForm2.getDrawMode() : pXForm1.getDrawMode());
    for (int i = 0; i < pXForm1.getModifiedWeights().length; i++) {
        res.getModifiedWeights()[i] = morphValue(pXForm1.getModifiedWeights()[i], pXForm2.getModifiedWeights()[i], pFScl);
    }
    res.clearVariations();
    List<Variation> vars1 = new ArrayList<Variation>();
    List<Variation> vars2 = new ArrayList<Variation>();
    HashMap<String, String> processed = new HashMap<String, String>();
    for (int i = 0; i < pXForm1.getVariationCount(); i++) {
        Variation var1 = pXForm1.getVariation(i);
        String fncName = var1.getFunc().getName();
        processed.put(fncName, fncName);
        vars1.add(var1);
        // search the same func in xForm2
        Variation var2 = null;
        for (int j = 0; j < pXForm2.getVariationCount(); j++) {
            var2 = pXForm2.getVariation(j);
            if (var2.getFunc().getName().equals(fncName)) {
                break;
            } else {
                var2 = null;
            }
        }
        if (var2 != null) {
            vars2.add(var2);
        } else {
            vars2.add(new Variation(0.0, VariationFuncList.getVariationFuncInstance(var1.getFunc().getName(), true)));
        }
    }
    for (int i = 0; i < pXForm2.getVariationCount(); i++) {
        Variation var2 = pXForm2.getVariation(i);
        String fncName = var2.getFunc().getName();
        if (processed.get(fncName) == null) {
            vars2.add(var2);
            vars1.add(new Variation(0.0, VariationFuncList.getVariationFuncInstance(var2.getFunc().getName(), true)));
        }
    }
    if (vars1.size() != vars2.size()) {
        throw new IllegalStateException();
    }
    for (int i = 0; i < vars1.size(); i++) {
        Variation var1 = vars1.get(i);
        Variation var2 = vars2.get(i);
        if (!var1.getFunc().getName().equals(var2.getFunc().getName())) {
            throw new IllegalStateException();
        }
        // System.out.println(i + ": " + var1.getFunc().getName() + " " + var1.getAmount() + " " + var2.getAmount());
        double amount = morphValue(var1.getAmount(), var2.getAmount(), pFScl);
        Variation var = res.addVariation(amount, var1.getFunc());
        // params
        if (var.getFunc().getParameterNames() != null && var.getFunc().getParameterNames().length > 0) {
            Object[] val = var.getFunc().getParameterValues();
            Object[] val1 = var1.getFunc().getParameterValues();
            Object[] val2 = var2.getFunc().getParameterValues();
            for (int j = 0; j < var.getFunc().getParameterNames().length; j++) {
                String name = var.getFunc().getParameterNames()[j];
                if (val[j] instanceof Integer) {
                    int mVal = morphValue((Integer) val1[j], (Integer) val2[j], pFScl);
                    if (mVal == 0 && name.equals("power")) {
                        mVal = 1;
                    }
                    // int mVal = pFScl >= 0.5 ? (Integer) val2[j] : (Integer) val1[j];
                    // System.out.println("  " + name + " " + mVal + " (" + val1[j] + " " + val2[j] + ")");
                    var.getFunc().setParameter(name, mVal);
                } else if (val[j] instanceof Double) {
                    double mVal = morphValue((Double) val1[j], (Double) val2[j], pFScl);
                    // System.out.println("  " + name + " " + mVal + " (" + val1[j] + " " + val2[j] + ")");
                    var.getFunc().setParameter(name, mVal);
                } else {
                    throw new IllegalStateException();
                }
            }
        }
        // ressources
        if (var.getFunc().getRessourceNames() != null && var.getFunc().getRessourceNames().length > 0) {
            Object[] ress1 = var1.getFunc().getRessourceValues();
            Object[] ress2 = var2.getFunc().getRessourceValues();
            for (int j = 0; j < var.getFunc().getRessourceNames().length; j++) {
                String name = var.getFunc().getRessourceNames()[j];
                if (name.equalsIgnoreCase(SubFlameWFFunc.RESSOURCE_FLAME) && var.getFunc().getName().indexOf("subflame_wf") >= 0) {
                    String flame1XML = new String((byte[]) ress1[j]);
                    String flame2XML = new String((byte[]) ress2[j]);
                    try {
                        Flame flame1 = new FlameReader(pPrefs).readFlamesfromXML(flame1XML).get(0);
                        Flame flame2 = new FlameReader(pPrefs).readFlamesfromXML(flame2XML).get(0);
                        Flame morphedFlame = morphFlames(pPrefs, FlameMorphType.MORPH, flame1, flame2, pFrame, pFrames);
                        String morphedFlameXML = new FlameWriter().getFlameXML(morphedFlame);
                        var.getFunc().setRessource(SubFlameWFFunc.RESSOURCE_FLAME, morphedFlameXML.getBytes());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        }
    }
    return res;
}
Also used : FlameReader(org.jwildfire.create.tina.io.FlameReader) XForm(org.jwildfire.create.tina.base.XForm) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FlameWriter(org.jwildfire.create.tina.io.FlameWriter) Variation(org.jwildfire.create.tina.variation.Variation) Flame(org.jwildfire.create.tina.base.Flame)

Aggregations

Flame (org.jwildfire.create.tina.base.Flame)232 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)109 Layer (org.jwildfire.create.tina.base.Layer)63 XForm (org.jwildfire.create.tina.base.XForm)55 VariationFunc (org.jwildfire.create.tina.variation.VariationFunc)30 FlameRenderer (org.jwildfire.create.tina.render.FlameRenderer)27 FlameReader (org.jwildfire.create.tina.io.FlameReader)24 File (java.io.File)21 RenderInfo (org.jwildfire.create.tina.render.RenderInfo)21 ArrayList (java.util.ArrayList)17 JFileChooser (javax.swing.JFileChooser)17 SimpleImage (org.jwildfire.image.SimpleImage)17 FlameWriter (org.jwildfire.create.tina.io.FlameWriter)15 Rectangle (java.awt.Rectangle)10 Clipboard (java.awt.datatransfer.Clipboard)10 FlamePanel (org.jwildfire.create.tina.swing.flamepanel.FlamePanel)9 RGBPalette (org.jwildfire.create.tina.palette.RGBPalette)8 Transferable (java.awt.datatransfer.Transferable)7 ResolutionProfile (org.jwildfire.base.ResolutionProfile)7 Test (org.junit.Test)6