OP Art in Java workshop

opart-java

The main goal of this workshop is, to get the Java IDE Eclipse running on your machine and to get into the provided script and modify it.

Here zou can get the Eclipse IDE:

http://www.eclipse.org/downloads/

Here is the Script:

/**

http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/galileo/SR1/eclipse-java-galileo-SR1-macosx-cocoa-x86_64.tar.gz



This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
02110-1301, USA.

Copyright (C) 2008 Claudio Zopfi

 */
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;

import javax.imageio.ImageIO;


public class Visual1 extends Applet implements Runnable {
    /**
     *
     */
    private static final long serialVersionUID = 4115815051186766767L;

    int n;
    int frame;
    int delay;
    int ind;    //image index
    Thread animator;

    public Visual1() {
        this.setSize(712, 712);
    }
    /**
     * Initialize the applet and compute the delay between frames.
     */
    public void init() {
        String str = getParameter("fps");
        int fps = (str != null) ? Integer.parseInt(str) : 10;
        delay = (fps > 0) ? (50000 / fps) : 5000;
        ind=0;
    }

    /**
     * This method is called when the applet becomes visible on
     * the screen. Create a thread and start it.
     */
    public void start() {
        animator = new Thread(this);
        animator.start();
    }

    /**
     * This method is called by the thread that was created in
     * the start method. It does the main animation.
     */
    public void run() {
        while (Thread.currentThread() == animator) {
            // Display the next frame of animation.
            repaint();

            // Delay for a while
            try {
                Thread.sleep(delay);
            } catch (InterruptedException e) {
                break;
            }

            // Advance the frame
            frame++;
        }
    }

    /**
     * This method is called when the applet is no longer
     * visible. Set the animator variable to null so that the
     * thread will exit before displaying the next frame.
     */
    public void stop() {
        animator = null;
    }

    public void update(Graphics g){
        Image bufImage=null;
        Graphics bufG=null;

        int w = 1024;
        int h = 1024;

        if(bufImage == null){
            bufImage = this.createImage(w,h);
            bufG = bufImage.getGraphics();
        }

//        bufG.setColor(this.getBackground());
//bufG.fillRect(0,0,w,h);
        //
//        bufG.setColor(this.getForeground());

        paint(bufG);
        g.drawImage(bufImage,0,0,this);

        BufferedImage bi = new BufferedImage(w, h,
                BufferedImage.TYPE_INT_ARGB);
        Graphics g2=bi.createGraphics();
        g2.drawImage(bufImage,0,0,this);

        try {
            // Save as PNG
            File file = new File("c:/vasa/newimage"+ind+".png");
            ind++;
            ImageIO.write(bi, "png", file);
        } catch (IOException e) {
        }


    }
    public void paint(Graphics g) {
        Random ra = new Random();
        if (n<1) {
            n=1;
        } else if (n>255) {
            n=1;
        } else {
            n=n*2;
        }
        int w=1024;    // size
        float col1=ra.nextFloat();
        float col2=ra.nextFloat();
        float col3=ra.nextFloat();
        float incval=ra.nextFloat()/100;
        float colmax=ra.nextFloat();
        float colmin=ra.nextFloat();
        for(int i=0;icolmax) col1=colmin;
                if(col2colmax) col3=colmin;
                if(col2>colmax) col2=colmin;
                if(col10.6) {
                    int
                    xp[]={i*w1+w4,(i+1)*w1-w4,(i+1)*w1-w4,i*w1+w4,i*w1+w4};
                    int
                    yp[]={j*w1+w4,j*w1+w4,(j+1)*w1-w4,(j+1)*w1-w4,j*w1+w4};
                    g.fillPolygon(xp,yp, 5);
                } else     if(r1>0.3) {
                    int xp[]={i*w1+w2,i*w1+w1,i*w1+w2,i*w1+0,i*w1+w2};
                    int yp[]={j*w1+0,j*w1+w2,j*w1+w1,j*w1+w2,j*w1+0};
                    g.fillPolygon(xp,yp, 5);
                } else {
                    g.fillOval(i*w1+w8, j*w1+w8, w1-w4, w1-w4);
                }
                r1=Math.random();
                g.setColor(Color.getHSBColor( col3, 1.0F, 1.0F ));
                if(r1>0.6) {
                    int
                    xp[]={i*w1+w3,(i+1)*w1-w3,(i+1)*w1-w3,i*w1+w3,i*w1+w3};
                    int
                    yp[]={j*w1+w3,j*w1+w3,(j+1)*w1-w3,(j+1)*w1-w3,j*w1+w3};
                    g.fillPolygon(xp,yp, 5);
                } else     if(r1>0.3) {
                    int xp[]={i*w1+w2,i*w1+w1-w3,i*w1+w2,i*w1+w3,i*w1+w2};
                    int yp[]={j*w1+w3,j*w1+w2,j*w1+w1-w3,j*w1+w2,j*w1+w3};
                    g.fillPolygon(xp,yp, 5);
                } else {
                    g.fillOval(i*w1+w3, j*w1+w3, w3, w3);
                }
            }
        }
    }
}




Posted

in

by

Tags: