Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ArrayList< int[] > cirPos = new ArrayList<int[]>();
- void setup()
- {
- background(255);
- size(600,600);
- fill(245, 239, 66);
- try{
- readfile();
- refresh();
- }
- catch(Exception e)
- {}
- }
- void draw()
- {
- }
- void mousePressed()
- {
- if (mouseButton == LEFT)
- {
- circle(mouseX , mouseY , 50);
- int[] thisPos = {mouseX , mouseY , 50}; // (x,y,size)
- cirPos.add(thisPos);
- thread("writefile");
- }
- else if (mouseButton == RIGHT)
- {
- double L = 0;
- int[] mousePos = {mouseX,mouseY};
- for (int i = cirPos.size()-1;i>=0;i--)
- {
- L = sqrt(pow(cirPos.get(i)[0] - mousePos[0] , 2) + pow(cirPos.get(i)[1] - mousePos[1] , 2) );
- if (L <= cirPos.get(i)[2])
- {
- cirPos.remove(i);
- thread("writefile");
- refresh();
- }
- }
- }
- }
- void refresh()
- {
- background(255);
- for (int[] n : cirPos)
- {
- circle(n[0] , n[1] , n[2]);
- }
- }
- void writefile()
- {
- JSONArray values = new JSONArray();
- for (int i = 0; i < cirPos.size(); i++) {
- JSONObject eachCir = new JSONObject();
- eachCir.setInt("x", cirPos.get(i)[0]);
- eachCir.setInt("y", cirPos.get(i)[1]);
- eachCir.setInt("size", cirPos.get(i)[2]);
- values.setJSONObject(i, eachCir);
- }
- saveJSONArray(values, "cirPos.json");
- }
- void readfile()
- {
- JSONArray values = loadJSONArray("cirPos.json");
- for (int i = 0; i < values.size(); i++)
- {
- JSONObject eachPos = values.getJSONObject(i);
- int x = eachPos.getInt("x");
- int y = eachPos.getInt("y");
- int size = eachPos.getInt("size");
- int[] oPos = {x , y , size};
- cirPos.add(oPos);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement