HIEROGLYPHS

Part of the ReCode Project (recodeproject.com)
recodeproject.com/artwork/v3n2untitled-marcus1
Based on "Untitled 1" by Aaron Marcus
Originally published in "Computer Graphics and Art" v3n2, 1978
Copyright (c) 2013 Arnaud Coolsaet - OSI/MIT license

Log in to post a comment.

// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(-1);
/*
http://recodeproject.com/translation/arnaud-coolsaet-recode-hieroglyphs-direct-untitled-1-aaron-marcus
Part of the ReCode Project (http://recodeproject.com)
Based on "Untitled 1" by Aaron Marcus
Originally published in "Computer Graphics and Art" v3n2, 1978
Copyright (c) 2013 Arnaud Coolsaet - OSI/MIT license (http://recodeproject/license).
*/

// Global code will be evaluated once.
const turtle = new Turtle();
turtle.penup();
let xPosStart, prevEl;
let incrementBoxes = true;
let rowStarted = true;
let rowCount = 25;
let boxIndex = 0.1;
let xPos = 0;
let yPos = 15;
const width = 400;

// set 'random' x-position according to shape & previous shape
const randomX = what => {
  if ( rowStarted === true ) {
    rowStarted = false;
    xPos = 80 + Math.random() * 100;
    xPosStart = xPos;
  } else {
    if ( what === "circle" ) {
        xPos += 15;
    } else if ( prevEl === "box" || prevEl === "circle" ) {
        xPos += 12 + Math.random() * 5;
    } else if ( what === "dot" && ( prevEl === "dot" || prevEl === "line" ) ) {
        xPos += 7;
    } else {
        xPos += 2 + Math.random() * 8;
    }
  }
  prevEl = what;
}
const circle = (x, y, r) => {
    x *= 0.5;
    y *= 0.5;
    r *= 0.5;
    turtle.goto(x - 100, y - 100 - r / 2);
    turtle.down();
    turtle.circle(r / 2);
    turtle.up();
}
const rect = (x0, y0, w0, h0) => {
    x0 *= 0.5;
    y0 *= 0.5;
    w0 *= 0.5;
    h0 *= 0.5;
    turtle.goto(x0 - 100, y0 - 100);
    turtle.down();
    for (let x = x0 - 100; x <= x0 + w0 - 100; x += 0.2 ) {
        turtle.goto(x, y0 - 100);
        turtle.goto(x, y0 + h0 - 100);
    }
    turtle.up();
}
const line = (x0, y0, x1, y1) => {
    x0 *= 0.5;
    y0 *= 0.5;
    x1 *= 0.5;
    y1 *= 0.5;
    turtle.goto(x0 - 100, y0 - 100);
    turtle.down();
    turtle.goto(x1 - 100, y1 - 100);
    turtle.up();
}
const twoTrema = () => {
  rect(xPos-1, yPos-2, 0.4, 2);
  rect(xPos-3, yPos-2, 0.4, 2);
  rect(xPos+7, yPos-2, 0.4, 2);
  rect(xPos+9, yPos-2, 0.4, 2);
}
const oneCirc = () => {
  line( xPos + 5, yPos-1, xPos+7, yPos-3 );
  line( xPos + 7, yPos-3, xPos + 9, yPos-1 );
line( xPos + 5, yPos-1+0.2, xPos+7, yPos-3+0.2 );
  line( xPos + 7, yPos-3+0.2, xPos + 9, yPos-1+0.2 );
}
const aCircle = () => {
  randomX( "circle" );
  circle( xPos, yPos + 5, 8 );
  circle( xPos, yPos + 5, 7 );
  circle( xPos, yPos + 5, 6 );
}
const aDot = () => {
  randomX( "dot" );
  rect( xPos, yPos+6, 2, 2 );
}
const aBar = () => {
  randomX( "bar" );
  const shorter = Math.random() < 0.5 ? 1 : 0;
  line( xPos, (yPos + shorter), xPos, (yPos + 12 - (shorter * 3)) );
  line( xPos + 0.2, (yPos + shorter), xPos + 0.2, (yPos + 12 - (shorter * 3)) );
}
const aBox = () => {
  randomX( "box" );
  if ( Math.random() < 0.5 - boxIndex ) {
  } else {
    const rGlitch = Math.random();
    if ( rGlitch < 0.2 ) {
      twoTrema();
    } else if ( rGlitch > 0.2 && rGlitch < 0.4 ) {
      oneCirc();
    }
  }
  rect( xPos+1, yPos+1, 8, 8 );
}
// The walk function will be called until it returns false.
function walk(i) {
    const rIndex = Math.random() * 15;
    // increment possible range for boxes
    if ( incrementBoxes && rIndex >= 0 && rIndex <= boxIndex && boxIndex < 12 ) {
        aBox();
        boxIndex += Math.random() / 5;
    }
    // else distribute them through fixed range
    else if ( !incrementBoxes && rIndex >= 3 && rIndex <= 6 ) {
        aBox();
    }
    // ranges for other shapes
    else if ( rIndex >= 7  && rIndex <= 8 && rowCount < 27 && rowCount > 19 ) {
      aCircle();
    }
    else if ( rIndex >= 9  && rIndex <= 10) {
      aDot();
    }
    else {
      aBar();
    }
    // set new line
    if ( xPos >= (width - xPosStart) ) {
      rowCount--;
      yPos += 15;
      rowStarted = true;
    }
    return rowCount > 0;
}