created mirror

This commit is contained in:
whatever
2026-09-14 20:19:29 -04:00
commit 6764738d92
600 changed files with 87187 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
/*
Default.java
*
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tero Mäyränen
*/
package org.gzigzag.module.multimedia;
import org.gzigzag.*;
import java.awt.*;
import java.awt.image.*;
public class Default extends MediaZOb
{
public static final String rcsid = "$Id: Default.java,v 1.3 2001/02/22 15:31:13 deetsay Exp $";
private Pixels pix = new Pixels(1, 1);
public Pixels getPixels()
{
pix.getPixels()[0] = 0xff000000;
return pix;
}
}

View File

@@ -0,0 +1,189 @@
/*
MediaFlobFactory.java
*
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tero Mäyränen
*/
package org.gzigzag.module.multimedia;
import org.gzigzag.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
public class MediaFlobFactory extends Default implements FlobFactory
{
public static final String rcsid = "$Id: MediaFlobFactory.java,v 1.14 2001/02/27 08:42:42 raulir Exp $";
static private String flobText;
static private float flobFract;
static private Vector flobColors = new Vector();
static public String getFlobText() { return flobText; }
static public float getFlobFract() { return flobFract; }
static public Vector getFlobColors() { return flobColors; }
static private Hashtable mediaCache = new Hashtable();
static private ImageObserver imgobs = new ImageObserver() {
public boolean imageUpdate(Image i, int inf, int i2,
int i3, int i4, int i5) {
if ((inf & ALLBITS) != 0) {
ZZUpdateManager.chg();
return false;
}
return true;
}
};
/**
* Get cached MediaZOb for ZZCell or make a new MediaZOb and
* add it to the cache.
*
* @param c ZZCell whose corresponding MediaZOb we want
*/
private MediaZOb getFromCache(ZZCell c)
{
MediaZOb mz;
ZZCell rc = c.h("d.clone"); // Cache rootclones only
if (mediaCache.containsKey(rc))
{
mz = (MediaZOb)mediaCache.get(rc);
}
else
{
mz = MediaZOb.newMediaZOb(rc);
mediaCache.put(rc, mz);
}
return mz;
}
public Dimension getSize(ZZCell c, float fract)
{
if (c == null) return new Dimension
(
readParam("width").getInt(80), readParam("height").getInt(15)
);
flobText = c.getText();
MediaZOb mz = getFromCache(c);
// Image img = ScalableFont.fmComp.createImage(mz);
// return new Dimension(img.getWidth(null), img.getHeight(null));
Pixels pix = mz.getPixels();
if (pix.getWidth() < 0 || pix.getHeight() < 0) {
return new Dimension(0, 0);
}
return new Dimension(pix.getWidth(), pix.getHeight());
}
public Flob makeFlob(FlobSet into, ZZCell zzc, final ZZCell handleCell,
final float fract, int x, int y, int d, int w, int h)
{
Flob cf = new Flob(x, y, d, w, h, zzc)
{
public void renderInterp(Graphics g,float frac)
{
Flob r=interpTo;
if (r==null) return;
int mx=(int)(this.x+frac*(r.x-this.x)),
my=(int)(this.y+frac*(r.y-this.y)),
mw=(int)(this.w+frac*(r.w-this.w)),
mh=(int)(this.h+frac*(r.h-this.h));
g.drawRect(mx,my,mw-1,mh-1);
}
public void render(Graphics g, int mx, int my, int md, int mw, int mh)
{
if (!ZZDrawing.instance.qualityEnabled()) return;
flobColors.removeAllElements();
ZZCell orig = c.h("d.clone", -1);
if (orig.h("d.cursor-list", -1).s("d.cursor", -1) != null)
{
flobColors.addElement(ZZCursorReal.getColorOrWhite(orig));
}
else
{
Enumeration e = ZZCursorReal.getPointers(c);
while (e.hasMoreElements())
{
ZZCell cu = (ZZCell)e.nextElement();
Color color = ZZCursorReal.getColor(cu);
if (color != null) flobColors.addElement(color);
}
}
flobText = c.getText();
MediaZOb mz = getFromCache(c);
Image img = ScalableFont.fmComp.createImage(mz.getPixels().getSource());
ZZDrawingJ2D drw = null;
if (ZZDrawing.instance instanceof ZZDrawingJ2D)
drw = (ZZDrawingJ2D) ZZDrawing.instance;
if (drw != null) {
drw.setFIXME(false);
drw.setQuality(g);
}
if (mw == 0 && mh == 0)
g.drawImage(img, mx, my, mw, mh, imgobs);
else
g.drawImage(img, mx, my, mw, mh, null);
if (drw != null) {
drw.setFIXME(true);
drw.setQuality(g);
}
}
public Object hit(int hx,int hy) {
if (hx >= this.x && hy >= this.y && hx < this.x+this.w
&& hy < this.y+this.h) return handleCell;
return null;
}
};
into.add(cf);
return cf;
}
public Flob placeFlob(FlobSet into, ZZCell c, ZZCell handleCell,
float fract, int x, int y, int depth, float xfract, float yfract)
{
Dimension d = getSize(c, fract);
return makeFlob(into, c, handleCell, fract,
(int)(x-xfract*d.width), (int)(y-yfract*d.height), depth, d.width, d.height);
}
public Flob centerFlob(FlobSet into, ZZCell c, ZZCell handleCell,
float fract, Point p, int xalign, int yalign, int depth, Dimension d)
{
if (d==null) d = getSize(c, fract);
int x, y;
x = p.x - d.height/2; y = p.y - d.height/2;
if (xalign<0) x = p.x;
if (xalign>0) x = p.x - d.width;
if (yalign<0) y = p.y;
if (yalign>0) y = p.y - d.height;
return makeFlob(into, c, handleCell, fract, x, y, depth, d.width, d.height);
}
public Flob centerFlob(FlobSet into, ZZCell c, ZZCell handleCell,
float fract, Point p, int xalign, int yalign, int depth)
{
return centerFlob(into, c, handleCell, fract, p, xalign, yalign, depth, null);
}
}
// Local variables:
// tab-width: 4
// End:

View File

@@ -0,0 +1,40 @@
/*
MediaFlobView.java
*
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tero Mäyränen
*/
package org.gzigzag.module.multimedia;
import org.gzigzag.module.*;
import org.gzigzag.*;
import java.awt.*;
public class MediaFlobView extends Default implements FlobView
{
public static final String rcsid = "$Id: MediaFlobView.java,v 1.1 2001/03/05 08:44:14 deetsay Exp $";
private MediaFlobFactory mff = new MediaFlobFactory();
public void raster(FlobSet into, FlobFactory fact, ZZCell view, java.lang.String[] dims,
ZZCell accursed)
{
mff.placeFlob(into, accursed, accursed, 1, 0, 0, 1, 0, 0);
}
}

View File

@@ -0,0 +1,460 @@
/*
MediaMath.java
*
* Copyright (c) 2000-2001, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tero Mäyränen
*/
package org.gzigzag.module.multimedia;
import org.gzigzag.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
/**
* MediaMath is a collection of MediaZObs that do mathematical functions.
* If at all possible, in the future this should be done with some actual
* mathematical language designed for GZigZag...
*/
public class MediaMath
{
public static final String rcsid = "$Id: MediaMath.java,v 1.1 2001/03/05 08:44:14 deetsay Exp $";
public abstract class MathZOb extends MediaZOb
{
protected Pixels pix = null;
protected Vector oldframes = new Vector();
/**
* The inputs for these are just lists of MediaZObs connected on d.2,
* unlike the normal way, which is a list of parameter names, which
* in turn are connected to ZObs on d.1........
*/
protected Vector readInputPixels()
{
Vector v = new Vector();
Pixels inpix;
ZZCell d = cell;
do
{
inpix = MediaZOb.newMediaZOb(d).getPixels();
v.addElement(inpix);
d = d.s("d.2");
}
while ((d != null) && (!d.equals(cell)));
return v;
}
protected Vector readInputZObs()
{
Vector v = new Vector();
MediaZOb mz;
ZZCell d = cell;
do
{
mz = MediaZOb.newMediaZOb(d);
v.addElement(mz);
d = d.s("d.2");
}
while ((d != null) && (!d.equals(cell)));
return v;
}
/**
* Allocate enough pixels to fit all inputs in their correct coordinate positions.
*/
protected void createPix(Vector inputs)
{
if (inputs.size() < 1)
{
pix = new Pixels(1, 1);
pix.getPixels()[0] = 0xff000000;
return;
}
Pixels inpix = (Pixels)inputs.elementAt(0);
int w = inpix.getWidth(), h = inpix.getHeight();
int x = inpix.getX(), y = inpix.getY();
for (int i=1; i<inputs.size(); i++)
{
inpix = (Pixels)inputs.elementAt(i);
if (inpix.getX() < x)
{
w += x-inpix.getX();
x = inpix.getX();
}
if (inpix.getY() < y)
{
h += y-inpix.getY();
y = inpix.getY();
}
if ((inpix.getWidth() + inpix.getX()) > (w + x))
{
w = inpix.getWidth() + inpix.getX() - x;
}
if ((inpix.getHeight() + inpix.getY()) > (h + y))
{
h = inpix.getHeight() + inpix.getY() - y;
}
}
if (pix == null)
{
pix = new Pixels(w, h);
}
else
{
pix.setSize(w, h);
}
pix.setX(x);
pix.setY(y);
}
}
public class add extends MathZOb
{
public int getInt(int def)
{
Vector inputs = readInputZObs();
if (inputs.size() < 1) return def;
int S = 0;
for (int i=0; i<inputs.size(); i++) S += ((MediaZOb)inputs.elementAt(i)).getInt(0);
return S;
}
public Pixels getPixels()
{
Vector inputs = readInputPixels();
Pixels inpix;
/* if (pix != null && inputs.size() == oldframes.size())
{
boolean dirty = false;
for (int i=0; (i<inputs.size()) && (dirty==false); i++)
{
inpix = (Pixels)inputs.elementAt(i);
if (inpix.getFrame() != ((Integer)oldframes.elementAt(i)).intValue())
dirty = true;
}
if (!dirty) return pix;
}
oldframes.removeAllElements();
for (int i=0; i<inputs.size(); i++)
{
oldframes.addElement(new Integer(((Pixels)inputs.elementAt(i)).getFrame()));
}
*/
createPix(inputs);
int p[] = pix.getPixels(), ip[];
for (int i=0; i<(pix.getWidth()*pix.getHeight()); i++) p[i] = 0xff000000;
int pi, ipi;
int pp, ipp;
int r, g, b;
for (int i=0; i<inputs.size(); i++)
{
inpix = (Pixels)inputs.elementAt(i);
ip = inpix.getPixels();
ipi = 0;
pi = ((inpix.getY() - pix.getY()) * pix.getWidth()) + inpix.getX() - pix.getX();
for (int y=0; y<inpix.getHeight(); y++)
{
for (int x=0; x<inpix.getWidth(); x++)
{
ipp = ip[ipi++];
pp = p[pi];
r = (pp & 0xff0000) + (ipp & 0xff0000);
if (r > 0xff0000) r = 0xff0000;
g = (pp & 0xff00) + (ipp & 0xff00);
if (g > 0xff00) g = 0xff00;
b = (pp & 0xff) + (ipp & 0xff);
if (b > 0xff) b = 0xff;
p[pi++] = 0xff000000 | r | g | b;
}
pi += pix.getWidth() - inpix.getWidth();
}
}
pix.setFrame(pix.getFrame()+1);
return pix;
}
}
public class and extends MathZOb
{
public int getInt(int def)
{
Vector inputs = readInputZObs();
if (inputs.size() < 1) return def;
int S = 0xffffffff;
for (int i=0; i<inputs.size(); i++) S &= ((MediaZOb)inputs.elementAt(i)).getInt(0xffffffff);
return S;
}
public Pixels getPixels()
{
Vector inputs = readInputPixels();
Pixels inpix;
/* if (pix != null && inputs.size() == oldframes.size())
{
boolean dirty = false;
for (int i=0; (i<inputs.size()) && (dirty==false); i++)
{
inpix = (Pixels)inputs.elementAt(i);
if (inpix.getFrame() != ((Integer)oldframes.elementAt(i)).intValue())
dirty = true;
}
if (!dirty) return pix;
}
oldframes.removeAllElements();
for (int i=0; i<inputs.size(); i++)
{
oldframes.addElement(new Integer(((Pixels)inputs.elementAt(i)).getFrame()));
}
*/
createPix(inputs);
int p[] = pix.getPixels(), ip[];
for (int i=0; i<(pix.getWidth()*pix.getHeight()); i++) p[i] = 0xffffffff;
int pi, ipi;
int pp, ipp;
int r, g, b;
for (int i=0; i<inputs.size(); i++)
{
inpix = (Pixels)inputs.elementAt(i);
ip = inpix.getPixels();
ipi = 0;
pi = ((inpix.getY() - pix.getY()) * pix.getWidth()) + inpix.getX() - pix.getX();
for (int y=0; y<inpix.getHeight(); y++)
{
for (int x=0; x<inpix.getWidth(); x++)
{
ipp = ip[ipi++];
pp = p[pi];
p[pi++] = 0xff000000 | (pp & ipp);
}
pi += pix.getWidth() - inpix.getWidth();
}
}
pix.setFrame(pix.getFrame()+1);
return pix;
}
}
public class mul extends MathZOb
{
public int getInt(int def)
{
Vector inputs = readInputZObs();
if (inputs.size() < 1) return def;
int S = 1;
for (int i=0; i<inputs.size(); i++) S *= ((MediaZOb)inputs.elementAt(i)).getInt(1);
return S;
}
public Pixels getPixels()
{
Vector inputs = readInputPixels();
Pixels inpix;
/* if (pix != null && inputs.size() == oldframes.size())
{
boolean dirty = false;
for (int i=0; (i<inputs.size()) && (dirty==false); i++)
{
inpix = (Pixels)inputs.elementAt(i);
if (inpix.getFrame() != ((Integer)oldframes.elementAt(i)).intValue())
dirty = true;
}
if (!dirty) return pix;
}
oldframes.removeAllElements();
for (int i=0; i<inputs.size(); i++)
{
oldframes.addElement(new Integer(((Pixels)inputs.elementAt(i)).getFrame()));
}
*/
createPix(inputs);
int p[] = pix.getPixels(), ip[];
for (int i=0; i<(pix.getWidth()*pix.getHeight()); i++) p[i] = 0xffffffff;
int pi, ipi;
int pp, ipp;
int r, g, b;
for (int i=0; i<inputs.size(); i++)
{
inpix = (Pixels)inputs.elementAt(i);
ip = inpix.getPixels();
ipi = 0;
pi = ((inpix.getY() - pix.getY()) * pix.getWidth()) + inpix.getX() - pix.getX();
for (int y=0; y<inpix.getHeight(); y++)
{
for (int x=0; x<inpix.getWidth(); x++)
{
ipp = ip[ipi++];
pp = p[pi];
r = (((pp >> 12) & 0xff0) * ((ipp >> 12) & 0xff0)) & 0xff0000;
g = (((pp >> 8) & 0xff) * ((ipp >> 8) & 0xff)) & 0xff00;
b = ((pp & 0xff) * (ipp & 0xff)) >> 8;
p[pi++] = 0xff000000 | r | g | b;
}
pi += pix.getWidth() - inpix.getWidth();
}
}
pix.setFrame(pix.getFrame()+1);
return pix;
}
}
public class or extends MathZOb
{
public int getInt(int def)
{
Vector inputs = readInputZObs();
if (inputs.size() < 1) return def;
int S = 0;
for (int i=0; i<inputs.size(); i++) S |= ((MediaZOb)inputs.elementAt(i)).getInt(0);
return S;
}
public Pixels getPixels()
{
Vector inputs = readInputPixels();
Pixels inpix;
/* if (pix != null && inputs.size() == oldframes.size())
{
boolean dirty = false;
for (int i=0; (i<inputs.size()) && (dirty==false); i++)
{
inpix = (Pixels)inputs.elementAt(i);
if (inpix.getFrame() != ((Integer)oldframes.elementAt(i)).intValue())
dirty = true;
}
if (!dirty) return pix;
}
oldframes.removeAllElements();
for (int i=0; i<inputs.size(); i++)
{
oldframes.addElement(new Integer(((Pixels)inputs.elementAt(i)).getFrame()));
}
*/
createPix(inputs);
int p[] = pix.getPixels(), ip[];
for (int i=0; i<(pix.getWidth()*pix.getHeight()); i++) p[i] = 0xff000000;
int pi, ipi;
int pp, ipp;
int r, g, b;
for (int i=0; i<inputs.size(); i++)
{
inpix = (Pixels)inputs.elementAt(i);
ip = inpix.getPixels();
ipi = 0;
pi = ((inpix.getY() - pix.getY()) * pix.getWidth()) + inpix.getX() - pix.getX();
for (int y=0; y<inpix.getHeight(); y++)
{
for (int x=0; x<inpix.getWidth(); x++)
{
ipp = ip[ipi++];
pp = p[pi];
p[pi++] = 0xff000000 | pp | ipp;
}
pi += pix.getWidth() - inpix.getWidth();
}
}
pix.setFrame(pix.getFrame()+1);
return pix;
}
}
public class xor extends MathZOb
{
public int getInt(int def)
{
Vector inputs = readInputZObs();
if (inputs.size() < 1) return def;
int S = 0;
for (int i=0; i<inputs.size(); i++) S ^= ((MediaZOb)inputs.elementAt(i)).getInt(0);
return S;
}
public Pixels getPixels()
{
Vector inputs = readInputPixels();
Pixels inpix;
/* if (pix != null && inputs.size() == oldframes.size())
{
boolean dirty = false;
for (int i=0; (i<inputs.size()) && (dirty==false); i++)
{
inpix = (Pixels)inputs.elementAt(i);
if (inpix.getFrame() != ((Integer)oldframes.elementAt(i)).intValue())
dirty = true;
}
if (!dirty) return pix;
}
oldframes.removeAllElements();
for (int i=0; i<inputs.size(); i++)
{
oldframes.addElement(new Integer(((Pixels)inputs.elementAt(i)).getFrame()));
}
*/
createPix(inputs);
int p[] = pix.getPixels(), ip[];
for (int i=0; i<(pix.getWidth()*pix.getHeight()); i++) p[i] = 0xff000000;
int pi, ipi;
int pp, ipp;
int r, g, b;
for (int i=0; i<inputs.size(); i++)
{
inpix = (Pixels)inputs.elementAt(i);
ip = inpix.getPixels();
ipi = 0;
pi = ((inpix.getY() - pix.getY()) * pix.getWidth()) + inpix.getX() - pix.getX();
for (int y=0; y<inpix.getHeight(); y++)
{
for (int x=0; x<inpix.getWidth(); x++)
{
ipp = ip[ipi++];
pp = p[pi];
p[pi++] = 0xff000000 | pp ^ ipp;
}
pi += pix.getWidth() - inpix.getWidth();
}
}
pix.setFrame(pix.getFrame()+1);
return pix;
}
}
}

View File

@@ -0,0 +1,216 @@
/*
MediaZOb.java
*
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tero Mäyränen
*/
package org.gzigzag.module.multimedia;
import org.gzigzag.module.*;
import org.gzigzag.*;
import java.awt.*;
/**
*/
public abstract class MediaZOb implements ZOb
{
public static final String rcsid = "$Id: MediaZOb.java,v 1.7 2001/03/05 08:44:14 deetsay Exp $";
public static boolean dbg = false;
private static void p(String s) { if(dbg) ZZLogger.log(s); }
private static void pa(String s) { ZZLogger.log(s); }
protected ZZCell cell = null;
protected ZZCell callFrom = null;
public void setMacro(ZZCell cf) { callFrom = cf; }
static private MediaZOb nullZOb = new Default();
static private MediaMath mediaMath = new MediaMath();
/**
* This is the readParams method, defined in the ZOb interface.
* Unlike in most ZObs, this method doesn't read parameters from
* the structure: it only sets the cell for reading the parameters later.
*/
public String readParams(ZZCell c) { cell = c; return ""; }
static public MediaZOb newMediaZObNoDefault(ZZCell c)
{
if (c == null) return nullZOb;
c = c.h("d.clone");
ZZCell cc;
MediaZOb mz;
/*
* psssssst!.... this is a secret feature:
* you can show images from the old-fashioned
* file:// or http:// protocols... :-)
*/
try
{
if (c.getText().indexOf("://") >= 0)
{
mz = new image();
mz.readParams(c);
return mz;
}
}
catch (Exception e) {}
cc = c.s("d.1");
if (cc == null) return null;
ZZCell macroCell = cc;
cc = macroCell.h("d.clone");
if (macroCell.equals(cc)) macroCell = null;
String t = cc.getText();
int x;
/*
* This is an unnecessary check just because
* you get some errors if you try newZOb() on an URL :-)
*/
if (t.indexOf("://") >= 0) return null;
x = t.indexOf('.');
if (x > 1) try
{
mz = (MediaZOb)ZZModule.getModule(t.substring(0, x)).newZOb(t.substring(x + 1));
mz.readParams(cc.s("d.1"));
if (macroCell != null) mz.setMacro(macroCell);
return mz;
}
catch (Exception e) {}
/*
* Mathematical functions are hidden inside MediaMath..
*/
if (t.equals("+")) { mz = mediaMath.new add(); mz.readParams(cc.s("d.1")); return mz; }
if (t.equals("&")) { mz = mediaMath.new and(); mz.readParams(cc.s("d.1")); return mz; }
if (t.equals("*")) { mz = mediaMath.new mul(); mz.readParams(cc.s("d.1")); return mz; }
if (t.equals("|")) { mz = mediaMath.new or(); mz.readParams(cc.s("d.1")); return mz; }
if (t.equals("%")) { mz = mediaMath.new xor(); mz.readParams(cc.s("d.1")); return mz; }
return null;
}
static public MediaZOb newMediaZOb(ZZCell c)
{
MediaZOb mz = newMediaZObNoDefault(c);
if (mz == null)
{
mz = new Default();
mz.readParams(c);
}
return mz;
}
/**
* Find a parameter of this cell from the ZZ-structure, and
* return it as a MediaZOb.
*
* @param name is the name of the parameter that you hope to find.
*/
protected MediaZOb readParam(String name)
{
MediaZOb mz = null;
if (cell == null) return nullZOb;
mz = readParam(name, cell, null);
return (mz == null ? nullZOb : mz);
}
/**
* Recursive part of the previous method
*/
private MediaZOb readParam(String name, ZZCell key, ZZCell first)
{
if ((key == null) || key.equals(first)) return null;
if (first == null) first = key;
if ((name != null) && (name.equals(key.getText())))
{
ZZCell value = key.s("d.1");
//-------------------------------------------------
// An acceptable way of passing macro parameters?
if ((value != null) && (value.getText().equals("param")))
{
MediaZOb mz = null;
ZZCell parname = value.s("d.1");
if (parname != null)
{
if (callFrom != null)
mz = readParam(parname.getText(), callFrom.s("d.1"), null);
if (mz == null)
mz = newMediaZOb(parname.s("d.1"));
return mz;
}
}
//-------------------------------------------------
return newMediaZOb(value);
}
return readParam(name, key.s("d.2"), first);
}
/**
* Contents of cell as text.
*
* @param def Default value.
*/
public String getText(String def)
{
return (cell == null ? def : cell.getText());
}
/**
* Contents of cell as integer.
*
* @param def Default value.
*/
public int getInt(int def)
{
String t = getText("");
// try to parse hex
try { if (t.substring(0, 2).equals("0x")) return Integer.parseInt(t.substring(2), 16); }
catch (Exception e) {}
// try to parse decimal
try { return Integer.parseInt(t); } catch (Exception e) {}
return def;
}
public abstract Pixels getPixels();
}
// Local variables:
// tab-width: 4
// End:

