Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <title>City Generator Test</title>
<canvas id="myCanvas" width="1000" height="1000"></canvas>
<!-- <form>
  <button id="regenerate"> Regenerate </button>
</form> -->


  margin: 0px;
  padding: 0px;
  font-family: 'Lato', sans-serif;
  oveflow: hidden;
body {
  margin: 0px;
  padding: 0px;
  overflow: hidden;
  margin: 0px;
  padding: 0px;
  border:1px solid black;


                const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');

var roads = [];
var bldgs = [];

function road(x,y,x2,y2,width,length) {
  this.x = x;
  this.y = y;
  this.x2 = x2;
  this.y2 = y2;
  this.width = width;
  this.length = length;

function bldg(x, y, eccen, size) {
    this.x = x; // 0 -> Width 
    this.y = y; // 0 -> Height
    this.eccen = eccen; //Eccentricity, how close to a perfect square the building is.
    this.size = size; //How wide the base of the building is, height is determined by content.
//------------Road Builder----------------
var x1,y1,x2,y2;
var secondPoint = false;
var roadsPath = new Path2D;

function addRoad(){
  if (!secondPoint){
    x1 = event.clientX;
    y1 = event.clientY;
    secondPoint = true;
  } else if(secondPoint) {
    x2 = event.clientX;
    y2 = event.clientY;
    secondPoint = false;
    if (distanceFromPointToLine(0,0,x1,y1,x2,y2,100)) {
      ctx.strokeStyle = 'green';
    } else {
      ctx.strokeStyle = 'red';
//------------Building Builder------------

function init() {
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;
  //Generate Layout
function showMap(){//Draws each frame
  //ctx.clearRect(0, 0, canvas.width, canvas.height); // clear canvas
  // var bldg61 = new Path2D;
  // bldg61.moveTo(10,10);
  // bldg61.lineTo(20,20);
  // bldg61.lineTo(30,50);
  // bldg61.lineTo(10,40);
  // bldg61.closePath();
  ctx.strokeStyle = 'green';

function boundingBoxOfLine(x1, y1, x2, y2){
  //get rectangle with spacing around line

function placeBuildingsAroundLine(){
  // for (var i=0; i< 50 ; i++){
  //   var rx = Math.random
  // }

function getRandomInt(min, max) {
  var diff = max - min;
  return Math.floor(Math.random() * Math.floor(diff));

function formulaOfLine(x1, y1, x2, y2) { //Coordinates of points of a line
  var a = y2 - y1;
  var b = x1 - x2;
  var c = (a * x1) + (b * y1);
  c = -c;
  var pieces = [a, b, c];
  return pieces;

function distanceFromPointToLine(px, py, x1, y1, x2, y2, max, min = 0){
  var eq = formulaOfLine(x1,y1,x2,y2);
  var dToLine = (Math.abs((eq[0]*px) + (eq[1]*py) + (eq[2]))/Math.hypot(eq[0],eq[1]));
  if (dToLine < max && dToLine > min) {
    return true;
  }else {
    return false; 
canvas.addEventListener('click', addRoad);