“Image Crossfader” by Dread-Eye
https://openprocessing.org/sketch/946179
License CreativeCommons Attribution ShareAlike
https://creativecommons.org/licenses/by-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
Play with Sliders and Buttons. Press Spacebar to Export PNG.
CC Attribution ShareAlike
Image Crossfader
xxxxxxxxxx
//Image Crossfader by Dread-Eye:
//https://www.openprocessing.org/sketch/946179
//With "The Starry Night" by Vincent Van Gogh
//and "The Great Wave Off Kanagawa" by Katsushika Hokusai
//Press Spacebar to Export PNG
let image1, image2;
let red, green, black, white, blue, yellow;
let play1Button, play2Button, invert1Button, invert2Button, blendButton;
let play1Color, play2Color, invert1Color, invert2Color, blendColor;
let invert1State, invert2State;
let xfadeSlider, tint1Slider, tint2Slider;
let xfadeValue, tint1Value, tint2Value;
function preload(){
image1 = loadImage("starryNight.png");
image2 = loadImage("underTheWave.png");
}
function setup() {
createCanvas(600, 400);
red = color(200, 0, 0);
green = color(0, 200, 0);
black = color(15);
white = color(240);
blue = color(50, 150, 255);
yellow = color(200, 200, 0);
play1Color = green;
play2Color = green;
invert1Color = white;
invert2Color = white;
blendColor = blue;
play1Button = true;
play2Button = true;
invert1Button = false;
invert2Button = false;
blendButton = true
invert1State = true;
invert2State = true;
blendState = true;
xfadeSlider = createSlider(0, 255, 127);
xfadeSlider.position(200, 350);
xfadeSlider.style('width', '200px');
let d1 = createDiv();
d1.style('transform: rotate(-90deg);');
d1.position(-25, 170);
tint1Slider = createSlider(0, 255, 255);
tint1Slider.style('width', '150px');
d1.child(tint1Slider);
let d2 = createDiv();
d2.style('transform: rotate(-90deg);');
d2.position(475, 170);
tint2Slider = createSlider(0, 255, 255);
tint2Slider.style('width', '150px');
d2.child(tint2Slider);
}
function draw() {
background(100);
xfadeValue = xfadeSlider.value();
tint1Value = tint1Slider.value();
tint2Value = tint2Slider.value();
drawButtons();
drawImage();
xfadeImage = get(100, 50, 400, 268);
}
function mousePressed() {
let d1 = dist(mouseX, mouseY, 50, 350);
let d2 = dist(mouseX, mouseY, 550, 350);
let d3 = dist(mouseX, mouseY, 50, 50);
let d4 = dist(mouseX, mouseY, 550, 50);
let d5 = dist(mouseX, mouseY, 480, 360);
if (d1 < 20) {
if (play1Button) {
play1Color = red;
play1Button = false;
}
else {
play1Color = green;
play1Button = true;
}
}
if (d2 < 20) {
if (play2Button) {
play2Color = red;
play2Button = false;
}
else {
play2Color = green;
play2Button = true;
}
}
if (d3 < 10) {
if (invert1Button) {
invert1Color = white;
invert1Button = false;
}
else {
invert1Color = black;
invert1Button = true;
}
}
if (d4 < 10) {
if (invert2Button) {
invert2Color = white;
invert2Button = false;
}
else {
invert2Color = black;
invert2Button = true;
}
}
if (d5 < 10) {
if (blendButton) {
blendColor = yellow;
blendButton = false;
}
else {
blendColor = blue;
blendButton = true;
}
}
}
function drawButtons() {
strokeWeight(2);
stroke(0);
fill(play1Color);
ellipse(50, 350, 40, 40);
strokeWeight(2);
stroke(0);
fill(play2Color);
ellipse(550, 350, 40, 40);
strokeWeight(2);
stroke(0);
fill(invert1Color);
ellipse(50, 50, 20, 20);
strokeWeight(2);
stroke(0);
fill(invert2Color);
ellipse(550, 50, 20, 20);
strokeWeight(2);
stroke(0);
fill(blendColor);
ellipse(480, 360, 20, 20);
}
function drawImage() {
push();
if (play1Button) {
tint(tint1Value, 255 - xfadeValue);
if (invert1Button && invert1State || !invert1Button && !invert1State) {
image1.filter(INVERT);
if (invert1State) {
invert1State = false;
}
else {
invert1State = true;
}
}
}
else {
tint(0, 0);
}
image(image1, 100, 50);
if (blendButton) {
blendMode(BLEND);
}
if (!blendButton) {
blendMode(DIFFERENCE);
}
if (play2Button) {
tint(tint2Value, xfadeValue);
if (invert2Button && invert2State || !invert2Button && !invert2State) {
image2.filter(INVERT);
if (invert2State) {
invert2State = false;
}
else {
invert2State = true;
}
}
}
else {
tint(0, 0);
}
image(image2, 100, 50);
pop();
}
function keyPressed(){
if(key == ' '){
save(xfadeImage, 'xfadeImage', 'png');
}
}
See More Shortcuts