View File

@@ -0,0 +1,163 @@
/*
Pixels.java
*
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tero Mäyränen
*/
package org.gzigzag.module.multimedia;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
/**
* The purpose of this class is to be the type of return value
* for MediaZOb's getPixels() method.
*
* @see MediaZOb
*/
public class Pixels
{
public static final String rcsid = "$Id: Pixels.java,v 1.2 2001/03/05 08:44:14 deetsay Exp $";
private int width, height, x, y;
private int allocatedSize;
private int pixels[];
private int frame = 0;
public int getFrame() { return frame; }
public void setFrame(int f) { frame = f; }
public int getX() { return x; }
public int getY() { return y; }
public int getCenterX() { return x + (width >> 1); }
public int getCenterY() { return y + (height >> 1); }
public void setX(int a) { x = a; }
public void setY(int a) { y = a; }
public void setCenterX(int a) { x = a - (width >> 1); }
public void setCenterY(int a) { y = a - (height >> 1); }
public int getWidth() { return width; }
public int getHeight() { return height; }
private void checkSize()
{
int newsize = width*height;
if (newsize > allocatedSize)
{
pixels = null;
allocatedSize = newsize;
pixels = new int[allocatedSize];
}
}
public void setSize(int a, int b)
{
width = a;
height = b;
checkSize();
}
public void setWidth(int a)
{
width = a;
checkSize();
}
public void setHeight(int a)
{
height = a;
checkSize();
}
public void setCenterWidth(int a)
{
x += ((width - a) >> 1);
width = a;
checkSize();
}
public void setCenterHeight(int a)
{
y += ((height - a) >> 1);
height = a;
checkSize();
}
public int[] getPixels() { return pixels; }
/**
* Thanks to this method there's no need to use MemoryImageSource
* to get an Image from pixel data.
*/
public ImageProducer getSource()
{
return new ImageProducer()
{
private Vector imageConsumers = new Vector();
public void addConsumer(ImageConsumer ic)
{
if ((ic != null) && (!isConsumer(ic)))
{
imageConsumers.addElement(ic);
}
}
public boolean isConsumer(ImageConsumer ic)
{
return imageConsumers.contains(ic);
}
public void removeConsumer(ImageConsumer ic)
{
imageConsumers.removeElement(ic);
}
public void requestTopDownLeftRightResend(ImageConsumer ic)
{
startProduction(ic);
}
public void startProduction(ImageConsumer ic)
{
addConsumer(ic);
int i = 0;
ImageConsumer cons;
try
{
while (true)
{
cons = (ImageConsumer)imageConsumers.elementAt(i++);
cons.setDimensions(getWidth(), getHeight());
cons.setHints(ImageConsumer.TOPDOWNLEFTRIGHT
| ImageConsumer.SINGLEFRAME | ImageConsumer.SINGLEPASS);
cons.setPixels(0, 0, getWidth(), getHeight(), ColorModel.getRGBdefault(),
getPixels(), 0, getWidth());
cons.imageComplete(ImageConsumer.STATICIMAGEDONE);
}
}
catch (Exception e) {}
}
};
}
public Pixels(int w, int h)
{
x = 0;
y = 0;
width = w;
height = h;
pixels = new int[width*height];
}
}

View File

@@ -0,0 +1,61 @@
/*
PolygonRenderer.java
*
* Copyright (c) 2000-2001, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tero Mäyränen
*/
package org.gzigzag.module.multimedia;
import org.gzigzag.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
/**
* unfinished..
*/
public class PolygonRenderer extends MediaZOb
{
public static final String rcsid = "$Id: PolygonRenderer.java,v 1.1 2001/03/05 08:44:14 deetsay Exp $";
private Pixels pix;
public Pixels getPixels()
{
int w = readParam("width").getInt(256);
int h = readParam("height").getInt(256);
if (pix == null)
{
pix = new Pixels(w, h);
}
else
{
pix.setSize(w, h);
}
int p[] = pix.getPixels();
for (int i=0; i<(w*h); i++) p[i] = 0xff000000;
/* sort polygons */
/* render */
return pix;
}
}

View File

@@ -0,0 +1,65 @@
/*
Polygons.java
*
* Copyright (c) 2000-2001, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tero Mäyränen
*/
package org.gzigzag.module.multimedia;
import org.gzigzag.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
/**
* unfinished
*/
public class Polygons
{
public static final String rcsid = "$Id: Polygons.java,v 1.1 2001/03/05 08:44:14 deetsay Exp $";
public class PolyPoint
{
public int x, y, z;
public int tx, ty, ex, ey, bx, by;
}
public class Polygon
{
public PolyPoint points[];
public Polygon()
{
points = new PolyPoint[3];
}
}
private PolyPoint points[];
private Polygon polygons[];
public PolyPoint[] getPoints() { return points; }
public Polygon[] getPolygons() { return polygons; }
public Polygons(int npoints, int npolygons)
{
points = new PolyPoint[npoints];
polygons = new Polygon[npolygons];
}
}

