All Downloads are FREE. Search and download functionalities are using the official Maven repository.

one.empty3.testscopy.tests.tests2.ballecouleur.TextureImgTache Maven / Gradle / Ivy

There is a newer version: 2024.5.10
Show newest version
/*
 * Copyright (c) 2022-2023. Manuel Daniel Dahmen
 *
 *
 *    Copyright 2012-2023 Manuel Daniel Dahmen
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

/*__
 * *
 * Global license : * CC Attribution
 * 

* author Manuel Dahmen *

* * */ package one.empty3.testscopy.tests.tests2.ballecouleur; import one.empty3.library.ECBufferedImage; import one.empty3.library.Point2D; import one.empty3.library.TextureImg; import java.awt.*; import java.util.HashMap; /*__ * * @author Manuel Dahmen */ public class TextureImgTache extends TextureImg { private final HashMap map; double dist = 0.0; Color actu = null; float actuA; float actuR; float actuG; float actuB; public TextureImgTache(HashMap colors) { super(new ECBufferedImage(100, 100, ECBufferedImage.TYPE_INT_ARGB)); map = colors; } @Override public int getColorAt(double x, double y) { return calculerCouleur(x, y).getRGB(); } public Color calculerCouleur(double x, double y) { final Point2D pData = new Point2D(x, y); actu = new Color(0f, 0f, 0f); final HashMap pond; pond = new HashMap(); map.forEach((u, t) -> { double dist2 = u.distance(pData); pond.put(u, dist2); dist += dist2; } ); pond.forEach((t, u) -> { actuA += map.get(t).getAlpha() / 256f * u; actuR += map.get(t).getRed() / 256f * u; actuG += map.get(t).getGreen() / 256f * u; actuB += map.get(t).getBlue() / 256f * u; actu = new Color((float) (actuR / dist), (float) (actuG / dist), (float) (actuB / dist), (float) (actuA / dist)); }); return actu; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy