xxxxxxxxxx
// primary image, using an image uploaded to open processing
var input01, input02
// Settings
var res = 300 // keep res 300 for testing, increasing this number it will take longer to
var saveFile = false // type true to save, false to turn off
// Change Images
const link1 = "monster-pattern.jpg" // primary image
const link2 = "mario3.jpg" // secondary image
function algorithm() {
console.log('starting algorithm')
// START EDING FROM HERE
// merge()
// tiling rules
array(24,4)
// rotation rule
rotation(12)
merge()
horizontal()
rotation(4)
array(4,4)
// deletion(20)
// diagonal()
// END EDITING HERE
console.log('algorithm done!')
}
// merge() // combine two images
// horizontal() // reflect x plane
// vertical() // reflect x plane
// diagonal() // mirror on diagonal
// array(3, 3) // tile in a 2x2 grid
// rotation(6) // number of rotations
// deletion(10) // must be greater than 2
// DO NOT ALTER CODE BELOW
var patt, patt02
function preload() {
// set loadImage to URL or Link
input01 = loadImage(link1) // primary
input02 = loadImage(link2) // secondary
}
function setup() {
imageMode(CENTER)
createCanvas(res, res)
patt = input01.get()
if (input02){
patt02 = input02.get()
} else {
patt01 = input01.get()
}
patt.resize(width, height)
patt02.resize(width, height)
algorithm()
image(patt, width / 2, width / 2);
if (saveFile) {
save('img.jpg')
}
}
// function mousePressed(){
// save('img.jpg')
// }
function cut() {
pg = createGraphics(width, height)
push()
pg.scale(1.5)
pg.image(patt, 0, 0)
pop()
patt = pg.get()
}
function array(numX, numY) {
pg = createGraphics(width, height)
stepX = width / numX
stepY = height / numY
for (x = 0; x < width; x += stepX) {
for (y = 0; y < height; y += stepY) {
pg.image(patt, x, y, stepX, stepY)
}
}
patt = pg.get()
}
function rotation(num) {
console.log('rotation', num)
pg = createGraphics(width, height)
// pg.imageMode(CENTER)
step = TWO_PI / num
// pg.loadPixels()
pg.image(patt, 0, 0)
for (angle = 0; angle < TWO_PI; angle += step) {
pg.push()
pg.translate(width / 2, height / 2)
pg.scale(0.5)
pg.rotate(angle)
pg.image(patt, 0, 0)
pg.pop()
}
pg.updatePixels()
patt = pg.get()
}
function horizontal(img) {
console.log('horizontal reflection')
patt.loadPixels()
let w = patt.width
let h = patt.height
for (y = h / 2; y < h; y++) {
for (x = 0; x < w; x++) {
patt.set(x, y, patt.get(x, h / 2 - (y - h / 2)));
}
}
patt.updatePixels()
}
function deletion(num) {
let steps = 2 || num
pg = createGraphics(width, height)
pg.image(patt, 0, 0)
pg.filter(POSTERIZE, num)
patt = pg.get()
}
function diagonal() {
pg = createGraphics(width, height)
pg.loadPixels()
let w = pg.width
let h = pg.height
for (x = 0; x < w; x++) {
for (y = h; y > 0; y--) {
if (y < pg.width - x) {
pg.set(x, y, patt.get(w - x, h-y))
continue
}
pg.set(x, y, patt.get(x, y))
}
}
pg.updatePixels()
patt = pg.get()
}
function merge() {
console.log('merge')
patt.loadPixels()
let w = patt.width
let h = patt.height
for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
if (x < w / 2) {
patt.set(x, y, patt.get(x, y))
continue
}
patt.set(x, y, patt02.get(x, y))
}
}
patt.updatePixels()
}
function vertical() {
console.log('vertical reflection')
patt.loadPixels()
let w = patt.width
let h = patt.height
for (x = w / 2; x < w; x++) {
for (y = 0; y < h; y++) {
patt.set(x, y, patt.get(w / 2 - (x - w / 2), y));
}
}
patt.updatePixels()
}