View File

@@ -0,0 +1,109 @@
/*
adjust.java
*
* Copyright (c) 2000-2001, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tero Mäyränen
*/
package org.gzigzag.module.multimedia;
import org.gzigzag.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
/**
* unfinished
*/
public class adjust extends MediaZOb
{
public static final String rcsid = "$Id: adjust.java,v 1.1 2001/03/05 08:44:14 deetsay Exp $";
private Pixels pix = null;
private int oldframe=0, oldradj=0, oldgadj=0, oldbadj=0, oldhadj=0, oldsadj=0, oldbradj=0;
public Pixels getPixels()
{
Pixels inpix = readParam("input").getPixels();
int radj = readParam("red").getInt(100);
int gadj = readParam("green").getInt(100);
int badj = readParam("blue").getInt(100);
int hadj = readParam("hue").getInt(100);
int sadj = readParam("saturation").getInt(100);
int bradj = readParam("brightness").getInt(100);
if (pix != null && inpix.getFrame() == oldframe
&& radj == oldradj && gadj == oldgadj && badj == oldbadj
&& hadj == oldhadj && sadj == oldsadj && bradj == oldbradj)
{
return pix;
}
oldradj = radj; oldgadj = gadj; oldbadj = badj;
oldhadj = hadj; oldsadj = sadj; oldbradj = bradj;
oldframe = inpix.getFrame();
int w = inpix.getWidth();
int h = inpix.getHeight();
int px = inpix.getX();
int py = inpix.getY();
if (pix == null)
{
pix = new Pixels(w, h);
}
else
{
pix.setSize(w, h);
}
pix.setX(px);
pix.setY(py);
float hsbvals[] = new float[3];
int ip[] = inpix.getPixels();
int pred, pgreen, pblue, prgb;
int op[] = pix.getPixels();
for (int i=0; i<(w*h); i++)
{
prgb = ip[i];
pred = ((prgb >> 16) & 0xff) * radj / 100;
pgreen = ((prgb >> 8) & 0xff) * gadj / 100;
pblue = (prgb & 0xff) * badj / 100;
Color.RGBtoHSB(
(pred > 255 ? 255 : pred),
(pgreen > 255 ? 255 : pgreen),
(pblue > 255 ? 255 : pblue),
hsbvals);
hsbvals[0] = hsbvals[0] * hadj / 100;
hsbvals[1] = hsbvals[1] * sadj / 100;
hsbvals[2] = hsbvals[2] * bradj / 100;
op[i] = Color.HSBtoRGB(
(hsbvals[0] > 1 ? 1 : hsbvals[0]),
(hsbvals[1] > 1 ? 1 : hsbvals[1]),
(hsbvals[2] > 1 ? 1 : hsbvals[2]));
}
return pix;
}
}

View File

@@ -0,0 +1,94 @@
/*
crop.java
*
* Copyright (c) 2000-2001, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tero Mäyränen
*/
package org.gzigzag.module.multimedia;
import org.gzigzag.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
/**
* unfinished
*/
public class crop extends MediaZOb
{
public static final String rcsid = "$Id: crop.java,v 1.2 2001/03/05 08:44:14 deetsay Exp $";
private Pixels pix = null;
private int oldframe=0, oldpw=0, oldph=0, oldpx=0, oldpy=0;
public Pixels getPixels()
{
Pixels inpix = readParam("input").getPixels();
int iw = inpix.getWidth();
int ih = inpix.getHeight();
int ix = inpix.getX();
int iy = inpix.getY();
int pw = readParam("width").getInt(iw);
int ph = readParam("height").getInt(ih);
int px = readParam("x").getInt(ix);
int py = readParam("y").getInt(iy);
if (pix != null && inpix.getFrame() == oldframe
&& pw == oldpw && ph == oldph && px == oldpx && py == oldpy)
{
return pix;
}
oldpw = pw; oldph = ph; oldpx = px; oldpy = py; oldframe = inpix.getFrame();
if (pix == null)
{
pix = new Pixels(pw, ph);
}
else
{
pix.setSize(pw, ph);
}
pix.setX(px);
pix.setY(py);
int p[] = pix.getPixels(), ip[] = inpix.getPixels();
int i = 0;
for (int y=py; y<py+ph; y++)
{
if ((y < iy) || (y >= iy + ih))
{
for (int x=0; x<pw; x++) p[i++] = 0xff000000;
}
else
{
for (int x=px; x<px+pw; x++)
{
if ((x < ix) || (x >= ix + iw)) p[i++] = 0xff000000;
else p[i++] = ip[ ((y-iy)*iw)+(x-ix) ];
}
}
}
pix.setFrame(pix.getFrame()+1);
return pix;
}
}

View File

@@ -0,0 +1,58 @@
/*
dots.java
*
* Copyright (c) 2000-2001, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tero Mäyränen
*/
package org.gzigzag.module.multimedia;
import org.gzigzag.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
public class dots extends MediaZOb
{
public static final String rcsid = "$Id: dots.java,v 1.2 2001/03/05 08:44:14 deetsay Exp $";
private Pixels pix = null;
private void plot(int p[], int w, int h, int n)
{
}
public Pixels getPixels()
{
if (pix == null)
{
int w = readParam("width").getInt(64);
int h = readParam("height").getInt(64);
int c = readParam("bg").getInt(0);
pix = new Pixels(w, h);
int p[] = pix.getPixels();
for (int i=0; i<(w*h); i++)
{
p[i] = 0xff000000 | c;
}
plot(p, w, h, readParam("dots").getInt(100));
}
return pix;
}
}

View File

@@ -0,0 +1,102 @@
/*
image.java
*
* Copyright (c) 2000-2001, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tero Mäyränen
*/
package org.gzigzag.module.multimedia;
import org.gzigzag.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
import java.net.*;
/** Image mediazob.
* Images can be read from a different place by setting the property images.from,
* like
* java -Dimages.from=img:///=file:///home/antkaij/cvs/gzigzag-demo/Java/demospace-lomat.2.zz/ org.gzigzag.Main demospace-lomat.2.zz
*/
public class image extends MediaZOb
{
public static final String rcsid = "$Id: image.java,v 1.7 2001/02/28 05:16:55 tjl Exp $";
public static boolean dbg = false;
private static void p(String s) { if(dbg) ZZLogger.log(s); }
private static void pa(String s) { ZZLogger.log(s); }
private static Hashtable convert = null;
private Pixels pix = null;
private static String doConvert(String str) {
if (convert == null) {
convert = new Hashtable();
String prop = null;
try {
prop = System.getProperty("images.from");
} catch(Throwable t) {}
if (prop != null) {
StringTokenizer tok = new StringTokenizer(prop, ";=");
while (tok.hasMoreTokens()) {
String a = tok.nextToken();
String b = tok.nextToken();
p(""+a+" => "+b);
convert.put(a, b);
}
}
}
for(Enumeration e = convert.keys(); e.hasMoreElements(); ) {
String from = (String)e.nextElement();
p(""+str+"; "+from);
if (!str.startsWith(from)) continue;
String to = (String)convert.get(from);
p(""+str+" => "+to + str.substring(from.length()));
str = to + str.substring(from.length());
return str;
}
p("Not converted: "+str);
return str;
}
public Pixels getPixels()
{
if (pix == null)
{
try
{
URL imgURL = new URL(doConvert(getText("")));
p("URL: "+imgURL);
Image img = Toolkit.getDefaultToolkit().getImage(imgURL);
int w = img.getWidth(null);
int count = 2000000;
while ((w < 0) && (count-- > 0)) w = img.getWidth(null);
int h = img.getHeight(null);
pix = new Pixels(w, h);
PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pix.getPixels(), 0, w);
pg.grabPixels();
}
catch (Exception e) {}
}
return pix;
}
}
// Local variables:
// tab-width: 4
// End:

View File

@@ -0,0 +1,51 @@
/*
mm.java
*
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tero Mäyränen
*/
package org.gzigzag.module;
import org.gzigzag.module.multimedia.*;
import org.gzigzag.*;
import java.awt.*;
/**
* Module for multimedia stuff.
*/
public class mm
{
static public final String rcsid = "$Id: mm.java,v 1.3 2001/03/05 08:44:14 deetsay Exp $";
static public ZZModule module = new ZZModule()
{
public ZOb newZOb(String id)
{
try
{
return (ZOb)Class.forName("org.gzigzag.module.multimedia." + id).newInstance();
}
catch (Exception e)
{
// ZZLogger.exc(e);
return null;
}
}
};
}

View File

@@ -0,0 +1,70 @@
/*
move.java
*
* Copyright (c) 2000-2001, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tero Mäyränen
*/
package org.gzigzag.module.multimedia;
import org.gzigzag.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
public class move extends MediaZOb
{
public static final String rcsid = "$Id: move.java,v 1.2 2001/03/05 08:44:14 deetsay Exp $";
Pixels pix = null;
private int oldframe=0, oldx=0, oldy=0;
public Pixels getPixels()
{
Pixels inpix = readParam("input").getPixels();
int x = readParam("x").getInt(0);
int y = readParam("y").getInt(0);
if (pix != null && inpix.getFrame() == oldframe && x == oldx && y == oldy)
{
return pix;
}
oldframe = inpix.getFrame(); oldx = x; oldy = y;
int w = inpix.getWidth();
int h = inpix.getHeight();
if (pix == null)
{
pix = new Pixels(w, h);
}
else
{
pix.setSize(w, h);
}
pix.setX(inpix.getX() + x);
pix.setY(inpix.getY() + y);
int p[] = pix.getPixels(), ip[] = inpix.getPixels();
for (int i=0; i<w*h; i++) p[i] = ip[i];
pix.setFrame(pix.getFrame()+1);
return pix;
}
}

View File

