I'm looking to multiply an image when it touches another image
thank you
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Ball05 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Ball05 extends Actor
{
private int SIZE = 400;
private int a = SIZE/2;
private int b = a;
private int diameter = 4 * SIZE / 5;
private int n = 12;
public void act()
{
addBall05();
}
public void addBall05()
{
GreenfootImage img = new GreenfootImage(SIZE, SIZE);
img.setColor(Color.BLACK);
int m = Math.min(a, b);
diameter = 4 * m / 5;
int r2 = Math.abs(m - diameter) / 2;
img.drawOval(a - diameter, b - diameter, 2 * diameter, 2 * diameter);
img.setColor(Color.BLUE);
for (int i = 0; i < n; i++)
{
double angle = 2 * Math.PI * i / n;
int x = (int) Math.round(a + diameter * Math.cos(angle));
int y = (int) Math.round(b + diameter * Math.sin(angle));
img.fillOval(x - r2, y - r2, 2 * r2, 2 * r2);
}
setImage(img);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Ball04 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Ball04 extends Actor
{
private int size = 400;
private int a = size/2;
private int b = a;
private int r = 4 * size / 5;
private int n = 12;
public void act()
{
drawImg();
}
public void drawImg()
{
GreenfootImage img = new GreenfootImage(size, size);
img.setColor(Color.BLACK);
int m = Math.min(a, b);
r = 4 * m / 5;
int r2 = Math.abs(m - r) / 2;
img.drawOval(a - r, b - r, 2 * r, 2 * r);
//img.setColor(Color.BLUE);
for (int i = 0; i < n; i++)
{
double t = 2 * Math.PI * i / n;
int x = (int) Math.round(a + r * Math.cos(t));
int y = (int) Math.round(b + r * Math.sin(t));
getWorld().addObject(new Ball04(), x+100, y+100);
//img.fillOval(x - r2, y - r2, 2 * r2, 2 * r2);
}
setImage(img);
}
}
// in constructor
public MyWorld()
{
super(600, 400, 1);
addObject(new Ball(), 50, 50); // "this." is implicitly understood
}
/* ********************** */
// in a method called by constructor
public MyWorld()
{
super(600, 400, 1);
prepare(); // "this." is implicitly understood
}
private void prepare()
{
Ball ball = new Ball();
addObject(ball, 0, 0); // "this." is implicitly understood
ball.setLocation(50, 50);
}
/* *********************** */
// in act method
if (this.getObjects(Ball.class).isEmpty()) this.addObject(new Ball(), 50, 50);import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Ball04 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Ball04 extends Actor
{
private static final int SIZE = 400;
private int a = SIZE/2;
private int b = a;
private int r = 4 * SIZE / 5;
private int n = 12;
public void act()
{
paintComponent();
}
public void paintComponent()
{
GreenfootImage img = new GreenfootImage(SIZE, SIZE);
img.setColor(Color.BLACK);
int m = Math.min(a, b);
r = 4 * m / 5;
int r2 = Math.abs(m - r) / 2;
img.drawOval(a - r, b - r, 2 * r, 2 * r);
//img.setColor(Color.BLUE);
for (int i = 0; i < n; i++)
{
double t = 2 * Math.PI * i / n;
int x = (int) Math.round(a + r * Math.cos(t));
int y = (int) Math.round(b + r * Math.sin(t));
if(getWorld().getObjects(Ball06.class).isEmpty())
{
getWorld().addObject(new Ball06(), x+100, y+100);
}
//img.fillOval(x - r2, y - r2, 2 * r2, 2 * r2);
}
setImage(img);
}
}