` 1:`

2:/**

3: * The idea for this class is that it can return either

4: * width and height, or a Dimension instance, where the ratio

5: * of the two sides is special number eg phi, pi or root(2)

6: * The minimum size has been set to 10 pixels

7: * @author Martin Prout

8: */

9:public class SpecialDimension {

10:

11: public final int MINSIZE = 10;

12: // static constant

13: public static final double PHI = (1 + Math.sqrt(5)) / 2;

14: public java.awt.Dimension special;

15: /**

16: * A version where the width is set as a proportion of height

17: * using the ratio value typically PHI or PI or root 2

18: * Arbitary minimum value 10 x 10. Since ratio is typically an

19: * irrational number rounding is required

20: * @param height int base

21: * @param ratio double multiplier

22: */

23: public SpecialDimension(int height, double ratio) {

24: if (height < MINSIZE)

25: { height = MINSIZE;}

26: int width = (int)Math.ceil (ratio*height);

27: if (width < MINSIZE){ // then ratio < 1

28: width = MINSIZE;

29: height = (int)Math.ceil(MINSIZE/ratio);

30: }

31: special = new java.awt.Dimension (width, height);}

32: /**

33: *

34: * @return special width int

35: */

36: public int getWidth(){return special.width;}

37: /**

38: *

39: * @return special height int

40: */

41: public int getHeight(){

42: return special.height;

43: }

44: /**

45: *

46: * @return special Dimension

47: */

48: public java.awt.Dimension getSize(){

49: return special;

50: }

51:

52:}

To use this class as library for a processing application, compile it, archive it as jar file and place it in the 'code' folder.

Heres my processing code:

` 1:SpecialDimension special = new SpecialDimension(400, SpecialDimension.PHI);`

2:

3:final java.awt.Dimension WSIZE = special.getSize();

4:

5:void setup() {

6: size(WSIZE.width, WSIZE.height);

7: background(03366);

8: noLoop();

9:}

Displays OK for me as a blue window, default aspect ratio is landscape, a refinement would add a switch to the library class to create a portrait look (as per Mondrian).

## No comments:

## Post a Comment