public void mouseDraw() { MouseInfo m = Greenfoot.getMouseInfo(); if(m == null) return; getBackground().setColorAt(m.getX(), m.getY(), Color.WHITE); }
public void mouseDraw() { MouseInfo m = Greenfoot.getMouseInfo(); if (m == null) return; if (!(m.getX() > getWidth() || m.getY() > getHeight())) { getBackground().fillOval(m.getX(), m.getY(), 10,10); } }
public void fadeOut() { for (int i = 0; i < getWidth(); i++) { for (int j = 0; j < getHeight(); j++) { fadeColor = getBackground().getColorAt(i,j); int r = fadeColor.getRed(); int b = fadeColor.getBlue(); int g = fadeColor.getGreen(); if (r > 5) { r-=5; } if (b > 5) { b-=5; } if (g > 5) { g-=5; } if (getBackground().getColorAt(i,j) != baseColor) { getBackground().setColorAt(i,j, new Color(r,b,g)); } } } }
import java.awt.Color; import greenfoot.* public class Black_Background extends World { private MouseInfo mouseNew; private MouseInfo mouseOld; private Color fadeColor = new Color(0,0,0); private Color baseColor = new Color(0,0,0); private Color myColor = new Color (0,200,200); private int r; private int b; private int g; public void act() { mouseShootParticle(); fadeOut(); } public void mouseShootParticle() { mouseNew = Greenfoot.getMouseInfo(); if (mouseNew == null ) return; if (mouseOld != mouseNew) { if (!(mouseNew.getX() > getWidth() || mouseNew.getY() > getHeight())) { addObject(new ColorParticle(calculateMouseSpeed(), calculateMouseDirection()), mouseNew.getX(), mouseNew.getY()); //addObject(new ColorParticle(10, 10),mouseNew.getX(), mouseNew.getY()); } mouseOld = mouseNew; } else if (mouseOld == mouseNew) { //idleMouseParticles(); } } public void fadeOut() { for (int i = 0; i < getWidth(); i++) { for (int j = 0; j < getHeight(); j++) { if (getBackground().getColorAt(i,j) != baseColor) { fadeColor = getBackground().getColorAt(i,j); r = fadeColor.getRed(); b = fadeColor.getBlue(); g = fadeColor.getGreen(); if (r > 10) { r-=5; } else if (r <= 10) { r = 0; } if (b > 10) { b-=5; } else if (b <= 10) { b = 0; } if (g > 10) { g-=5; } else if (g <= 10) { g = 0; } getBackground().setColorAt(i,j, new Color(r,b,g)); } } } } public int calculateMouseSpeed() { return (int)(calculateMouseDistance() / 1); } public int calculateMouseDirection() { return (int)(Math.tan(calculateMouseSlope())); } public double calculateMouseDistance() { return Math.sqrt(Math.pow(mouseOld.getX() - mouseNew.getX(),2) + Math.pow(mouseOld.getY() - mouseNew.getY(),2)); } public double calculateMouseSlope() { if (Greenfoot.mouseMoved(null)) { return (mouseOld.getY() - mouseNew.getY() / (mouseOld.getX() - mouseNew.getX())); } else { return 1; } }
public int calculateMouseDirection() throws Exception { (int)(180 * Math.atan2(mouseNew.getY() - mouseOld.getY(), mouseNew.getX() - mouseOld.getX()) / Math.PI) }
try { addObject(new ColorParticle(calculateMouseSpeed(), calculateMouseDirection()), mouseNew.getX(), mouseNew.getY()); } catch(Exception e) {}
public void grow() { if (Greenfoot.mousePressed(null)) { shapeSize= 150; } if (Greenfoot.mouseClicked(null)) { shapeSize = 20; } }
if (!(mouseNew.getX() > getWidth() || mouseNew.getY() > getHeight())) { try { addObject(new ColorParticle(calculateMouseSpeed(), calculateMouseDirection(), shapeSize), mouseNew.getX() - (shapeSize / 2), mouseNew.getY() - (shapeSize / 2)); } catch(Exception e) {} }