实现的简单放大镜功能,大神绕路
processing吧
全部回复
仅看楼主
level 9
海洋57221 楼主
//拖图进去并重命名为2.jpg
PImage img;
int size =70;
int bei=4;
int x=0 ;
float y=0 ;
int x0 ;
float y0 ;
int i=0;
int j=0;
void setup() {
img = loadImage("2.jpg");
img.resize(500, 0);
size(img.width,img.height);
background(255);
smooth();
}
void draw() {
image (img, 0, 0);
fill(255, 255, 255, 60);
rect(mouseX, mouseY, size, size);
for (i=0; i<=size; i++)
{
for (j=0; j<=size; j++)
{
int loc = (mouseY+j)*img.width +(mouseX+i) ;
float r = red(img.pixels[loc]);
float g = green(img.pixels[loc]);
float b = blue(img.pixels[loc]);
fill(r, g, b, 255);
{
noStroke();
rect(size+mouseX+bei*i, size+mouseY+bei*j, bei, bei);
}
}
}
println("i="+i);
println(j);
}
2014年12月08日 17点12分 1
level 7
copy()函数就能实现吧
2014年12月10日 03点12分 2
大神,你说得对[大拇指]
2014年12月10日 16点12分
level 3
拖进去的图片哪去了?
2014年12月10日 05点12分 3
图片保存在data文件夹里,按ctrl+k或者点sketch
2014年12月10日 16点12分
level 9
海洋57221 楼主
void setup()
{PImage img = loadImage("2.jpg");
size(img.width,img.height);
}
void draw()
{PImage img = loadImage("2.jpg");
image(img, 0, 0, width, height);
copy(mouseX, mouseY, 30, 30, mouseX+40, mouseY+40, 100, 100);
}
2014年12月10日 16点12分 4
level 6
void setup()
{PImage img = loadImage("2.jpg");
size(img.width,img.height);
}
void draw()
{PImage img = loadImage("2.jpg");
image(img, 0, 0, width, height);
copy(mouseX-15, mouseY-15, 30, 30, mouseX+40, mouseY+40, 100, 100);
}
小小的改动,让鼠标指的地方就是放大镜的中心
谢谢楼主分享
2014年12月11日 19点12分 5
[大拇指]
2014年12月12日 03点12分
1