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中的一个重要的数据库,用于存储系统和应用程序的设置信 ...
随机推荐
- MySQL索引使用:字段为varchar类型时,条件要使用''包起来
结论: 当MySQL中字段为int类型时,搜索条件where num='111' 与where num=111都可以使用该字段的索引.当MySQL中字段为varchar类型时,搜索条件where nu ...
- 拍照权限,GPS权限的控制
最近项目中会遇到一些手机用户权限的问题,从网上百度了一下,发现有一些方法不能解决判断用户权限的是否开关,下面我就介绍两种权限的判断 1 拍照的权限控制 public static boolean is ...
- jmeter通过json extrcator或者正则表达式获取json返回信息
1.下载地址,及插件文档资料 https://jmeter-plugins.org/wiki/JSONPathExtractor/ json信息如下 { "error_code": ...
- EasyNVR智能云终端硬件使用场景分析:如何实现软硬一体的视频上云整体解决方案
背景分析 在于众多的客户交流中,经常会被客户问到,"EasyNVR到底是软件还是硬件?"."EasyNVR能否出一个硬件的版本,摆脱自建服务器的压力?".&qu ...
- 图片上传JS插件梳理与学习
项目的oper端和seller端,用了两个不同插件,简单了解一下: 一.seller端:AjaxUpload.js seller端使用的是 AjaxUpload.js ,封装好的一个库.调用时传入参数 ...
- 单片机c语言教程:C51循环语句
单片机c语言教程第十三课 C51循环语句 循环语句是几乎每个程序都会用到的,它的作用就是用来实现需要反复进行多次的操 作.如一个 12M 的 51 芯片应用电路中要求实现 1 毫秒的延时,那么就要执行 ...
- Magic Cast Method in Java Magic Trick In Java
https://www.atlassian.com/blog/archives/magic_trick_in_java https://www.gamlor.info/wordpress/2010/1 ...
- Nuxt使用Vuex
Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化. 基础知识这里不再重述,学习的话请自行到官网 ...
- Django的models方法返回值异常,待解决
class BookInfo(models.Model): #创建书本信息类,继承models.Model booktitle=models.CharField(max_length=20) book ...
- Django 之 URL(路由)分发机制
本质 (1):它的本质是 URL 模式以及要为该 URL 模式调用的视图函数之间的映射表. django-admin.py startproject 运行时,该脚本会自动为你建了一份 URLconf( ...