1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

バイナリ変換した適当な文字列からロゴを作成する

Last updated at Posted at 2024-11-10

p5.jsを使う。
https://p5js.org/

let phrase = "なにか適当な文字列";
  let binaryRepresentation = stringToUTF16Binary(phrase);
  binaryRepresentation += '0000'

function dotGrid() {
  
  let xDist = 10;
  let yDist = 10;

  let xOffset = 50;
  let yOffset = 50;

  let r0 = 1;
  let r1 = 5;

  let phrase = "なにか適当な文字列";
  let binaryRepresentation = stringToUTF16Binary(phrase);

  console.log(`Binary representation of "${phrase}": ${binaryRepresentation}`);

  binaryRepresentation += '0000'

  const colsPerRow = 10;

  background(255);
  fill('black')
  for (let i = 0; i < binaryRepresentation.length; i++) {
    const x = i % colsPerRow * xDist + xOffset;
    const y = Math.floor(i/colsPerRow) * yDist + yOffset;
    const b = binaryRepresentation[i];
    
    circle(x, y, b === '0' ? r0 : r1);
    
  }
  
}

function dotGridAnimated() {
  
  let xDist = 10;
  let yDist = 10;

  let xOffset = 50;
  let yOffset = 350;

  let r0 = 2;
  let r1 = 5;

  const colsPerRow = 10;
  
  fill('white')
  strokeWeight(0)
  rect(xOffset-10, yOffset-10, 200, 200)

  fill('black')
  
  for (let i = 0; i < Math.min((millis()/10) % (binaryRepresentation.length + 100), binaryRepresentation.length); i++) {
    const x = i % colsPerRow * xDist + xOffset;
    const y = Math.floor(i/colsPerRow) * yDist + yOffset;
    const b = binaryRepresentation[i];
    
    circle(x, y, b === '0' ? r0 : r1);
    
  }
  
}

function lines() {
  
  let xDist = 10;
  let yDist = 10;

  let xOffset = 50;
  let yOffset = 200;

  let r0 = 1;
  let r1 = 10;

  let phrase = "なにか適当な文字列";
  let binaryRepresentation = stringToUTF16Binary(phrase);

  console.log(`Binary representation of "${phrase}": ${binaryRepresentation}`);


  const colsPerRow = 10;

  let x = xOffset;
  let y = yOffset;
  let xMax = 180;

  fill('black')
  stroke('black')
  strokeWeight(1);
  
  for (let i = 0; i < binaryRepresentation.length; i++) {
    const b = binaryRepresentation[i];
    const len = b === '0' ? r0 : r1;
    line(x, y, x+len, y);
    x += len + xDist;
    if(x >= xMax){
      x = xOffset;
      y += yDist;
    }
    
    
  }
  
}

function setup() {
  createCanvas(800, 800);
    background(255);
  dotGrid();
  lines();
}

function draw() {
  dotGridAnimated();
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?