Created
December 6, 2023 13:02
-
-
Save lorinc/fb8510af1176240679841fc9800f71ca to your computer and use it in GitHub Desktop.
Moire Pattern Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.0/p5.js"></script> | |
<link rel="stylesheet" type="text/css" href="style.css"> | |
<meta charset="utf-8" /> | |
</head> | |
<body> | |
<main> | |
</main> | |
<script src="sketch.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var img_zoom = 1.08; | |
var canvas_size = 840; | |
var rotation = 0; | |
var rotation_boundary = 18; // 180/x degree | |
var rotation_speed = 0.003; | |
var position = 0; | |
var position_size = 15; | |
var position_speed = 0.007; | |
var repo = 'https://raw.githubusercontent.com/lorinc/moire/main/' | |
var pattern = 'cross_ripple_fine.png' | |
function setup() { | |
createCanvas(canvas_size , canvas_size); | |
img = loadImage(repo + pattern); | |
} | |
function draw() { | |
background(255) | |
imageMode(CENTER); | |
translate(width / 2, height / 2); | |
//drawing the bottom pattern | |
image(img, 0, 0, img.height * img_zoom, img.height * img_zoom); | |
// rotating the top layer | |
var angle = PI / rotation_boundary * sin(rotation); | |
rotate(angle); | |
// moving the top layer in a 8-shape | |
var x = position_size * cos(position); | |
var y = position_size * sin(position) * cos(position); | |
// drawing the moving pattern | |
image(img, x, y); | |
// updating loop cursors | |
rotation = rotation + rotation_speed; | |
position = position + position_speed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment