Created
July 13, 2020 09:51
-
-
Save usbharu/40b281b1875360e2fc6e3e2cabf4cb0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Date; | |
import java.awt.event.MouseListener; | |
import java.awt.event.MouseEvent; | |
import java.awt.Component; | |
import java.awt.event.MouseWheelEvent; | |
import java.awt.event.MouseWheelListener; | |
int partid=-1; | |
static int rightid=0; | |
boolean mouse_flg=false; | |
ArrayList<part> part; | |
ArrayList<image_list> il; | |
// menu_bar mp; | |
Menu mp; | |
Wheel m; | |
// image_list il = new image_list(); | |
String[] filenames; | |
static int ofset_x,ofset_y; | |
static int set_deg; | |
static boolean remove_flg; | |
int f=0,mouse_of_x,mouse_of_y; | |
int grid_s=10; | |
void setup(){ | |
String path = "/home/haru/parts/"; | |
filenames = listFileNames(path); | |
java.util.Arrays.sort(filenames); | |
size(600,400); | |
part = new ArrayList<part>(); | |
il = new ArrayList<image_list>(); | |
for(int i=0;i<filenames.length;i++){ | |
String filename=path+filenames[i]; | |
il.add(new image_list()); | |
il.get(i).remake(63,63,80,80,0,0,250,400,filename); | |
} | |
Component component = (Component) this.surface.getNative(); //クラスの中でMouseEventを使うおまじない | |
component.addMouseListener(new Menu(this)); | |
component.addMouseWheelListener(new mouseWheel()); | |
mp = new Menu(this); | |
m=new Wheel(); | |
} | |
void draw() { | |
background(187,201,158); | |
il.get(f).scrool(ofset_x,ofset_y); | |
il.get(f).redraw(); | |
// il.scrool(ofset_x,ofset_y); | |
// il.redraw(); | |
if(remove_flg==true){ | |
if (rightid!=-1){ | |
part.remove(rightid); | |
} | |
remove_flg=false; | |
} | |
for(int i=0;i<part.size();i++){ | |
if (rightid==i){ | |
if(set_deg!=-1){ | |
println("rightid",rightid); | |
part.get(i).turn(set_deg); | |
set_deg=-1; | |
rightid=-1; | |
} | |
} | |
part.get(i).redraw_parts(); | |
} | |
// println(partid); | |
if (partid!=-1){ | |
fill(255,255,255,0); | |
if(part.get(partid).deg==0){ | |
rect(mX()-part.get(partid).ofset_x+mouse_of_x,mY()+mouse_of_y-part.get(partid).ofset_y,part.get(partid).size_x,part.get(partid).size_y); | |
}else if(part.get(partid).deg==1){ | |
rect(mX()+part.get(partid).ofset_y+mouse_of_x-part.get(partid).size_y,mY()-part.get(partid).ofset_x+mouse_of_y,part.get(partid).size_y,part.get(partid).size_x); | |
}else if(part.get(partid).deg==2){ | |
rect(mX()-part.get(partid).size_x+part.get(partid).ofset_x+mouse_of_x,mY()-part.get(partid).size_y+part.get(partid).ofset_y+mouse_of_y,part.get(partid).size_x,part.get(partid).size_y); | |
}else if(part.get(partid).deg==3){ | |
rect(mX()-part.get(partid).ofset_y+mouse_of_x,mY()-part.get(partid).size_x+part.get(partid).ofset_x+mouse_of_y,part.get(partid).size_y,part.get(partid).size_x); | |
} | |
fill(255,255,255); | |
} | |
} | |
void mousePressed(){ | |
if (mouseButton == LEFT){ | |
if (il.get(f).push_b()==-1){ | |
for(int i=0;i<part.size();i++){ | |
if(part.get(i).poscheck()==true){ | |
partid=i; | |
set_deg=-1; | |
mouse_of_x=part.get(i).pos_x-mX(); | |
mouse_of_y=part.get(i).pos_y-mY(); | |
break; | |
}else{ | |
partid=-1; | |
set_deg=-1; | |
} | |
} | |
}else{ | |
part.add(new part()); | |
part.get(part.size()-1).new_parts(0,"dd",il.get(f).push_n(il.get(f).push_b()),mX(),mY()); | |
partid=part.size()-1; | |
} | |
}else if(mouseButton==RIGHT){ | |
for(int i=0;i<part.size();i++){ | |
if(part.get(i).poscheck()==true){ | |
set_deg=-1; | |
rightid=i; | |
break; | |
}else{ | |
set_deg=-1; | |
rightid=-1; | |
} | |
} | |
} | |
} | |
void mouseReleased(){ | |
if (partid!=-1){ | |
part.get(partid).move_parts(mX()+mouse_of_x,mY()+mouse_of_y); | |
partid=-1; | |
} | |
} | |
// void mouseWheel(MouseWheelEvent e){ | |
// if (keyPressed == false){ | |
// if( e.getAmount() < 0 ){ | |
// ofset_y = ofset_y + 15; | |
// } else { | |
// ofset_y = ofset_y - 15; | |
// } | |
// }else{ | |
// if( e.getAmount() < 0 ){ | |
// ofset_x = ofset_x + 15; | |
// } else { | |
// ofset_x = ofset_x - 15; | |
// } | |
// } | |
// } | |
void mouseWheel() { | |
println(m.a); | |
} | |
String[] listFileNames(String dir) { | |
File file = new File(dir); | |
if (file.isDirectory()) { | |
String names[] = file.list(); | |
return names; | |
} else { | |
return null; | |
} | |
} | |
void keyPressed(){ | |
switch(key){ | |
case '1': | |
f=0; | |
break; | |
case '2': | |
f=1; | |
break; | |
case '3': | |
f=2; | |
break; | |
case '4': | |
f=3; | |
break; | |
case '5': | |
f=4; | |
break; | |
case '6': | |
f=5; | |
break; | |
case '7': | |
f=6; | |
break; | |
case '8': | |
f=7; | |
break; | |
case '9': | |
f=8; | |
break; | |
case '0': | |
f=10; | |
break; | |
case '': | |
break; | |
default: | |
f=19; | |
break; | |
} | |
println(key); | |
println(filenames[f]); | |
println(f); | |
} | |
int mX() { | |
int p; | |
p= mouseX-mouseX%grid_s; | |
return p; | |
} | |
int mY(){ | |
int p; | |
p = mouseY-mouseY%grid_s; | |
return p; | |
} | |
// | |
static public class mouseWheel implements MouseWheelListener { | |
mouseWheel(){} | |
@Override | |
public void mouseWheelMoved(MouseWheelEvent e) { | |
//マウスホイールが回された時 | |
if ( e.getWheelRotation() == -1 ) { | |
ofset_y=ofset_y+15; | |
} else if (e.getWheelRotation() == 1) { | |
ofset_y=ofset_y-15; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class image_list{ | |
int kazu,tasu,k,l_w,w,h,s_w,s_h,ofset_x,ofset_y,file_num,pos_x,pos_y,size_x,size_y; | |
String folder; | |
String[] extensions = {".jpg",".gif",".bmp",".png"}; | |
File[] files; | |
String[] filesbmp; | |
String[] filesname; | |
ArrayList<PImage>images=new ArrayList<PImage>(); | |
image_list(){ | |
} | |
void redraw(){ | |
rect(pos_x,pos_y,size_x,size_y); | |
k=0; | |
kazu=file_num; | |
if (kazu%l_w!=0){ | |
tasu=1; | |
} | |
for(int i=0;i<kazu/l_w;i++){ | |
for(int j=0;j<l_w;j++){ | |
if ((pos_y<=i*s_h+ofset_y+pos_y+h)&&(pos_x<=j*s_w+ofset_x+pos_x+w)&&(pos_y+size_y>=i*s_h+ofset_y+pos_y)&&(pos_x+size_x>=j*s_w+ofset_x+pos_x)){ | |
rect(j*s_w+ofset_x+pos_x,i*s_h+ofset_y+pos_y,w,h); | |
image(images.get(k),j*s_w+ofset_x+pos_x,i*s_h+ofset_y+pos_y); | |
fill(0); | |
text(filesname[k],j*s_w+ofset_x+pos_x+w-w/2,i*s_h+ofset_y+pos_y+h+10); | |
fill(255); | |
} | |
k++; | |
} | |
} | |
for(int n=0;n<kazu%l_w;n++){ | |
if ((pos_y<=kazu/l_w*s_h+ofset_y+pos_y+h)&&(pos_x<=n*s_w+ofset_x+pos_x+w)&&(pos_y+size_y>=kazu/l_w*s_h+ofset_y+pos_y)&&(pos_x+size_x>=n*s_w+ofset_x+pos_x)){ | |
rect(n*s_w+ofset_x+pos_x,kazu/l_w*s_h+ofset_y+pos_y,w,h); | |
image(images.get(k),n*s_w+ofset_x+pos_x,kazu/l_w*s_h+ofset_y+pos_y); | |
} | |
k++; | |
} | |
} | |
void move(int p_x,int p_y){ | |
pos_x=p_x; | |
pos_y=p_y; | |
} | |
void scrool(int of_x,int of_y){ | |
ofset_x=of_x; | |
ofset_y=of_y; | |
} | |
void remake(int img_w,int img_h,int box_w,int box_h,int p_x,int p_y,int s_x,int s_y,String directory){ | |
images.clear(); | |
w=img_w; | |
h=img_h; | |
s_w=box_w; | |
s_h=box_h; | |
pos_x=p_x; | |
pos_y=p_y; | |
size_x=s_x; | |
size_y=s_y; | |
l_w=size_x/box_w; | |
// folder=directory.getAbsolutePath(); | |
int a=0; | |
textAlign(CENTER); | |
println(directory); | |
files = listFiles(directory); | |
java.util.Arrays.sort(files); | |
println(files.length); | |
filesbmp = new String[files.length]; | |
filesname = new String[files.length]; | |
for(int i= 0; i< files.length; i++){ | |
for(String extension : extensions){ | |
if(files[i].getPath().endsWith(extension)){ | |
PImage img = loadImage(files[i].getAbsolutePath()); | |
filesbmp[a] = files[i].getAbsolutePath(); | |
filesname[a] = files[i].getName(); | |
// println(files[i].getAbsolutePath()); | |
if ((img.width >= w) || (img.height >= h)) { | |
if (img.width >= img.height){ | |
img.resize(w,0); | |
}else{ | |
img.resize(0,h); | |
} | |
} | |
images.add(img); | |
a++; | |
} | |
} | |
} | |
file_num=a; | |
} | |
int push_b(){ | |
int l=-1; | |
int g=0; | |
for(int i=0;i<kazu/l_w;i++){ | |
for(int j=0;j<l_w;j++){ | |
if ((mouseX>=j*s_w+ofset_x+pos_x)&&(mouseY>=i*s_h+ofset_y+pos_y)&&(mouseX<=j*s_w+ofset_x+pos_x+w)&&(mouseY<=i*s_h+ofset_y+pos_y+h)&&(mouseX>=pos_x)&&(mouseY>=pos_y)&&(mouseX<=pos_x+size_x)&&(mouseY<=pos_y+size_y)){ | |
l=g; | |
} | |
g++; | |
} | |
} | |
for(int n=0;n<kazu%l_w;n++){ | |
if ((mouseX>=n*s_w+ofset_x+pos_x)&&(mouseY>=kazu/l_w*s_h+ofset_y+pos_y)&&(mouseX<=n*s_w+ofset_x+pos_x+w)&&(mouseY<=kazu/l_w*s_h+ofset_y+pos_y+h)&&(mouseX>=pos_x)&&(mouseY>=pos_y)&&(mouseX<=pos_x+size_x)&&(mouseY<=pos_y+size_y)){ | |
l=g; | |
} | |
g++; | |
} | |
return l; | |
} | |
String push_n(int a){ | |
return filesbmp[a]; | |
// println(files[a].getAbsolutePath()); | |
// return "https://blog-imgs-141.fc2.com/h/a/r/harujisaku/20200610070849042.png"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class part{ | |
int size_x,size_y,pos_x,pos_y,deg,ofset_x,ofset_y; | |
PImage photo; | |
part(){ | |
} | |
void new_parts(int _deg,String gloup,String path,int ps_x,int ps_y) { | |
photo = loadImage(path); | |
pos_x=ps_x; | |
pos_y=ps_y; | |
size_x=photo.width; | |
size_y=photo.height; | |
ofset_x=serch_point_x(photo.width,photo.height); | |
ofset_y=serch_point_y(photo.width,photo.height); | |
if(_deg!=-1){ | |
deg=_deg; | |
} | |
redraw_parts(); | |
} | |
void move_parts(int ps_x,int ps_y){ | |
pos_x=ps_x; | |
pos_y=ps_y; | |
redraw_parts(); | |
} | |
void redraw_parts() { | |
pushMatrix(); | |
translate(pos_x,pos_y); | |
rotate(radians(deg*90)); | |
image(photo,0-ofset_x,0-ofset_y); | |
popMatrix(); | |
} | |
void print_variable() { | |
println(deg); | |
println(pos_x); | |
println(pos_y); | |
println(ofset_x); | |
println(ofset_y); | |
} | |
boolean _poscheck() { | |
if ((deg==0)||(deg==2)){ | |
if ((mouseX>=pos_x-ofset_x)&&(mouseY>=pos_y-ofset_y)&&(mouseX<=pos_x+size_x-ofset_x)&&(mouseY<=pos_y+size_y-ofset_y)){ | |
return true; | |
}else{ | |
return false; | |
} | |
}else{ | |
if ((mouseX>=pos_x+size_x/2-size_y/2-ofset_x)&&(mouseY>=pos_y+size_y/2-size_x/2-ofset_y)&&(mouseX<=pos_x+size_x/2+size_y/2-ofset_x)&&(mouseY<=pos_y+size_y/2+size_x/2-ofset_y)){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
} | |
boolean poscheck(){ | |
if (deg==0){ | |
if((mouseX>=pos_x-ofset_x)&&(mouseY>=pos_y-ofset_y)&&(mouseX<=pos_x+size_x-ofset_x)&&(mouseY<=pos_y+size_y-ofset_y)){ | |
return true; | |
}else{ | |
return false; | |
} | |
}else if(deg==1){ | |
if((mouseX>=pos_x-size_y+ofset_y)&&(mouseY>=pos_y-ofset_x)&&(mouseX<=pos_x+ofset_y)&&(mouseY<=pos_y+size_x-ofset_x)) { | |
return true; | |
}else{ | |
return false; | |
} | |
}else if(deg==2){ | |
if((mouseX>=pos_x-size_x-ofset_x)&&(mouseY>=pos_y-size_y+ofset_y)&&(mouseX<=pos_x+ofset_x)&&(mouseY<=pos_y+ofset_y)){ | |
return true; | |
}else{ | |
return false; | |
} | |
}else if(deg==3){ | |
if((mouseX>=pos_x-ofset_y)&&(mouseY>=pos_y-size_x+ofset_x)&&(mouseX<=pos_x-ofset_x+size_y)&&(mouseY<=pos_y-ofset_y+size_x)){ | |
return true; | |
}else{ | |
return false; | |
} | |
}else{ | |
return false; | |
} | |
} | |
int serch_point_x(int w,int h) { | |
int f=0; | |
int d2=0; | |
for (int d=0 ; d<w ; d++) { | |
for (int i=0 ; i<h ; i++){; | |
color c = photo.get(d,i); | |
if ((red(c)>240)&&(green(c)<=20)&&(blue(c)<=20)) { | |
f++; | |
if (f==1) { | |
d2=d; | |
return d; | |
}}}} | |
return d2; | |
} | |
int serch_point_y(int w, int h) { | |
int f=0; | |
int i2=0; | |
for (int d=0 ; d<w ; d++) { | |
for (int i=0 ; i<h ; i++){ | |
color c = photo.get(d,i); | |
if ((red(c)>240)&&(green(c)<=20)&&(blue(c)<=20)) { | |
f++; | |
if (f==1) { | |
i2=i; | |
return i; | |
}}}} | |
return i2; | |
} | |
void turn(int adeg){ | |
if(adeg==-1){ | |
}else{ | |
deg=adeg; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment