Skip to content
Snippets Groups Projects
Commit dc1521cc authored by Fabian Schwarze's avatar Fabian Schwarze
Browse files

init

parents
Branches master
No related tags found
No related merge requests found
{
"folders": [
{
"path": "."
}
],
"settings": {}
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sketch</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="libraries/p5.min.js"></script>
<script src="libraries/p5.sound.min.js"></script>
<script src="libraries/p5svg.js"></script>
</head>
<body>
<script src="sketch.js"></script>
</body>
</html>
{
"include": [
"*.js",
"libraries/*.js",
"c:\\Users\\f01\\.vscode\\extensions\\samplavigne.p5-vscode-1.2.11\\p5types\\global.d.ts"
]
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
sketch.js 0 → 100644
let map = null;
let grid = 30;
let size
let amp = 200;
//let amp = 1;
let noiseScale = 1/amp;
// let noiseScale = 2;
let i = 1;
elevationHeight = 1;
numberLoop = 0;
function setup() {
sketchName = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
console.log(sketchName);
//noLoop();
createCanvas(1024, 600);
size = 0.5*width;
noiseDetail(5, 0.5);
makePixelMap();
}
function draw(){
translate(width / 2, height/1.6);
//drawMap();
drawLinesFromPixel3D();
elevationHeight = 5*sin(0.05*numberLoop)+6;
numberLoop++;
}
function makePixelMap() {
map = [];
for(let i = 0; i < size; i++)
{
map[i] = [];
for(let j = 0; j < size; j++)
{
let h= getHeight(i, j);
h = h*sin((PI/size)*j);
h = h*sin((PI/size)*i);
map[i][j] = h*amp*2;
}
}
}
function getHeight(i, j) {
return noise(i*noiseScale, j*noiseScale);
}
function drawMap()
{
for(let i = 0; i < size; i++)
{
for(let j = 0; j < size; j++)
{
set(i, j, map[i][j])
}
}
updatePixels();
}
function drawLinesFromPixel3D(){
clear();
background(0);
a = TWO_PI/6;
b = 0;
c = TWO_PI/8;
for(let y = 0; y < size; y = y+5){
strokeWeight(1);
noFill();
stroke(255);
beginShape();
for(let x = 0; x < size; x++){
let z = map[x][y]/elevationHeight;
xa = x - size/2;
ya = y - size/2;
let xr = xa * cos(b) * cos(c) + z * sin(b) - ya * cos(b) * sin(c);
let yr = -z * cos(b) * sin(a) + xa * (cos(c) * sin(a) * sin(b) + cos(a) * sin(c)) + ya * (cos(a) * cos(c) - sin(a) * sin(b) * sin(c));
vertex(xr, yr);
}
endShape();
}
}
function keyReleased(){
if(key == 's'){
save(sketchName);
}
}
html, body {
margin: ;
padding: 0;
background-color: black;
}
canvas {
padding: 0;
margin: auto;
display: block;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment