第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

處理代碼-觸摸屏橡皮擦代碼

處理代碼-觸摸屏橡皮擦代碼

牛魔王的故事 2022-07-27 11:35:21
當(dāng)我向我的講師詢問關(guān)于一個小組項目的一段代碼的建議時,我被帶到了這個論壇。一般的想法是有兩個圖像在彼此的頂部,用戶可以擦掉頂部的圖像以顯示下面的圖像。使用該論壇中的其他一些項目,我已經(jīng)設(shè)法使基礎(chǔ)知識運行起來,但是一旦用戶放開鼠標(biāo),我就很難將代碼放到起點。我也將不勝感激有關(guān)如何將其轉(zhuǎn)換為使用觸摸屏的任何建議。我查看了處理應(yīng)用程序中的多點觸控代碼,但是它不允許我向其中添加圖像,如果我嘗試使用計算機軟件,它似乎不喜歡多點觸控。有沒有辦法解決?我目前擁有的代碼如下,如果有任何建議或意見,我將不勝感激 - 提前致謝!PImage img, front;int xstart, ystart, xend, yend;int ray;void setup(){    size(961, 534);    img = loadImage("back.jpg");    front = loadImage("front.jpg");    xstart = 0;    ystart = 0;    xend = img.width;    yend = img.height;    ray = 50;}void draw() {    {        img.loadPixels();        front.loadPixels();        // loop over image pixels         for (int x = xstart; x < xend; x++)        {            for (int y = ystart; y < yend; y++ )            {                int loc = x + y*img.width;                float dd = dist(mouseX, mouseY, x, y);                        // pixels distance less than ray                  if (mousePressed && dd < 50)                {                    // set equal pixel                    front.pixels[loc] = img.pixels[loc];                }                else                {                    if (!mousePressed)                    {                      // reset- this is what I have not been able to work as of yet                      front.pixels[loc] =   ;                    }                }            }        }        img.updatePixels();        front.updatePixels();        // show front image        image(front, 0, 0);    }    }
查看完整描述

1 回答

?
慕蓋茨4494581

TA貢獻1850條經(jīng)驗 獲得超11個贊

我建議使用蒙版而不是更改圖像的像素。創(chuàng)建一個空圖像并將其作為掩碼關(guān)聯(lián)到圖像:


img = loadImage("back.jpg");

front = loadImage("front.jpg");

mask = createImage(img.width, img.height, RGB);

img.mask(mask);

如果您現(xiàn)在繪制兩個圖像,那么您只能“看到”front圖像:


image(front, 0, 0);

image(img, 0, 0);

設(shè)置遮罩的顏色 (255, 255, 255) 而不是改變 的像素front:


mask.pixels[loc] = color(255, 255, 255);

并將蒙版重新應(yīng)用于圖像


img.mask(mask);

釋放鼠標(biāo)按鈕時,必須將遮罩的像素改回 (0, 0, 0) 或簡單地創(chuàng)建一個新的空遮罩:


mask = createImage(img.width, img.height, RGB);

請參閱我將建議應(yīng)用于您的原始代碼的示例:


PImage img, front, mask;

int xstart, ystart, xend, yend;

int ray;


void setup() {

    size(961, 534);


    img = loadImage("back.jpg");

    front = loadImage("front.jpg");

    mask = createImage(img.width, img.height, RGB);

    img.mask(mask);


    xstart = 0;

    ystart = 0;

    xend = img.width;

    yend = img.height;

    ray = 50;

}


void draw() {

    img.loadPixels();

    front.loadPixels();


    // loop over image pixels 

    for (int x = xstart; x < xend; x++) {

        for (int y = ystart; y < yend; y++ ) {

            int loc = x + y*img.width;

            float dd = dist(mouseX, mouseY, x, y);        


            if (mousePressed && dd < 50) {

                mask.pixels[loc] = color(255, 255, 255);

            }

            else {

                if (!mousePressed) {

                    //mask = createImage(img.width, img.height, RGB);

                    mask.pixels[loc] = color(0, 0, 0);

                }

            }

        }

    }

    mask.updatePixels();

    img.mask(mask);


    // show front image

    image(front, 0, 0);

    image(img, 0, 0);

}    


查看完整回答
反對 回復(fù) 2022-07-27
  • 1 回答
  • 0 關(guān)注
  • 116 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號