@@ -0,0 +1,107 @@
<html>
<head>
<title>Multimedia module</title>
<!-- // $Id: readme.html,v 1.2 2001/03/05 08:44:14 deetsay Exp $ // -->
<script language="javascript">
<!--
function nop(c)
{
return '<td colspan="'+c+'"></td>\n';
}
function cell(p)
{
return '<td>'
+ '<table cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000">'
+ '<table cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#ffff00">'
+ p + '</td></tr></table></td></tr></table></td>\n';
}
function hconn(p)
{
var t = '';
var i;
for (i=0; i<8; i++) { t = t + '&nbsp;'; }
return '<td><font size="-1"><u>'+t+p+t+'</u></font></td>\n';
}
function vconn(p)
{
return '<td>| <font size="-1">'+p+'</font></td>\n';
}
function figure(p, t)
{
return '<center>'
+ '<table cellspacing=0 cellpadding=16 border=0><tr><td bgcolor="#ffcc00">\n'
+ '<table cellspacing=0 cellpadding=0 border=0><tr>\n'
+ p + '</tr></table></td></tr></table>\n'
+ '<b>Fig. ' + t + '</b><br>\n</center>\n';
}
// -->
</script>
</head>
<body bgcolor="#ffffff" text="#000000">
<h2>1. How to use MediaZObs</h2>
<script language="javascript">
<!-- //
document.write(figure(
cell('<i>The picture created by the MediaZOb would be shown in this cell. '
+'The text contents of this cell are inconsequential, for example it could be a name '
+'for this picture.</i>')
+hconn('d.1')+cell('<i>name of MediaZOb</i>')+hconn('d.1')+cell('&nbsp;')+nop(2)
+'</tr><tr>'
+nop(4)+vconn("d.2")+nop(2)
+'</tr><tr>'
+nop(4)+cell('parameter')+hconn('d.1')+cell('value')
+'</tr><tr>'
+nop(4)+vconn("d.2")+nop(2)
+'</tr><tr>'
+nop(4)+cell('parameter')+hconn('d.1')+cell('value')
+'</tr><tr>'
+nop(4)+vconn("d.2")+nop(2),
'1.1. The structure of a typical MediaZOb.'
));
// -->
</script>
<h2>2. How to use macros</h2>
To define a macro:
<ul>
<li>Just use the MediaZOb you want to use ("mm.rect" below).</li><br>
<li>Replace some of the parameters with the word "param" :-)</li><br>
<li>To the cell next from "param" on "d.1" write the name of your
parameter. ("mywidth" below)</li><br>
<li>Optional: To the cell next on "d.1" write a default value.</li><br>
</ul>
<script language="javascript">
<!-- //
document.write(figure(
nop(2)+cell('mm.rect')+hconn('d.1')+cell('&nbsp;')+nop(6)+'</tr><tr>'
+nop(2)+vconn('')+nop(1)+vconn('d.2')+nop(6)+'</tr><tr>'
+nop(2)+vconn('d.clone')+nop(1)+cell('width')+hconn('d.1')+cell('param')+hconn('d.1')+cell('mywidth')+hconn('d.1')+cell('50')+'</tr><tr>'
+nop(2)+vconn('')+nop(8)+'</tr><tr>'
+cell('<i>a rectangle will show up here</i>')
+hconn('d.1')+cell('mm.rect')+hconn('d.1')+cell('&nbsp;')+nop(6)+'</tr><tr>'
+nop(4)+vconn('d.2')+nop(6)+'</tr><tr>'
+nop(4)+cell('mywidth')+hconn('d.1')+cell('100')+nop(4),
'2.1. The structure of a macro.'
));
// -->
</script>
To use a macro:
<ul>
<li>Clone the name of the MediaZOb...</li><br>
<li>Give the clone some of the parameters you have used in your
macro definition.</li><br>
</ul>
</body>
</html>

View File

@@ -0,0 +1,122 @@
/*
rect.java
*
* Copyright (c) 2000-2001, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tero Mäyränen
*/
package org.gzigzag.module.multimedia;
import org.gzigzag.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
public class rect extends MediaZOb
{
public static final String rcsid = "$Id: rect.java,v 1.4 2001/03/05 08:44:14 deetsay Exp $";
private Pixels pix = null;
private int fade(int x, int fg, int bg)
{
int y = 0xff-x;
return 0xff000000
| (((((fg & 0xff0000) * x) + ((bg & 0xff0000) * y)) >> 8) & 0xff0000)
| (((((fg & 0xff00) * x) + ((bg & 0xff00) * y)) >> 8) & 0xff00)
| (((((fg & 0xff) * x) + ((bg & 0xff) * y)) >> 8) & 0xff);
}
private int oldw=0, oldh=0, oldbg=0, oldfg=0, oldstarsize=0;
private String oldmode="";
public Pixels getPixels()
{
int w = readParam("width").getInt(64);
int h = readParam("height").getInt(64);
int bg = readParam("bg").getInt(0);
int fg = readParam("fg").getInt(0xffffff);
int starsize = readParam("size").getInt(16);
if (starsize==0) starsize=1;
String mode = readParam("fillmode").getText("solid");
if (pix != null && oldw==w && oldh==h && oldbg==bg && oldfg==fg
&& oldstarsize==starsize && mode.equals(oldmode))
{
return pix;
}
oldw=w; oldh=h; oldbg=bg; oldfg=fg; oldstarsize=starsize; oldmode=mode;
if (pix == null)
{
pix = new Pixels(w, h);
}
else
{
pix.setSize(w, h);
}
int p[] = pix.getPixels();
if (mode.equals("solid"))
{
for (int i=0; i<(w*h); i++)
{
p[i] = 0xff000000 | fg;
}
}
if (mode.equals("starburst"))
{
// älä optiomoi, vaihda algoritmia
int w2 = w >> 1;
int h2 = h >> 1;
int i = 0, j;
for (int y=-h2; y<h-h2; y++)
{
for (int x=-w2; x<w-w2; x++)
{
j = ((int)Math.sqrt(x*x+y*y)*(256 / starsize));
if (j > 0xff) j = 0xff;
p[i++] = fade(j, bg, fg);
}
}
}
if (mode.equals("radial"))
{
int w2 = w >> 1;
int h2 = h >> 1;
int i = 0, j = w, i2 = w*h, j2 = (w*h)-w, k;
for (int y=-h2; y<0; y++)
{
for (int x=-w2; x<0; x++)
{
k = ((int)(Math.atan(((double)x) / y) * 128 / Math.PI)) & 0x3f;
p[i++] = fade(k, bg, fg);
p[--j] = fade(k, fg, bg);
p[--i2] = fade(k | 0x80, bg, fg);
p[j2++] = fade(k | 0x80, fg, bg);
}
i += w2;
j += w + w2;
i2 -= w2;
j2 -= w + w2;
}
}
pix.setFrame(pix.getFrame()+1);
return pix;
}
}

View File

@@ -0,0 +1,42 @@
/*
sin.java
*
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tero Mäyränen
*/
package org.gzigzag.module.multimedia;
import org.gzigzag.module.*;
import org.gzigzag.*;
import java.awt.*;
/**
*/
public class sin extends Default
{
public static final String rcsid = "$Id: sin.java,v 1.1 2001/03/05 08:44:14 deetsay Exp $";
public int getInt(int def)
{
int a = ((int)System.currentTimeMillis()) >> 7;
return ((int)(Math.sin(((double)a * readParam("speed").getInt(64)) / (Math.PI * 100))
* readParam("amplitude").getInt(16))) + readParam("bias").getInt(64);
}
}