Yoix - Examples

Examples

1. Extract all HTML directives from the AT&T home page and write them to standard output.

import yoix.*.*; URL att = open("http://www.att.com", "r"); String text; int cnt = 0; while (cnt >= 0) { if ((cnt = fscanf(att, " <%>", &text)) > 0) printf("<%s>\n", text); else cnt = fscanf(att, " %*"); // discard }

2. Build and display a GUI with two buttons in a titled frame (i.e., window) that also has a titled border. One button pops up a message when pressed, the other quits the example. The window is sized automatically to just fit its components, and some additional code calculates its location to put it in the center of the screen before making it visible.

import yoix.*.*; JFrame jf = { Dimension size = NULL; // auto-size window FlowLayout layoutmanager = { int hgap = 18; // 0.25 inch gap }; String title = "Wikipedia Yoix Example"; // window title String border = "Simple Button Example"; // border title Array layout = { new JButton { String text = "Press for Message"; actionPerformed(ActionEvent ev) { showMessageDialog(root, "Hello, world.", "Message Example"); } }, new JButton { String text = "Press to Exit"; actionPerformed(ev) { // ActionEvent declaration can be omitted exit(0); } }, }; }; // set frame location to center of screen now that frame size is known jf.location = new Point { int x = (VM.screen.width - jf.size.width) / 2; int y = (VM.screen.height - jf.size.height) / 2; }; // make it visible jf.visible = TRUE;

3. The code shown here was used to generate the Yoix logo image in PNG format that can be seen in the language description box near the top of this page. Command-line arguments allow the size of the image to be specified as well as select between PNG image output or display in an on-screen window.

import yoix.*.*; BuildYoixLogoImage(double height, Color color, int addshadow) { // create the basic image, without shadow GenImage(double height, Color color, Font imagefont, double scale) { Image yoixlogo = { int type = TYPE_RGB_ALPHA; Color imgcolor = color; double scale = scale; Font imagefont = imagefont; Font regfont = imagefont.scalefont(0.5, 0.5); Graphics graphics = { Font font = imagefont; int textantialiasing = TRUE; }; double ywd = stringWidth(graphics.font, "Y"); Dimension size = { double height = height; double width = ywd * 5.25; }; double owd = stringWidth(graphics.font, "o"); double iwd = stringWidth(graphics.font, "i"); double xwd = stringWidth(graphics.font, "x"); ywd += iwd; ywd /= 2.0; paint(Rectangle r) { double alpha = 1.0; double alpha2 = 0.3333; int limit = 12; graphics { gsave; erasedrawable(0.0); // for transparent PNG rectclip(r); setrgbcolor(imgcolor.red, imgcolor.green, imgcolor.blue); translate(48 * this.scale, 44 * this.scale); for(n=0; n 1) ? atof(argv) : 270; int shdw = 1; int print = 0; // second argument: if 0/1 turn shadow off/on, otherwise // assume it is a filename for printing. if (argc > 2) { if (argv =~ "^$") { shdw = atoi(argv); } else { print = 1; } } Image yoixlogo = BuildYoixLogoImage(sz, Color.black, (sz >= 72) && shdw); if (print) { Stream output; if ((output = open(argv, "w")) != NULL) { encodeImage(yoixlogo, "png", output); close(output); } } else { JFrame jf = { int visible = TRUE; Dimension size = NULL; Array layout = { new JPanel { Dimension preferredsize = { double width = yoixlogo.size.width; double height = yoixlogo.size.height; }; Color background = Color.white; Image backgroundimage = yoixlogo; int backgroundhints = SCALE_NONE; }, }; }; }

Read more about this topic:  Yoix

Famous quotes containing the word examples:

    It is hardly to be believed how spiritual reflections when mixed with a little physics can hold people’s attention and give them a livelier idea of God than do the often ill-applied examples of his wrath.
    —G.C. (Georg Christoph)

    Histories are more full of examples of the fidelity of dogs than of friends.
    Alexander Pope (1688–1744)

    In the examples that I here bring in of what I have [read], heard, done or said, I have refrained from daring to alter even the smallest and most indifferent circumstances. My conscience falsifies not an iota; for my knowledge I cannot answer.
    Michel de Montaigne (1533–1592)