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
void setup() {
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
}
void draw() {
// 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);
}
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;
int y; void setup() {
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");
} void draw() {
background(bg); stroke(226, 204, 0);
line(0, y, width, y); y++;
if (y > height) {
y = 0;
}
}
3、透明度。
向左移动,指针对面的形象改变立场。本方案通过用色调()函数修改图像的α值覆盖在另一个图象。
PImage img;
float offset = 0;
float easing = 0.05; void setup() {
size(640, 360);
img = loadImage("moonwalk.jpg"); // Load an image into the program
} void draw() {
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);
}
4、遮罩
为图像加载“遮罩”以指定图像不同部分的透明度。 使用Image的mask()方法将两个图像混合在一起。
PImage img;
PImage imgMask; void setup() {
size(640, 360);
img = loadImage("moonwalk.jpg");
imgMask = loadImage("mask.jpg");
img.mask(imgMask);
imageMode(CENTER);
} void draw() {
background(0, 102, 153);
image(img, width/2, height/2);
image(img, mouseX, mouseY);
}
5、创建图像。
createImage()函数提供了一个新的像素的缓冲区。 此示例创建图像渐变。
PImage img;
void setup() {
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);
}
}
void draw() {
background(0);
image(img, 90, 80);
image(img, mouseX-img.width/2, mouseY-img.height/2);
}
6、点画
鼠标水平位置控制点的大小。 使用根据图像中的像素着色的椭圆创建简单的点画效果。
PImage img;
int smallPoint, largePoint; void setup() {
size(640, 360);
img = loadImage("moonwalk.jpg");
smallPoint = 4;
largePoint = 40;
imageMode(CENTER);
noStroke();
background(255);
} void draw() {
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);
}
7、请求图像由Ira Greenberg(从为Flash开发人员处理)。
展示如何使用requestImage()函数与preloader动画。 requestImage()函数在单独的线程上加载图像,以使草图在加载时不会冻结。 当你加载大图片时,它非常有用。这些图像是小的快速下载,但尝试应该大的图像,以获得完整的效果。
int imgCount = 12;
PImage[] imgs = new PImage[imgCount];
float imgW; // Keeps track of loaded images (true or false)
boolean[] loadStates = new boolean[imgCount]; // For loading animation
float loaderX, loaderY, theta; void setup() {
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");
}
} void draw(){
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();
}
} void drawImages() {
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
void runLoaderAni(){
// 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
boolean checkLoadStates(){
for (int i = 0; i < imgs.length; i++){
if (loadStates[i] == false){
return false;
}
}
return true;
}
processing学习整理---Image的更多相关文章
- processing学习整理---Structure
1.语法介绍:与java很相近,可以认为就是java. 2.运行命令(linux): processing-java --output=/tmp/processing-xx --run --force ...
- processing学习整理---Input(输入)
1.鼠标1D. 左右移动鼠标可移动天平. “mouseX”变量用于控制矩形的大小和颜色. void setup(){ size(640,360); noStroke(); colorMode(RGB, ...
- dataTables 插件学习整理
在项目中使用了dataTables 插件,学习整理一下. dataTables 的官方中文网站 http://www.datatables.club 引入文件: 所有的都要引入 jq文件 1. dat ...
- js数组学习整理
原文地址:js数组学习整理 常用的js数组操作方法及原理 1.声明数组的方式 var colors = new Array();//空的数组 var colors = new Array(3); // ...
- TweenMax学习整理--特有属性
TweenMax学习整理--特有属性 构造函数:TweenMax(target:Object, duration:Number, vars:Object) target:Object -- 需要缓 ...
- HttpClient学习整理
HttpClient简介HttpClient 功能介绍 1. 读取网页(HTTP/HTTPS)内容 2.使用POST方式提交数据(httpClient3) 3. 处理页面重定向 ...
- !!对python列表学习整理列表及数组详细介绍
1.Python的数组分三种类型:(详细见 http://blog.sina.com.cn/s/blog_6b783cbd0100q2ba.html) (1) list 普通的链表,初始化后可以通过特 ...
- Java设计模式(学习整理)---命令模式
设计模式之Command(学习整理) 1.Command定义 不少Command模式的代码都是针对图形界面的,它实际就是菜单命令,我们在一个下拉菜单选择一个命令时,然后会执行一些动作. 将这些命令封装 ...
- Wix学习整理(5)——安装时填写注册表
原文:Wix学习整理(5)--安装时填写注册表 一 Microsoft操作系统的注册表 什么是注册表? 注册表是Mircrosoft Windows中的一个重要的数据库,用于存储系统和应用程序的设置信 ...
随机推荐
- 1、easyUI-创建 CRUD普通dataGrid(表格)
在实现功能之前,我们要做以下几个准备: 分以下几个步骤:开发工具,easyUI包,目录结构,创建数据库,创建相应的页面视图,后台代码编写,优化: 第一步:开发工具 我的开发工具是Hbuild,开发语言 ...
- Win7 +Cuda9.0+cudnn7.0.5 tensorflow-gpu1.5.0 安装实战
https://blog.csdn.net/gangeqian2/article/details/79358543 https://blog.csdn.net/tomato_sir/article/d ...
- filter和find区别,元素遍历
转 filter和find区别 find()会在当前指定元素中查找符合条件的子元素,是对它的子集操作,而filter()则是在当前指定的元素集合中查找符合条件的元素,是对自身集合元素进行筛选. HTM ...
- 超哥mysql数据库部分blog整理:
总目录:mysql数据库阶段学习目录 https://www.cnblogs.com/clschao/articles/10065275.html Day1. 1.数据库初识 https://www. ...
- Linux学习拾遗
一.安装iso文件 首先建立一个目录作为挂载点:# mkdir /mnt/iso 获得root权限然后使用下面的参数挂载ISO映像文件:# mount -t iso9660 /path/image.i ...
- 接口测试工具 — postman(post请求)
1.登录接口 2.添加学生信息,这个接口是用来讲入参是json类型的 3.学生金币充值接口,这个接口是为了讲添加cookie以及身份验证的 4.上传文件接口
- 0x03 MySQl 库操作
一 系统数据库 information_schema: 虚拟库,不占用磁盘空间,存储的是数据库启动后的一些参数,如用户表信息.列信息.权限信息.字符信息等performance_schema: MyS ...
- hadoop学习第四天-Writable和WritableComparable序列化接口的使用&&MapReduce中传递javaBean的简单例子
一. 为什么javaBean要继承Writable和WritableComparable接口? 1. 如果一个javaBean想要作为MapReduce的key或者value,就一定要实现序列化,因为 ...
- 剑指offer 面试37题
面试37题: 题:序列化二叉树 题目:请实现两个函数,分别用来序列化和反序列化二叉树 解题思路:首先来看二叉树的序列化,二叉树的序列化就是采用前序遍历二叉树输出节点,再碰到左子节点或者右子节点为Non ...
- Overload and Override without Overwrite - Java
Override(覆盖/覆写): 子类Override父类中的函数(方法).Overload(重载): 同一个类中包含多个同名的函数(方法), 但各个函数的参数列表不同. Override和Overl ...