xxxxxxxxxx
//Concept and composition: Alex Nolla
//The Sun was adapted using the sketch Sun slices by Jerome Herr
//The CyberPunk grid was taken from 80s Grid by Vidar Waagbø
//Song: Timecop1983 - My Delorean (feat. Primo)
//3D Model: Jelly Fighter - https://sketchfab.com/JellyFighter
p5.disableFriendlyErrors = true;
var spacingX = 50;
var spacingY = 50;
var myAngle = 0.0;
let step;
let i = 0;
const num = 26;
let theta;
let delorean;
let dragon ; // ad
let sunPosition = 0;
function preload() {
delorean = loadModel('delorean_painted.obj', true, loadingOk());
dragon = loadModel('dragon.obj', true, loadingOk());
// sound = loadSound('my_delorean-TimeCop1983.mp3');
}
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
// Initialize audio input and FFT
//mic = new p5.AudioIn();
//mic.start();
amp = new p5.Amplitude();
amp.setInput(sound); // music
fft = new p5.FFT();
fft.setInput(sound); // music
//Create initial cubes
for (let i = 0; i < NUM_CUBES; i++) {
cubes.push(new Cube(i * CUBE_SPACING - (NUM_CUBES * CUBE_SPACING)/2, 0));
}
camera(0.0, -150.0, 720.0, -0.0, 0.0, 0.0, 0.0, 130.0, 0.0);
noStroke();
angleMode(DEGREES);
lights();
normalMaterial();
smooth();
//step = 200/num;
theta = 0;
}
function draw() {
background(0);
setGradient();
orbitControl();
scale(2.0);
let wave = fft.waveform(); // music
var s = fft.analyze(); // music
level = amp.getLevel();
let xScale = width/wave.length; // music
// Draw the sun first (behind everything)
push();
rotateZ(180);
translate(0, 0, -1300); // Move sun behind the scene
drawSun();
pop();
// Draw the grid
push();
rotateX(90);
translate(0, 0, -30);
translate(-200, millis()/5 % 100);
drawGrid();
pop();
// Draw the DeLorean
rotateZ(180);
rotateY(-90);
model(delorean);
push() ;
translate( 250,100,0) ; //
rotateY(-90) ;
model(dragon ) ; //
pop() ;
push();
// Draw the Cube
rotateZ(-180);
rotateY(-180);
translate(-295, 30, 200);
// Analyze frequencies
fft.analyze(); // music
// Move all cubes
const moveSpeed = 3*6;
for (let i = cubes.length - 1; i >= 0; i--) {
cubes[i].x += moveSpeed;
}
// Check if we need to add a new cube
if (cubes.length > 0) {
const leftmostX = Math.min(cubes.map(cube => cube.x));
if (leftmostX > -(NUM_CUBES * CUBE_SPACING)/2 + CUBE_SPACING) {
// Add new cube at the left
cubes.push(new Cube(leftmostX - CUBE_SPACING, 0));
}
}
// Update and display cubes
for (let i = cubes.length - 1; i >= 0; i--) {
let freqBand = floor(map(i % NUM_CUBES, 0, NUM_CUBES, 0, 220));
let freqValue = fft.getEnergy(freqBand);
// Remove cubes that are either dead or too far right
if (!cubes[i].update(freqValue) || cubes[i].x > (NUM_CUBES * CUBE_SPACING)/2) {
cubes.splice(i, 1);
} else {
cubes[i].display();
}
}
pop();
push();
// Draw the 2nd Cube
rotateZ(-180);
rotateY(-180);
translate(-295, 30, -200);
// Update and display cubes
for (let i = cubes.length - 1; i >= 0; i--) {
let freqBand = floor(map(i % NUM_CUBES, 0, NUM_CUBES, 0, 220));
let freqValue = fft.getEnergy(freqBand);
// Remove cubes that are either dead or too far right
if (!cubes[i].update(freqValue) || cubes[i].x > (NUM_CUBES * CUBE_SPACING)/2) {
cubes.splice(i, 1);
} else {
cubes[i].display();
}
}
pop();
}
function setGradient() {
// Calculate sun position (0 to 1) based on time
sunPosition = (sin(millis() / 20) + 1) / 2;
// Create gradient background
push();
translate(-width/2, -height/2, 0);
noStroke();
pop();
}
function drawGrid() {
push();
//fill(0,0,0);
stroke(139, 0, 139);
for (var y = -1300; y < windowHeight+650; y = y + spacingY) {
line(-1300, y, windowWidth+650, y);
}
for (var x = -1300; x < windowWidth+650; x = x + spacingX) {
line(x, -1300, x, windowHeight+650);
}
pop();
}
function loadingOk() {
return;
}
function drawSun() {
push();
// Draw the sun with changing colors based on time
let sunColor = color('#FFB700');
let sunColorSet = color('#E2FF01');
let currentSunColor = lerpColor(sunColor, sunColorSet, sunPosition);
fill(currentSunColor);
noStroke();
// Fixed sun size
let sunSize = 900*0.7;
circle(0, 50*6, sunSize);
// Calculate offset based on time for animation
let offset = (millis() / 20) % (sunSize/num); // Controls speed of animation
// Draw sun patterns with animated upward movement
for (let i = 0; i < num + 1; i++) { // Added +1 to ensure smooth transition
// Calculate y position with offset for animation
let y = map(i, 0, num-1, -sunSize/2, sunSize/2) + offset;
// Wrap the lines around when they go beyond the sun's bounds
if (y > sunSize/2) {
y -= sunSize + (sunSize/num); // Adjust position to create seamless loop
}
// Create varying stroke weight based on vertical position
// Map position to stroke weight, accounting for wrapped position
let relativePos = (y + sunSize/2) / sunSize; // normalize position to 0-1
let sw = map(relativePos, 0, 1, 300, 1.5);
stroke(0);
strokeWeight(sw);
line(-sunSize/2, y, sunSize/2, y);
}
theta += 2;
pop();
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
/*
function doubleClicked(){
if(sound.isPlaying()){
sound.pause();
}
else {
sound.play();
}
}
*/