2022年11月20日日曜日

p5jsの透過処理バグ回避のシェーダーの設定

2022 11/20の時点でこのバグはまだ健在

https://discourse.processing.org/t/webgl-alpha-cant-be-used-as-a-texture/35981

の解決案のソースを参考にシェーダーの今回使わないライト設定を削り

createShader()したらバグが消えたようなので残しておく

シェーダーの必要な部分も消えてるかもしれないので挙動が怪しい場合は

上記記事から加工前のシェーダーを引っ張って来て使おう



<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/p5.js"></script>
<div id="p5canvas"></div>
<script>
	//Reference site
	//https://discourse.processing.org/t/webgl-alpha-cant-be-used-as-a-texture/35981

	let img;
	let buf;
	let shdr;
	let spritedata = '00101032323255bb30b27134f8300d0000400000014000000140000001500000105000005d55000115410000d51d4011415444055d5c5405455510011555400002800000028000000a8000002aa800';

	let camerax = 0;
	let cameray = 90;
	let cameraz = -300;
	let lookatx = 0;
	let lookatz = 0;

	let trees = [
		[0, 0, 200],
		[-200, 0, 200],
		[200, 0, 20]
	]

	//makeimage from hex strings with magnifi (1,2,4,8,16)
	function makeimage(hexstrings, magni) {
		let ix = hexstrings;
		//read header  "transparent num","imagew","imageh" [0~6] (3byte)
		let tpc = parseInt(ix.slice(0, 2), 16);
		let imgw = parseInt(ix.slice(2, 4), 16);
		let imgh = parseInt(ix.slice(4, 6), 16);
		let imagemap = [];
		//read color palet "palet rgb(3yite)"x3 [6~30] (24 = 12byte = 4x3)
		let colorpalet = [];
		for (let i = 0; i < 4; i++) {
			let rgba = [];
			for (let j = 0; j < 3; j++) {
				rgba.push(parseInt(
					//head + rgb(3byte)+r(1byte)+g(1byte)+b(1byte) (1byte=2char)
					ix.slice(6 + i * 6 + j * 2, 8 + i * 6 + j * 2), 16));
			}
			if (tpc == i) {
				rgba.push(0);
			} else {
				rgba.push(255);
			}
			colorpalet.push(rgba);
		}
		//read pixels color one pixel 4 bit   [30~EOF] (4bit *2 =1byte=2pixels)
		for (let i = 30; i < ix.length; i++) {
			let onebyte = parseInt(ix[i], 16);
			let upper = parseInt(onebyte / 4);
			let lower = onebyte % 4;
			imagemap.push(upper);
			imagemap.push(lower);
		}
		let himg = createImage(imgw * magni, imgh * magni);
		himg.loadPixels();

		for (let y = 0; y < himg.height; y++) { ///magnifi; y++) {
			for (let x = 0; x < himg.width; x++) { ///magnifi; x++) {
				let index = (x + y * himg.width) * 4;
				let cnum = imagemap[
					parseInt(x / magni) +
					parseInt(y / magni) * imgw];

				himg.pixels[index] = colorpalet[cnum][0];
				himg.pixels[index + 1] = colorpalet[cnum][1];
				himg.pixels[index + 2] = colorpalet[cnum][2];
				himg.pixels[index + 3] = colorpalet[cnum][3];
			}
		}
		himg.updatePixels();
		return himg;
	}
	//camera turn
	function mouseDragged() {
		lookatx += (pmouseX - mouseX) * 0.01;
		lookatz += (pmouseY - mouseY) * 0.01;
		if (lookatx > TWO_PI) lookatx -= TWO_PI; //loop
		if (lookatx < 0) lookatx += TWO_PI;
		if (lookatz > PI + QUARTER_PI) lookatz = PI + QUARTER_PI; //no loop
		if (lookatz < PI - QUARTER_PI) lookatz = PI - QUARTER_PI;
	}
	// camera move
	function keyinput() {
		let zx = cos(lookatx) * 5;
		let zz = sin(lookatx) * 5;
		if (keyIsDown(87)) { //w
			camerax += zx;
			cameraz += zz;
		} else
		if (keyIsDown(83)) { //s
			camerax -= zx;
			cameraz -= zz;
		}
		zx = cos(lookatx + HALF_PI) * 5;
		zz = sin(lookatx + HALF_PI) * 5;
		if (keyIsDown(65)) { //a
			camerax -= zx;
			cameraz -= zz;
		} else
		if (keyIsDown(68)) { //d
			camerax += zx;
			cameraz += zz;
		}
	}

	function setup() {
		img = makeimage(spritedata, 16);
		lookatz = 3.5; // PI;
		lookatx = 1.6; // HALF_PI;

		createCanvas(700, 400, WEBGL).parent("p5canvas");
		shdr = createShader(vert, frag);
		shader(shdr);
		noStroke();
	}


	function draw() {
		background(150, 150, 255);
		keyinput();
		shdr.setUniform('mydiffuse', sin(frameCount * 0.01));
		camera(camerax, cameray, cameraz,
			(cos(lookatx) * -cos(lookatz)) + camerax,
			sin(lookatz) + cameray,
			sin(lookatx) + cameraz, 0.0, 1.0, 0.0);

		for (let [x, y, z] of trees) {
			push();
			translate(x, y, z);
			rotateY(QUARTER_PI);
			texture(img);
			plane(255);
			rotateY(HALF_PI);
			plane(255);
			pop();
		}

		push();
		fill(0, 255, 0);
		translate(0, 127, 0);
		rotateX(HALF_PI);
		plane(1000);
		pop();

		push();
		translate(0, 0, 0);
		rotateY(frameCount * 0.01);
		texture(img);
		plane(255);
		rotateY(HALF_PI);
		plane(255);
		pop();
	}


	let vert = `
		precision highp float;
		precision highp int;

		uniform bool uUseLighting;
		uniform float mydiffuse;

		void totalLight(
		  vec3 modelPosition,
		  vec3 normal,
		  out vec3 totalDiffuse,
		  out vec3 totalSpecular
		) {
		  totalSpecular = vec3(0.0);
		  if (!uUseLighting) {
		    totalDiffuse = vec3(mydiffuse);
		    return;
		  }
		  totalDiffuse = vec3(0.0);
		  vec3 viewDirection = normalize(-modelPosition);
		}

		attribute vec3 aPosition;
		attribute vec3 aNormal;
		attribute vec2 aTexCoord;

		uniform mat4 uModelViewMatrix;
		uniform mat4 uProjectionMatrix;
		uniform mat3 uNormalMatrix;

		varying highp vec2 vVertTexCoord;
		varying vec3 vDiffuseColor;
		varying vec3 vSpecularColor;

		void main(void) {
		  vec4 viewModelPosition = uModelViewMatrix * vec4(aPosition, 1.0);
		  gl_Position = uProjectionMatrix * viewModelPosition;

		  vec3 vertexNormal = normalize(uNormalMatrix * aNormal);
		  vVertTexCoord = aTexCoord;

		  totalLight(viewModelPosition.xyz, vertexNormal, vDiffuseColor, vSpecularColor);
		}`;
	let frag = `
		precision highp float;

		uniform vec4 uMaterialColor;
		uniform vec4 uTint;
		uniform sampler2D uSampler;
		uniform bool isTexture;
		uniform bool uEmissive;

		varying highp vec2 vVertTexCoord;
		varying vec3 vDiffuseColor;
		varying vec3 vSpecularColor;

		void main(void) {
		  if(uEmissive && !isTexture) {
		    gl_FragColor = uMaterialColor;
		  }
		  else {
		    gl_FragColor = isTexture ? texture2D(uSampler, vVertTexCoord) * (uTint / vec4(255, 255, 255, 255)) : uMaterialColor;
		    gl_FragColor.rgb = gl_FragColor.rgb * vDiffuseColor + vSpecularColor;
		  }

		  if (gl_FragColor.a == 0.0) {
		    discard;
		  }
		}`;
</script>

image 拡大問題は解決したが透過処理のバグが出てくるp5js

Base64文字列からimageを作る ... ○
image で拡大して表示    ... △ めっちゃぼやける
    pixelを読み込んで拡大imageを作る .... ×
        Base64で読み込むのがOUTぽい

自前フォーマットでimageを作る ...○
pixelを読み込んで拡大imgを作る... ○
WebGL の3D のPLANEのテクスチャに設定...○
    テクスチャの透過処理... ×

2022 11/20時点でデフォルトのシェーダーだとこうなる
この一文が在るので https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/p5.js
ここはこのまま、
次の投稿はこの問題の解決案

1pixel 4bit color のimage のデータを文字列で出力するエディタをp5jsでつくった


Base64で読み込んだimageで.loadPixels()を呼ぶとエラーがでるので

(2022 11/20現在)自前のフォーマットでimageデータ文字列を作ることに

したのでそれ用の簡易エディタを残しておく

作った文字列は下記の関数でimageに変換できる

引数は独自フォーマットの16進数文字列と拡大したい倍率

戻り値はimage

let myimage=makeimage(hexstrings,

で動くはず

上部

左からcanvas,色選択用のrect,カラーピッカー,透過パレットチェックボックス

中部

”magnifi select”(倍率)これはエディタでのみでデータにはならない

”outputsize” 出力画像サイズこれで倍率を選ぶと下部のtextareaに

データが出力される

下部

”output hex” 16進数 画像データ文字列, これをコピペして使う

”canvas crear ”canvasをクリアする

”input hex hera” ここに再編集したい文字列データを貼り付け

hex read をクリックするとcanvasに読み込み

1pixel 3色(透過の有り)か4色が使える(透過なし)

もしかしたらtextarea とかcolorpickerの表示位置が

ずれてるかもしれないが致し方なし。


//makeimage from hex strings with magnifi (1,2,4,8,16)
	function makeimage(hexstrings, magni) {
		let ix = hexstrings;
		//read header  "transparent num","imagew","imageh" [0~6] (3byte)
		let tpc = parseInt(ix.slice(0, 2), 16);
		let imgw = parseInt(ix.slice(2, 4), 16);
		let imgh = parseInt(ix.slice(4, 6), 16);
		let imagemap = [];
		//read color palet "palet rgb(3yite)"x4 [6~30] (24 = 12byte = 4x3)
		let colorpalet = [];
		for (let i = 0; i < 4; i++) {
			let rgba = [];
			for (let j = 0; j < 3; j++) {
				rgba.push(parseInt(
					//head + rgb(3byte)+r(1byte)+g(1byte)+b(1byte) (1byte=2char)
					ix.slice(6 + i * 6 + j * 2, 8 + i * 6 + j * 2), 16));
			}
			if (tpc == i) {
				rgba.push(0);
			} else {
				rgba.push(255);
			}
			colorpalet.push(rgba);
		}
		//read pixels color one pixel 4 bit   [30~EOF] (4bit *2 =1byte=2pixels)
		for (let i = 30; i < ix.length; i++) {
			let onebyte = parseInt(ix[i], 16);
			let upper = parseInt(onebyte / 4);
			let lower = onebyte % 4;
			imagemap.push(upper);
			imagemap.push(lower);
		}
		let himg = createImage(imgw * magni, imgh * magni);
		himg.loadPixels();

		for (let y = 0; y < himg.height; y++) { ///magnifi; y++) {
			for (let x = 0; x < himg.width; x++) { ///magnifi; x++) {
				let index = (x + y * himg.width) * 4;
				let cnum = imagemap[
					parseInt(x / magni) +
					parseInt(y / magni) * imgw];

				himg.pixels[index] = colorpalet[cnum][0];
				himg.pixels[index + 1] = colorpalet[cnum][1];
				himg.pixels[index + 2] = colorpalet[cnum][2];
				himg.pixels[index + 3] = colorpalet[cnum][3];
			}
		}
		himg.updatePixels();
		return himg;
	}

2022年11月16日水曜日

p5js 3d でFPSっぽいキー入力とマウス入力

いつぞやのコードが見つかったのでこちらに残す

3dでのキーとマウス入力


”A,S,D,F"で移動、マウスドラッグで方向転換



<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/p5.js"></script>
<div id="p5canvas"></div>
<script>
	let camerax = 0;
	let cameray = 700;
	let cameraz = -350;
	let lookatx = 0;
	let lookatz = 0;

	function setup() {
		createCanvas(700, 400, WEBGL).parent("p5canvas");
		lookatz = 3.5; // PI;
		lookatx = 1.6; // HALF_PI;
	}
	//camera turn
	function mouseDragged() {
		lookatx += (pmouseX - mouseX) * 0.01;
		lookatz += (pmouseY - mouseY) * 0.01;
		if (lookatx > TWO_PI) lookatx -= TWO_PI; //loop
		if (lookatx < 0) lookatx += TWO_PI;
		if (lookatz > PI + QUARTER_PI) lookatz = PI + QUARTER_PI; //no loop
		if (lookatz < PI - QUARTER_PI) lookatz = PI - QUARTER_PI;
	}

	// camera move
	function keyinput() {
		let zx = cos(lookatx) * 5;
		let zz = sin(lookatx) * 5;
		if (keyIsDown(87)) { //w
			camerax += zx;
			cameraz += zz;
		}else
		if (keyIsDown(83)) { //s
			camerax -= zx;
			cameraz -= zz;
		}
		zx = cos(lookatx + HALF_PI) * 5;
		zz = sin(lookatx + HALF_PI) * 5;
		if (keyIsDown(65)) { //a
			camerax -= zx;
			cameraz -= zz;
		}else
		if (keyIsDown(68)) { //d
			camerax += zx;
			cameraz += zz;
		}
	}

	function draw() {
		background(250);
		camera(camerax, cameray, cameraz,
			(cos(lookatx) * -cos(lookatz)) + camerax,
			sin(lookatz) + cameray,
			sin(lookatx) + cameraz, 0.0, 1.0, 0.0); //
		keyinput();
		noStroke();
		normalMaterial();
		//ambientMaterial(255,255,255);
		//directionalLight(255,255,255, 0, 1, 0);
		push();
		translate(0, 0, 800);
		plane(1600);
		translate(0, 0, -1600);
		plane(1600);
		translate(0, 800, 800);
		rotateX(PI / 2);
		plane(1600);
		pop();

		beginShape(); // 閉矩形
		vertex(100, 0, -500);
		vertex(100, 100, -500);
		vertex(0, 100, -500);
		endShape(CLOSE);

		translate(-240, 400, 0);

		push();
		rotateZ(frameCount * 0.01);
		rotateX(frameCount * 0.01);
		rotateY(frameCount * 0.01);
		plane(70);
		pop();

		translate(240, 0, 0);
		push();
		rotateZ(frameCount * 0.01);
		rotateX(frameCount * 0.01);
		rotateY(frameCount * 0.01);
		box(70, 70, 70);
		pop();

		translate(240, 0, 0);
		push();
		rotateZ(frameCount * 0.01);
		rotateX(frameCount * 0.01);
		rotateY(frameCount * 0.01);
		cylinder(70, 70);
		pop();

		translate(-240 * 2, 200, 0);
		push();
		rotateZ(frameCount * 0.01);
		rotateX(frameCount * 0.01);
		rotateY(frameCount * 0.01);
		cone(70, 70);
		pop();

		translate(240, 0, 0);
		push();
		rotateZ(frameCount * 0.01);
		rotateX(frameCount * 0.01);
		rotateY(frameCount * 0.01);
		torus(70, 20);
		pop();

		translate(240, 0, 0);
		push();
		rotateZ(frameCount * 0.01);
		rotateX(frameCount * 0.01);
		rotateY(frameCount * 0.01);
		sphere(70);
		pop();
	}
</script>

2022年11月8日火曜日

迷路作成アルゴリズム p5jsで作る ループ有り

 ループ有りの迷路が作れたので残しておく

ゲームだと背後に回り込むとかできるので

使えそう



<!DOCTYPE html>
<html lang="en">
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/p5.js"></script>
<div id="p5canvas"></div>

<script>
	class mymaze {
		writex = 0;
		writey = 0;
		msize = 0;
		state = 0;
		possiblesize = 0;
		maze = [];
		xtable = [2, -2, 0, 0];
		ytable = [0, 0, 2, -2];
		constructor(n) {
			this.msize = n;
		}


		mazeloop() {
			switch (this.state) {
				//pass through candidate points
				case 0:
					this.writex += 2;
					if (this.writex > this.msize - 2) {
						this.writex = 2;
						this.writey += 2;
					}
					if (this.writey > this.msize - 2)
						this.writey = 2;

					if (this.maze[this.writey][this.writex] == 0) {
						this.maze[this.writey][this.writex] = 2;
						this.possiblesize--;

						this.state = 1;
					}
					break;


				case 1:
					let direction = parseInt(Math.random() * 4);
					let addx = this.xtable[direction];
					let addy = this.ytable[direction];
					switch (this.maze[this.writey + addy][this.writex + addx]) {
						case 0:
							this.possiblesize--;
							this.maze[this.writey + addy][this.writex + addx] = 2;
							this.maze[this.writey + addy / 2][this.writex + addx / 2] = 2;
							this.writex += addx;
							this.writey += addy;
							break;
						case 1:
							this.maze[this.writey + addy / 2][this.writex + addx / 2] = 2;
							this.state = 2;
							break;
						case 2:
							this.state = 2;
							break;
					}
					break;

				case 2:
					for (let i = 1; i < this.msize - 1; i++) {
						for (let j = 1; j < this.msize - 1; j++) {
							if (this.maze[i][j] == 2)
								this.maze[i][j] = 1;
						}
					}
					this.state = 0;
					if (this.possiblesize <= 0)
						this.state = 4;
					break;
				case 4:
					this.writex = 1;
					this.writey = 1;
					break;
			}
		}

		mazeinit() {
			this.state = 0;
			let row = [];
			for (let i = 0; i < this.msize; i++) {
				row = [];
				for (let j = 0; j < this.msize; j++) {
					if (i == 0 || i == this.msize - 1 || j == 0 || j == this.msize - 1)
						row.push(1);
					else
						row.push(0);
				}
				this.maze.push(row);
			}
			this.writex = 2;
			this.writey = 2;
			//'n*2-1'=insid width ;'n*2'=block and space;'-1'=del extra space;'4'=(side block and space)*2
			this.possiblesize = (this.msize - 3) / 2; //n*2-1+4=maze_width ->  n=(maze_width-3)/2;
			this.possiblesize *= this.possiblesize;
		}
	}

	let mazesize = 21; //maze width height ,it must odd number
	let maze;

	function setup() {
		createCanvas(500, 500).parent("p5canvas");
		textSize(17);
		noStroke();

		maze = new mymaze(mazesize);
		maze.mazeinit();
	}

	function mousePressed() {
		maze = [];
		maze = new mymaze(mazesize);
		maze.mazeinit();
	}

	function draw() {
		background(100);
		let tilesize = parseInt(500 / (mazesize + 4));
		translate(tilesize * 2, tilesize * 2);
		maze.mazeloop();
		fill(255);
		for (let i = 0; i < maze.msize; i++)
			for (let j = 0; j < maze.msize; j++) {
				if (maze.maze[i][j] == 1) {
					fill(200);
					rect(j * tilesize, i * tilesize, tilesize - 2);
				} else if (maze.maze[i][j] == 2) {
					fill(100, 200, 100);
					rect(j * tilesize, i * tilesize, tilesize - 2);
				}
				if (maze.writex == j && maze.writey == i) {
					fill(255);
					rect(j * tilesize, i * tilesize, tilesize - 2);
				}
			}
		translate(-tilesize * 2, -tilesize * 2);
	}
</script>
</html>

2022年11月7日月曜日

クラスカル法

chat-gptにきいたらおしえてくれた

                                                   参考動画



<!DOCTYPE html>
<html lang="en">
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/p5.js"></script>
<div id="p5canvas"></div>

<script>

class Graph {
  constructor() {
    this.vertices = [];
    this.edges = [];
  }

  addVertex(x, y) {
    this.vertices.push({ x, y });
  }

  addEdge(source, destination, weight) {
    if (this.vertices[source] && this.vertices[destination]) {
      this.edges.push({ source, destination, weight });
    } else {
      throw new Error("Invalid vertex");
    }
  }

  find(parents, vertex) {
    if (parents[vertex] === -1) {
      return vertex;
    }
    return this.find(parents, parents[vertex]);
  }

  union(parents, x, y) {
    const xRoot = this.find(parents, x);
    const yRoot = this.find(parents, y);
    parents[xRoot] = yRoot;
  }

 
  kruskalWithSteps() {
    const mst = [];
    const parents = Array(this.vertices.length).fill(-1);

    this.edges.sort((a, b) => a.weight - b.weight);

    for (let i = 0; i < this.edges.length; i++) {
    
  console.log("step",i);
      const { source, destination, weight } = this.edges[i];
      const sourceRoot = this.find(parents, source);
      const destinationRoot = this.find(parents, destination);

      if (sourceRoot !== destinationRoot) {
        mst.push({ source, destination, weight });
        this.union(parents, sourceRoot, destinationRoot);
      }
      
            console.log("Step:", i + 1);
      console.log("Minimum Spanning Tree:", mst);
      console.log("====================");
    }

    return mst;
  }


   findSingletonVertices(mstEdges,start,goal) {
    const vertexCount = new Map();

    for (const edge of mstEdges) {
      vertexCount.set(edge.source, (vertexCount.get(edge.source) || 0) + 1);
      vertexCount.set(edge.destination, (vertexCount.get(edge.destination) || 0) + 1);
    }
    
    const singletonVertices = [];

   for (const [vertex, count] of vertexCount) {
      if (count === 1 && vertex !== start && vertex !== goal) {
        singletonVertices.push(vertex);
      }
    }


  return mstEdges.filter(edge => !singletonVertices.includes(edge.source) && !singletonVertices.includes(edge.destination));

    //return singletonVertices;
  }
  
  removeEdgesConnectedToVertices(edges, vertices) {
    return edges.filter(edge => !vertices.includes(edge.source) && !vertices.includes(edge.destination));
  }

  
}
  
  
function getRandomInt(max) {
  return Math.floor(Math.random() * max);
}


// 使用例

let graph ;
let mstEdges ;
let singletonVertices;
let remainingEdges;
let startVertex ;
let endVertex ;
let hubVertices ;

const vtx=[50,200,350,500,125,275,425,125,275,425];
const vty=[150,150,150,150,75,75,75,225,225,225];


const edges=[
 [0,1,5],[1,2,5],[2,3,5],
 [4,5,5],[5,6,5],[7,8,5],[8,9,5],
 [0,4,5],[0,7,5],[1,4,5],[1,7,5],
 [1,5,5],[1,8,5],[2,5,5],[2,8,5],
 [2,6,5],[2,9,5],[3,6,5],[3,9,5],
 ];
 

function runKruskal(){ 
 graph = new Graph(); 
 
 for(let i=0;i<vtx.length;i++){
  graph.addVertex(vtx[i], vty[i]); 
 }

 for(let i=0;i<edges.length;i++){
  graph.addEdge(edges[i][0],edges[i][1],getRandomInt(10)+1); 
 }
 
 startVertex = 0;
 endVertex = 3; 
 
 
 mstEdges = graph.kruskalWithSteps(graph.kruskalWithSteps());
  
 remainingEdges = graph.findSingletonVertices(mstEdges,startVertex,endVertex); 


 mstEdges.forEach(edge => {
  console.log(`Source: ${edge.source}, Destination: ${edge.destination}, Weight: ${edge.weight}`);
});
 
  console.log(singletonVertices);

  console.log(remainingEdges);
}



function setup() {
 createCanvas(550, 500).parent("p5canvas");
 textSize(17);
 runKruskal();
}


  
function mousePressed() {
 runKruskal();
}
 
 

function draw() {
  background(100);
  
  stroke(255, 255, 155);
  strokeWeight(1);
  for(let i=0;i<graph.vertices.length;i++){
   fill(255);
   circle(graph.vertices[i].x,graph.vertices[i].y,15);
  }
  

  for(let i=0;i<graph.edges.length;i++){
   let snum=graph.edges[i].source;
   let dnum=graph.edges[i].destination;

   let x1=graph.vertices[snum].x;
   let y1=graph.vertices[snum].y;
   let x2=graph.vertices[dnum].x;
   let y2=graph.vertices[dnum].y;
   line(x1,y1,x2,y2);
  }
  
  for(let i=0;i<graph.vertices.length;i++){
   fill(255);
   text(i,graph.vertices[i].x,graph.vertices[i].y-10);
  }
  
  stroke(0, 0, 255);
  fill(255,255,255);
  for(let i=0;i<graph.edges.length;i++){
   let snum=graph.edges[i].source;
   let dnum=graph.edges[i].destination;

   let x1=graph.vertices[snum].x;
   let y1=graph.vertices[snum].y;
   let x2=graph.vertices[dnum].x;
   let y2=graph.vertices[dnum].y;
   text(graph.edges[i].weight,(x1+x2)/2,(y1+y2)/2-10);
  }
  
  stroke(200,255,200);
  strokeWeight(5);
  
  for(let i=0;i<mstEdges.length;i++){
   let snum=mstEdges[i].source;
   let dnum=mstEdges[i].destination;

   let x1=graph.vertices[snum].x;
   let y1=graph.vertices[snum].y;
   let x2=graph.vertices[dnum].x;
   let y2=graph.vertices[dnum].y;
   line(x1,y1,x2,y2);
  }
 }
</script>

</html>

Arduino IDE が "Downloading index: library_index.tar.bz2" で固まる問題

PCとのシリアル通信が原因の一つらしい '/home/usename/.arduino15/packages' を消すといいらしい ので消すと治った IDEの起動中にフリーズしてたのが治った Downloading index: library_ind...