Skip to content

Instantly share code, notes, and snippets.

@devpruthvi
Created May 11, 2015 15:32
Show Gist options
  • Save devpruthvi/29b864c15de9b147da82 to your computer and use it in GitHub Desktop.
Save devpruthvi/29b864c15de9b147da82 to your computer and use it in GitHub Desktop.
package temp;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Random;
public class temp extends Applet
{
boolean drawCircle = false;
Color[] colArr= new Color[20];
int[][] ballCoords = new int[20][2];
int radius= 50,numClicks=0;
public void initColors()
{
for(int i=0;i<20;i++)
{
Random random = new Random();
float hue = random.nextFloat();
float saturation = (random.nextInt(2000) + 1000) / 10000f;
float luminance = 0.9f;
colArr[i] = Color.getHSBColor(hue, saturation, luminance);
}
}
@Override
public void init() {
initColors();
// TODO Auto-generated method stub
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
int ballX = (int) (Math.random()*500);
int ballY = (int) (Math.random()*500);
ballCoords[numClicks][0] = ballX;
ballCoords[numClicks][1] = ballY;
numClicks++;
repaint();
}
});
}
public void paint(Graphics g)
{
if(numClicks <= 20)
{
for(int i=0;i<numClicks;i++)
{
g.setColor(colArr[i]);
g.fillOval(ballCoords[i][0], ballCoords[i][1], radius, radius);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment