# 10 print chr$(205.5+rnd(1)); : goto 10

**URL:** <https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483>\
**Category:** Coding Questions\
**Created:** [November 14, 2019, 10:30am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483 "2019-11-14T10:30:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [November 14, 2019, 10:30am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/1 "2019-11-14T10:30:45Z")

</div>

10 PRINT CHR$(205.5+RND(1)); : GOTO 10

Can this be done in Processing? 😁

@jeremydouglass

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [November 14, 2019, 10:52am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/2 "2019-11-14T10:52:04Z")

</div>

Sure, but it’s a little different because reasons.

```auto
size(600,400);int x=0,y=0;while(y<height){while(x<width){if(random(2)<1) line(x,y,x+20,y+20);else line(x+20,y,x,y+20);x+=20;}x=0;y+=20;}

```

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [November 14, 2019, 10:57am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/3 "2019-11-14T10:57:53Z")

</div>

Thank you!!!

> [@TfGuy44](#):
>
> Sure, but it’s a little different because reasons.

```auto
size(600, 400);
int x=0, y=0;
while (y < height) {
  while (x < width)
  {
    if (random(2) < 1) line(x, y, x+20, y+20);
    else line(x+20, y, x, y+20);
    x+=20;
  }
  x=0;
  y+=20;
}

```

![amazing](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/da53d8e670abbb9d620099be629ccc5e69e8c889.png)

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [November 14, 2019, 11:01am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/4 "2019-11-14T11:01:01Z")

</div>

And of course then you can tinker with it to keep it from being boring.

```auto
size(1000, 1000);
background(0);
int x=0, y=0;
while (y<height) {
  while (x<width) {
    stroke(
      map(x,0,width,0,255),
      map(y,0,height,0,255),
      255-map(x+y,0,width+height,0,255)
    );
    if (random(2)<1){
      line(x, y, x+20, y+20);
    } else { 
      line(x+20, y, x, y+20);
    }
    x+=20;
  }
  x=0;
  y+=20;
}

```

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [November 14, 2019, 11:15am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/5 "2019-11-14T11:15:55Z")

</div>

Wheee!

```auto
class Lino {
  int x, y, ttb;
  boolean b;
  Lino(int ix, int iy) {
    x = ix;
    y = iy;
    ttb = 0;
    b = random(2)<1;
  }
  void draw() {
    stroke(
      map(x, 0, width, 0, 255), 
      map(y, 0, height, 0, 255), 
      255-map(x+y, 0, width+height, 0, 255)
      );
    if (b) {
      line(x, y, x+20, y+20);
    } else { 
      line(x+20, y, x, y+20);
    }
  }
  void swap(){
    b = !b;
  }
}

ArrayList<Lino> linos; 

void setup() {
  size(600, 600);
  linos = new ArrayList();
  int x=0, y=0;
  while (y<height) {
    while (x<width) {
      linos.add(new Lino(x,y));
      x+=20;
    }
    x=0;
    y+=20;
  }
}

void draw() {
  background(0);
  for( Lino lin : linos){
    lin.draw();
  }
  for( int t = 0; t < 10; t++){
    linos.get(int(random(linos.size()))).swap();
  }
}

```

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [November 14, 2019, 11:36am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/6 "2019-11-14T11:36:26Z")

</div>

Wow, wow and more wow! @TfGuy44

I think your first example is better because part of the aesthetic is to get the complexity into one line of code (or nearly).

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [November 14, 2019, 11:44am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/7 "2019-11-14T11:44:31Z")

</div>

> [@paulstgeorge](#):
>
> 10 PRINT CHR$(205.5+RND(1)); : GOTO 10

What a good old time. I want it back!

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [November 14, 2019, 1:05pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/8 "2019-11-14T13:05:52Z")

</div>

Is there a way to make it draw really slowly, line by line, turn by turn so we can see the maze being formed?

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 14, 2019, 2:27pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/9 "2019-11-14T14:27:24Z")

</div>

Replace the while with if and you‘ve got it slower (though the Speed depends on frameRate).

Like this :

```auto
void setup() {
   size(600, 400);
}
int x=0, y=0;
void draw() {
   if (y < height) {
      if (x < width)
      {
         if (random(2) < 1) line(x, y, x+20, y+20);
         else line(x+20, y, x, y+20);
         //x+=20;
      }
      //x=0;
      
      y+=20;
   } else {
      x+=20;
      y = 0;
   }
}

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [November 14, 2019, 3:09pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/10 "2019-11-14T15:09:08Z")

</div>

@paulstgeorge – great question!

In the 10 PRINT book, check out the section on Variations in Processing (105-118). We discuss using the console, basic output, and different methods of visual styling – with full code examples.

The one-liner is: **EDIT**

```auto
void draw() { print((random(1) < 0.5) ? '/' : '\\'); }

```

…although the result is different from a Commodore 64 display!

If you don’t have a copy of the book handy the full PDF is freely available from [http://10print.org](http://10print.org)

* * *

@TfGuy44 gives a long “one-liner” for visual output that is really compelling – a related way to approach that would be to create a char and then use text() rather than line().

@Lexyth gives a nice example of a typewriter-like display. Another method is to add a characters / bit each frame to a buffer, then loop over the whole buffer. This would lets you more easily mimic the line advance behavior when the screen fills.

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [November 14, 2019, 5:32pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/11 "2019-11-14T17:32:03Z")

</div>

Um, is

`void draw() {print((random(1) < 0.5 ? '/' : '\\'));}`

better? Even number of brackets, and ().

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [November 14, 2019, 5:35pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/12 "2019-11-14T17:35:25Z")

</div>

Excellent! I added frameRate(1); to your code @Lexyth and it works perfectly.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [November 14, 2019, 5:45pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/13 "2019-11-14T17:45:17Z")

</div>

> [@paulstgeorge](#):
>
> better?

Ah, yes–I fixed the typo in my post above.

Kids: don’t post ternary one-liners from your cell phone. Smokey the Bear says: test code first.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 14, 2019, 6:17pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/14 "2019-11-14T18:17:16Z")

</div>

> [@jeremydouglass](#):
>
> `void draw() { print((random(1) < 0.5) ? '/' : '\\'); }`

- More compact: `void draw(){print(random(2)<1?'/':'\\');}`
- For Python Mode: `def draw():this.print(random(2)<1and'/'or'\\')`

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [November 14, 2019, 7:08pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/15 "2019-11-14T19:08:06Z")

</div>

> [@jeremydouglass](#):
>
> If you don’t have a copy of the book handy the full PDF is freely available from [http://10print.org](http://10print.org)

10 Excellent book, thank you. Have just read it in one sitting.  
20 GOTO 10

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [November 15, 2019, 11:32am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/16 "2019-11-15T11:32:12Z")

</div>

This makes we want to fire up my C64!

This was my go at this:

```auto
size(500, 500);

int x = 0, y = 0;
int s = 25;
int r;

while (y < height) 
  {
  r = int(random(2))*s;
  line(x+r, y, x+s-r, y+s);
  x += s;
  if (x > width) 
    {
    y+=s;
    x=0;
    } 
  //println(x, y);  
  }
 

```

My attempt at this came out pretty much the same as others.  
I did the line a bit differently; tried to make it short and not use if() else().  
I looked at examples after and removed setup() and draw().

That was fun!

🙂

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [November 15, 2019, 12:35pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/17 "2019-11-15T12:35:32Z")

</div>

> [@glv](#):
>
> This was my go at this:

Very elegant. Yours also works with fewer lines:

```auto
size(500, 500);

int x = 0, y = 0;
int s = 25;
int r;

while (y < height) {r = int(random(2))*s; line(x+r, y, x+s-r, y+s); x += s; 
if (x > width) {y+=s; x=0;} }

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [November 16, 2019, 12:08am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/18 "2019-11-16T00:08:11Z")

</div>

A bit leaner:

```auto
size(500,500);int x=0,y=0;while(y<height){int r=int(random(2))*25;line(x+r,y,x+25-r,y+25);x+=25;if(x>width){y+=25;x=0;}}

```

```auto
size(500, 500);
int x=0, y=0;
while (y<height) {
  int r=int(random(2))*25;
  line(x+r, y, x+25-r, y+25);
  x+=25;
  if (x>width) {
    y+=25;
    x=0;
  }
}

```

🙂

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [November 16, 2019, 8:52am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/19 "2019-11-16T08:52:04Z")

</div>

Touché Truchet! @glv

OK, shall we make a group effort for a curved maze?

The result should look something like this.

![TruchetPattern_800](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/607cc23f0dd6bfd3905e2d2f0400ab2ea44c6fd0.gif)  
Each tile is randomly this:

```auto
noFill();
arc(25, 25, 50, 50, 0, HALF_PI);
arc(75, 75, 50, 50, PI, PI+HALF_PI);

```

or this:

```auto
noFill();
arc(25, 75, 50, 50, PI+HALF_PI, TWO_PI);
arc(75, 25, 50, 50, HALF_PI, PI);

```

The origins of each tile can be pulled from a 2D array (except I need help with that!). Or, there might be a better way to orientate and position the tiles.

```auto
int originX = 50;
int originY = 50;
noFill();
//this:
arc(originX-25, originY+25, 50, 50, PI+HALF_PI, TWO_PI);
arc(originX+25, originY-25, 50, 50, HALF_PI, PI);
// or this:
//arc(originX-25, originY-25, 50, 50, 0, HALF_PI);
//arc(originX+25, originY+25, 50, 50, PI, PI+HALF_PI);

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [November 16, 2019, 12:53pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/20 "2019-11-16T12:53:03Z")

</div>

Let’s do it!

So far…

I have an arcDraw() function for drawing the arcs:

```auto
int y = 50;
int x = 50;
int[] z = { -1, -1, +1, -1, +1, +1, -1, +1};

void setup() 
  {
  size(640, 360);
  noFill();
  }

void draw() 
  {
  arcs2();    
  }
  
void arcs2()
  {
  int originX = 50;
  int originY = 50;
  int a = 0;
  
  //Original from paulstgeorge
  //this:
  arc(originX-25, originY+25, 50, 50, PI+HALF_PI, TWO_PI);
  arc(originX+25, originY-25, 50, 50, HALF_PI, PI);
  // or this:
  arc(originX-25, originY-25, 50, 50, 0, HALF_PI);
  arc(originX+25, originY+25, 50, 50, PI, PI+HALF_PI);
 
  //Arcs rearranged above to find a pattern and used TAU for TWO_PI
  translate(100, 0);
  arc(originX-25, originY-25, 50, 50, 0*TAU/4, 1*TAU/4);
  arc(originX+25, originY-25, 50, 50, 1*TAU/4, 2*TAU/4);
  arc(originX+25, originY+25, 50, 50, 2*TAU/4, 3*TAU/4); 
  arc(originX-25, originY+25, 50, 50, 3*TAU/4, 4*TAU/4);  
  
  //Arcs wigh method()
  translate(100, 0);
  for (a = 0; a<4; a++)
    {     
    //arc(originX+z[2*a]*25, originY+z[2*a+1]*25, 50, 50, a*TAU/4, (a+1)*TAU/4);   
    arcDraw(a, 50, 50);
    }
  }

void arcDraw(int a, int originX, int originY)
  {
  arc(originX+z[2*a]*25, originY+z[2*a+1]*25, 50, 50, a*TAU/4, (a+1)*TAU/4);  
  }

```

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8ca0868727625ecae83bd48549591bcdfe3fce36.png)

🙂

[Next page](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483.md?page=2)
