void setup() {
size(500, 500);
}
int x=-1, y=-1;
void draw() {
if (x!=-1) {
ellipse(x, y, 1, 1);
y++;//往下滴(x,y)座標中y慢慢變大,就是往下的感覺
}
}
void mouseDragged() { //按下右鍵,才會滴水滴
if (mouseButton==LEFT)line(mouseX, mouseY, pmouseX, pmouseY);
if (mouseButton==RIGHT) {
x=mouseX;
y=mouseY;
}
}
void setup(){
size(500,500);
background(255);//背景設成白色
}
void draw(){
//pixels
}
void mouseDragged(){
if(mouseButton==LEFT){//左鍵拖曳
line(mouseX,mouseY,pmouseX,pmouseY);
loadPixels();//取出畫面的像素
for(int i=1; i<width*height; i++){//全部的點,都循一下色彩
if(pixels[i] != -1)pixels[i]=color(random(255),random(255),random(255));
}//如果不是白色就是有畫圖碰到的pixels,都變成亂數的彩色
}
}
}
沒加 background(255);//點擊會變彩色
PImage img;
void setup() {
size(500, 500);
img = createImage(500, 500, RGB);//用來畫圖的畫布
img.loadPixels();
for (int i=0; i<500*500; i++)img.pixels[i] = color(#FFFFF2);//-14
img.updatePixels();
}
int x=250, y=0;
void draw() {
background(img);
ellipse(x, y, 20, 20);
if (img.pixels[x+y*250]==-14)y++;
}
void mouseDragged() {
background(img);
line(mouseX, mouseY, pmouseX, pmouseY);
loadPixels();//取出畫面的像素
img.loadPixels();
for (int i=0; i<500*500; i++) img.pixels[i]=pixels[i];//把畫面色彩,搬到img裡
img.updatePixels();
updatePixels();
}
PImage img;
void setup() {
size(500, 500);
img = createImage(500, 500, RGB);//用來畫圖的畫布
}//換黑背景,可以用mouse刮出彩色的線條
//int x=250, y=0;
ArrayList<PVector> p = new ArrayList<PVector>();//很多個點p
void draw() {
background(img);
for (PVector pp : p) {
ellipse(pp.x, pp.y, 20, 20);
if (pp.y<498 && img.pixels[int(pp.x)+int(pp.y)*500]==-16777216)pp.y++;
}
//if (y<498 && img.pixels[x+y*250]==-16777216)y++;
}
void mouseDragged() {
background(img);
stroke(random(255), random(255), random(255));
line(mouseX, mouseY, pmouseX, pmouseY);
loadPixels();
img.loadPixels();
for (int i=0; i<500*500; i++) img.pixels[i]=pixels[i];//把畫面色彩,搬到img裡
img.updatePixels();
updatePixels();
for (PVector pp : p) {
ellipse(pp.x, pp.y, 20, 20);
}
}
void mousePressed(){
if(mouseButton==RIGHT){
p.add(new PVector(mouseX,mouseY));
}
}
void setup() {
size(500, 500);
background(#FFFFF2);
}
void draw() {
if (mousePressed && mouseButton==LEFT) line(mouseX, mouseY, pmouseX, pmouseY);
if (mousePressed && mouseButton==RIGHT) {
loadPixels();//把畫面,讀入pixels[]陣列裡
color c1 = pixels[mouseX+mouseY*500];//原本的色彩
color c2 = color(random(255), random(255), random(255));//亂數色彩
if (c1!=c2)myFloodFill(mouseX, mouseY, c1, c2);
updatePixels();//把陣列的數值,放回畫面
}
}
boolean isOk(int x, int y, color c1) {
if (x<0 || y<0 || x>=500 || y>=500)return false;//超過邊界,不能做
if (pixels[x+y*500]!=c1)return false;//色彩原本的c1色彩不同,就不要變色
return true;
}
void myFloodFill(int x,int y, color c1, color c2) {
pixels[x+y*500]=c2;//這一格,設成新色彩
if (isOK(x+1, y, c1))myFloodFill(x+1, y, c1, c2);//試右邊,色彩對嗎
if (isOK(x-1, y, c1))myFloodFill(x-1, y, c1, c2);//試左邊,色彩對嗎
if (isOK(x, y+1, c1))myFloodFill(x, y+1, c1, c2);
if (isOK(x, y-1, c1))myFloodFill(x, y-1, c1, c2);
}//不要點太大區域,因為函式呼叫函式太多層,會被警告出錯
void setup(){
size(500,500);
PImage img = loadImage("234.png");
cursor(img);
}
void draw(){
background(#FFFFF2);
}
截圖看不到鼠標-->

<--
PImage img234,img123;
void setup(){
size(500,500);
img234 = loadImage("234.png");
img123 = loadImage("123.png");
cursor(img123);
}
void draw(){
background(#FFFFF2);
if(frameCount%120==0)cursor(img123);
if(frameCount%120==60)cursor(img234);
}

PImage img234,img123;
void setup(){
size(500,500);
img234 = loadImage("234.png");
img123 = loadImage("123.png");
img123 = img234;
}
void draw(){
background(#FFFFF2);
imageMode(CENTER);
image(img123,mouseX,mouseY);
imageMode(CENTER);
if(frameCount%120==0)cursor(img123);
if(frameCount%120==60)cursor(img234);
}
沒有留言:
張貼留言