Help us understand the problem. What is going on with this article?

忘年会で使えるかも?なモザイクゲーム用コード

More than 1 year has passed since last update.

背景と目的

忘年会シーズンが近づくにつれて、半ば無理やり幹事をさせられる新人さんのストレスは相当なものです。
そんな新人さんに手を差し伸べるべく、忘年会の余興に使えるかも?なモザイクゲームをProcessingで作成しました。

使用方法

キーボードのkをクリックすれば画像のモザイクが小さくなり、
キーボードのjをクリックすれば画像のモザイクが大きくなります。

PImage img;
MozImage moz;
float mozSize = 80;//初期のモザイクのサイズ
boolean sizeUp = true;
boolean sizeDown = true;

void setup() {
  background(0);
  img = loadImage("Lion.PNG");//画像の設定
  size(1143, 676);//キャンバスのサイズをの画像サイズに設定

  smooth();
  noStroke();
}

void draw() {  
  for (int i=0; i<width/mozSize; i++) {
    float x = mozSize * i;
    for (int j=0; j<height/mozSize; j++) {
      float y = mozSize * j;
      moz = new MozImage(int(x), int(y));
      moz.show();
    }
  }
}

void keyPressed() {
  if (sizeDown == true && key == 'k') {
    if(mozSize >10){
      mozSize -= 10;
    }else{
      mozSize = 1;
    }
    sizeDown = false;
  } else if (sizeUp == true && key == 'j') {
    mozSize += 10;
    sizeUp = false;
  }
}

void keyReleased() {
  sizeDown = true;
  sizeUp = true;
}

class MozImage {
  float x;
  float y;
  float r;
  MozImage(int _x, int _y) {
    x = _x;
    y = _y;
    r = mozSize;
  }
  void show() {
    color c = img.get(int(x), int(y));
    fill(c);
    noStroke();
    //ellipse(x,y,2*r,2*r);
    rect(x, y, r, r);
  }
}

使用例:

問題:この動物はなんでしょう!

ゲーム開始時の画像
ライオン1.PNG

徐々にモザイクを小さくしていって・・・
ライオン2.PNG

正解はこちら!
(元画像が拾い物なので省略)

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした