Mein aktuelles Projekt ist schwer auf dem Code so weit. Ich würde gerne Musik hinzufügen, indem ich minim (ich benutze einen PC) benutze, aber ich werde immer wieder mit dem Speicherfehler konfrontiert. Das Lied wird aber extrem abgehackt laufen und es macht das Programm unbrauchbar. Ich änderte den maximalen Speicher in den Einstellungen, aber nachdem ich 4GB ohne Glück versucht hatte, dachte ich, das würde einfach nicht funktionieren. Kann mir bitte jemand meinen Code ansehen und mir einen Weg geben, vielleicht Dinge zu komprimieren, um Platz zu sparen? oder eine Möglichkeit, mein Programm so laufen zu lassen, wie es ist?Nicht genügend Speicherfehler. Was kann ich tun, um das zu beheben?
hier ist der gesamte Code:
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
Minim minim;
AudioPlayer player;
final int stateMenu = 0;
final int RedBox = 1;
final int BlueBox = 2;
final int GreenBox = 3;
int state = stateMenu;
float x, y, r, g, b, radius;
int timer;
//
// font
PFont font;
PFont Amatic;
//
// ----------------------------------------------------------------------
// main functions
void setup()
{
// runs only once
//
size(800, 700);
smooth();
minim = new Minim (this);
font = createFont("ARCARTER-78.vlw", 14);
textFont(font);
//Amatic = createFont("Amatic-Bold.ttf",60);
//textFont(Amatic);
frameRate(15);
} // func
//
void draw()
{
// the main routine. It handels the states.
// runs again and again
switch (state) {
case stateMenu:
showMenu();
break;
case RedBox:
handleRedBox();
player = minim.loadFile("SuperLove.mp3");
player.play();
break;
case BlueBox:
handleBlueBox();
break;
case GreenBox:
handleGreenBox();
break;
default:
println ("Unknown state (in draw) "
+ state
+ " ++++++++++++++++++++++");
exit();
break;
} // switch
//
} // func
// ----------------------------------------------------------------
// keyboard functions
void keyPressed() {
// keyboard. Also different depending on the state.
switch (state) {
case stateMenu:
keyPressedForStateMenu();
break;
case RedBox:
keyPressedForRedBox();
break;
case BlueBox:
keyPressedForBlueBox();
break;
case GreenBox:
keyPressedForGreenBox();
break;
default:
println ("Unknown state (in keypressed) "
+ state
+ " ++++++++++++++++++++++");
exit();
break;
} // switch
//
} // func
void keyPressedForStateMenu() {
//
switch(key) {
case '1':
state = RedBox;
break;
case '2':
state = BlueBox;
background(255);
break;
case '3':
state = GreenBox;
break;
case 'x':
case 'X':
// quit
exit();
break;
default:
// do nothing
break;
}// switch
//
} // func
void keyPressedForRedBox() {
// any key is possible
switch(key) {
default:
state = stateMenu;
break;
} // switch
//
} // func
void keyPressedForBlueBox() {
// any key is possible
switch(key) {
default:
state = stateMenu;
break;
} // switch
}//
void keyPressedForGreenBox(){
switch(key) {
default:
state = stateMenu;
break;
}
} // func
// ----------------------------------------------------------------
// functions to show the menu and functions that are called from the menu.
// They depend on the states and are called by draw().
void showMenu() {
background(255);
fill(0);
textSize(45);
//textFont(Amatic);
text(" Music Box ", 330, 250, 3);
textFont(font);
textSize(14);
text("Press 1 for Red ", 350, 300);
textSize(14);
text("Press 2 for Blue ", 350, 325);
textSize(14);
text("Press 3 for Green", 350, 350);
textSize(14);
// exit button
text("Press x to quit ", 350, 375);
}
void handleRedBox() {
background(255);
stroke(255,0,0);
color from = color(100,random(255),2);
color to = color(0,200,0);
color interA = lerpColor (to,from,.44);
int x = 100;
while (x < width/2 || x> width/2) {
int y = 100;
while (y <height/2 || y > height/2) {
blendMode(DIFFERENCE);
noStroke();
fill(interA);
quadstuff();
strokeWeight(5);
stroke(0,random(255),0);
line(width/2,height/2,mouseY,mouseX);
translate(width, height);
rotate(radians(frameCount));
y = y + 50;
}
x = x + 50;
}
ghostcirc();
ghostcirc2();
}
void ghostcirc(){
int w = 0;
while (w < width) {
int q = 0;
while (q <height) {
blendMode(ADD);
fill(random(61), random(90), random(250));
ellipse(255,255,100,100);;
noStroke();
translate(width, height);
rotate(radians(frameCount));
q = q + 100;
}
w = w + 50;
}
}
void ghostcirc2(){
for (int w= 0; w < width; w+=10) {
blendMode(ADD);
fill(random(61), random(90), random(250));
ellipse(50,50,75,75);;
noStroke();
translate(width, height);
rotate(radians(frameCount));
//if (keyPressed == true){
// fill(random(100), random(90), random(250));
}
}
void quadstuff() {
int rad = 60; // Width of the shape
float xpos, ypos; // Starting position of shape
float xspeed = 2.8; // Speed of the shape
float yspeed = 2.2; // Speed of the shape
xpos = width/2;
ypos = height/2;
//ellipse(mouseX+x, mouseY+y, 100,100);
quad(xpos, ypos, rad, rad, mouseX+rad, mouseY+rad, xspeed, yspeed);
stroke(0);
strokeWeight(5);
}
void handleBlueBox() {
Zon();
}
void Zon(){
blendMode(REPLACE);
frameRate(75);
noStroke();
smooth();
color from = color(2,217,227);
color to = color(0,127,193);
color interA = lerpColor (from,to,.24);
// use frameCount to move x, use modulo to keep it within bounds
x = frameCount % width;
// use millis() and a timer to change the y every 2 seconds
if (millis() - timer >= 8000) {
y = random(height);
timer = millis();
}
// use frameCount and noise to change the red color component
r = noise(frameCount * 0.01) * 60;
// use frameCount and modulo to change the green color component
g = frameCount % 1;
// use frameCount and noise to change the blue color component
b = 255 - noise(1 + frameCount * 0.025) * 255;
// use frameCount and noise to change the radius
radius = noise(frameCount * 0.01) * mouseX;
color c = color(r, g, b);
fill(c);
ellipse(x, y, radius, radius);
}
void Vert(){
frameRate(45);
// use frameCount to move x, use modulo to keep it within bounds
x = frameCount % width;
// use millis() and a timer to change the y every 2 seconds
if (millis() - timer >= 8000) {
y = random(height);
timer = millis();
}
// use frameCount and noise to change the red color component
r = noise(frameCount * 0.01) * 255;
// use frameCount and modulo to change the green color component
g = frameCount % 1;
// use frameCount and noise to change the blue color component
b = 255 - noise(1 + frameCount * 0.025) * 255;
// use frameCount and noise to change the radius
radius = noise(frameCount * 0.01) * mouseX;
color c = color(r, g, b);
fill(c);
ellipse(y, x, radius, radius);
}
void handleGreenBox() {
background(255);
fill(0);
textSize(32);
text(" Some stuff", 150, 100, 3);
textSize(14);
text("..... some text ", 100, 200);
}