日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

processing python模式添加图片_processing学习整理---Image

發布時間:2024/10/8 python 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 processing python模式添加图片_processing学习整理---Image 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、Load and Display(加載與顯示)

Images can be loaded and displayed to the screen at their actual size or any other size.

圖像可以按照其實際尺寸或任何其他尺寸加載并顯示到屏幕。

PImage img; //Declare variable "a" of type PImage

voidsetup() {

size(640, 360);//The image file must be in the data folder of the current sketch//圖片文件必須在當前草稿文件的同一文件夾才能加載成功。//to load successfully

img = loadImage("moonwalk.jpg"); //Load the image into the program

}voiddraw() {//Displays the image at its actual size at point (0,0)

image(img, 0, 0);//Displays the image at point (0, height/2) at half of its size

image(img, 0, height/2, img.width/2, img.height/2);

}

View Code

2、Background Image.?(背景圖片)

This example presents the fastest way to load a background image into Processing. To load an image as the background, it must be the same width and height as the program.

此示例介紹將加載背景圖像的最快方法轉換到Processing。 要加載圖像作為背景,它必須與程序的寬度和高度相同。

PImage bg;inty;voidsetup() {

size(640, 360);//The background image must be the same size as the parameters//into the size() method. In this program, the size of the image//is 640 x 360 pixels.

bg = loadImage("moonwalk.jpg");

}voiddraw() {

background(bg);

stroke(226, 204, 0);

line(0, y, width, y);

y++;if (y >height) {

y= 0;

}

}

View Code

3、透明度。

向左移動,指針對面的形象改變立場。本方案通過用色調()函數修改圖像的α值覆蓋在另一個圖象。

PImage img;float offset = 0;float easing = 0.05;voidsetup() {

size(640, 360);

img= loadImage("moonwalk.jpg"); //Load an image into the program

}voiddraw() {

image(img,0, 0); //Display at full opacity

float dx = (mouseX-img.width/2) -offset;

offset+= dx *easing;

tint(255, 127); //Display at half opacity

image(img, offset, 0);

}

View Code

4、遮罩

為圖像加載“遮罩”以指定圖像不同部分的透明度。 使用Image的mask()方法將兩個圖像混合在一起。

PImage img;

PImage imgMask;voidsetup() {

size(640, 360);

img= loadImage("moonwalk.jpg");

imgMask= loadImage("mask.jpg");

img.mask(imgMask);

imageMode(CENTER);

}voiddraw() {

background(0, 102, 153);

image(img, width/2, height/2);

image(img, mouseX, mouseY);

}

View Code

5、創建圖像。

createImage()函數提供了一個新的像素的緩沖區。 此示例創建圖像漸變。

PImage img;voidsetup() {

size(640, 360);

img= createImage(230, 230, ARGB);for(int i = 0; i < img.pixels.length; i++) {float a = map(i, 0, img.pixels.length, 255, 0);

img.pixels[i]= color(0, 153, 204, a);

}

}voiddraw() {

background(0);

image(img,90, 80);

image(img, mouseX-img.width/2, mouseY-img.height/2);

}

View Code

6、點畫

鼠標水平位置控制點的大小。 使用根據圖像中的像素著色的橢圓創建簡單的點畫效果。

PImage img;intsmallPoint, largePoint;voidsetup() {

size(640, 360);

img= loadImage("moonwalk.jpg");

smallPoint= 4;

largePoint= 40;

imageMode(CENTER);

noStroke();

background(255);

}voiddraw() {float pointillize = map(mouseX, 0, width, smallPoint, largePoint);int x = int(random(img.width));int y = int(random(img.height));

color pix=img.get(x, y);

fill(pix,128);

ellipse(x, y, pointillize, pointillize);

}

View Code

7、請求圖像由Ira Greenberg(從為Flash開發人員處理)。

展示如何使用requestImage()函數與preloader動畫。 requestImage()函數在單獨的線程上加載圖像,以使草圖在加載時不會凍結。 當你加載大圖片時,它非常有用。這些圖像是小的快速下載,但嘗試應該大的圖像,以獲得完整的效果。

int imgCount = 12;

PImage[] imgs= newPImage[imgCount];floatimgW;//Keeps track of loaded images (true or false)

boolean[] loadStates = new boolean[imgCount];//For loading animation

floatloaderX, loaderY, theta;voidsetup() {

size(640, 360);

imgW= width/imgCount;//Load images asynchronously

for (int i = 0; i < imgCount; i++){

imgs[i]= requestImage("PT_anim"+nf(i, 4)+".gif");

}

}voiddraw(){

background(0);//Start loading animation

runLoaderAni();for (int i = 0; i < imgs.length; i++){//Check if individual images are fully loaded

if ((imgs[i].width != 0) && (imgs[i].width != -1)){//As images are loaded set true in boolean array

loadStates[i] = true;

}

}//When all images are loaded draw them to the screen

if(checkLoadStates()){

drawImages();

}

}voiddrawImages() {int y = (height - imgs[0].height) / 2;for (int i = 0; i < imgs.length; i++){

image(imgs[i], width/imgs.length*i, y, imgs[i].height, imgs[i].height);

}

}//Loading animation

voidrunLoaderAni(){//Only run when images are loading

if (!checkLoadStates()){

ellipse(loaderX, loaderY,10, 10);

loaderX+= 2;

loaderY= height/2 + sin(theta) * (height/8);

theta+= PI/22;//Reposition ellipse if it goes off the screen

if (loaderX > width + 5){

loaderX= -5;

}

}

}//Return true when all images are loaded - no false values left in array

booleancheckLoadStates(){for (int i = 0; i < imgs.length; i++){if (loadStates[i] == false){return false;

}

}return true;

}

View Code

總結

以上是生活随笔為你收集整理的processing python模式添加图片_processing学习整理---Image的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。