@@ -0,0 +1,3138 @@
+import helpers.ExtendedPApplet;%0Aimport processing.core.PApplet;%0Aimport processing.event.KeyEvent;%0A%0Aimport java.awt.*;%0A%0Apublic class Sphere extends ExtendedPApplet %7B%0A%0A    // colors%0A    int bgColor = new Color(255, 248, 246).getRGB();%0A    int drawColor = new Color(255, 0, 4).getRGB();%0A%0A    // sphere radius and number of points%0A    private int r = getHeight() / 4;%0A    private int rIncrease = 10;%0A    private int numPoints = 30;%0A    private int pointsIncrease = 5;%0A%0A    @Override%0A    protected int getHeight() %7B%0A        return 400;%0A    %7D%0A%0A    @Override%0A    protected int getWidth() %7B%0A        return 600;%0A    %7D%0A%0A%0A    public static void main(String%5B%5D args) %7B%0A        PApplet.main(%22Sphere%22);%0A    %7D%0A%0A    public void settings() %7B%0A        size(getWidth(), getHeight(), P3D);%0A    %7D%0A%0A    public void setup() %7B%0A        background(bgColor);%0A        fill(drawColor);%0A        stroke(drawColor);%0A        strokeWeight(2);%0A        System.out.println(%22UP/DOWN: radius, LEFT/RIGHT: number of points%22);%0A        System.out.println(%22Press mouse to change sphere color%22);%0A    %7D%0A%0A    public void draw() %7B%0A        // frame rate in title%0A        surface.setTitle(round(frameRate) + %22 fps%22);%0A%0A        // clear%0A        background(bgColor);%0A%0A        // draw sphere%0A//        drawSphere(getWidth() / 2, getHeight() / 2, 0, numPoints, r);%0A        drawSphere(mouseX, mouseY, 0, numPoints, r);%0A%0A        // change sphere color%0A        if (mousePressed)%0A            stroke(new Color(%0A                    Math.round(random(0, 255)),%0A                    Math.round(random(0, 255)),%0A                    Math.round(random(0, 255))).getRGB());%0A    %7D%0A%0A    @Override%0A    public void keyPressed(KeyEvent event) %7B%0A        switch (event.getKeyCode()) %7B%0A            case 38: // UP%0A                r += rIncrease;%0A                System.out.println(%22radius: %22 + r);%0A                break;%0A            case 40: // DOWN%0A                if (r %3E= rIncrease)%0A                    r -= rIncrease;%0A                System.out.println(%22radius: %22 + r);%0A                break;%0A%0A            case 37: // LEFT%0A                if (numPoints %3E= pointsIncrease)%0A                    numPoints -= pointsIncrease;%0A                System.out.println(%22numPoints: %22 + numPoints);%0A                break;%0A            case 39: // RIGHT%0A                numPoints += pointsIncrease;%0A                System.out.println(%22numPoints: %22 + numPoints);%0A                break;%0A        %7D%0A    %7D%0A%0A    private void drawSphere(float midX, float midY, float midZ, int numPoints, double r) %7B%0A        if (r %3C= 0)%0A            throw new IllegalArgumentException(%22r can't be negative.%22);%0A%0A        for (int i = 0; i %3C numPoints; i++) %7B%0A            for (int j = 0; j %3C numPoints; j++) %7B%0A                double theta = Math.PI * ((double) i / (double) numPoints);%0A                double phi = (2 * Math.PI) * ((double) j / (double) numPoints);%0A                point(%0A                        midX + (float) (r * Math.sin(theta) * Math.cos(phi)),%0A                        midY + (float) (r * Math.cos(theta)),%0A                        midZ + (float) (r * Math.sin(theta) * Math.sin(phi))%0A                );%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Add Sphere