OneHourProcessing 一日目
OneHourProcessingとは?
OneHourProcessingとは、この僕、霜暮黒夢がなんとなく思い付きで始めたものです。
ルールは、「1時間でProcessingのプログラムを書く」というもの。
とりあえずそれだけです。
もしかしたら3日坊主どころか1日坊主になりそうな所ですが、とりあえず頑張ってみます。
一日目の作品
今日作ったのはこれ。
#OneHourProcessing#Processing
— 霜暮黒夢@V高専生 (@V_hero_aid) August 4, 2020
一日目の作品です
作るのにかかった時間は「1時間15分」
>>>初日から時間オーバー<<< pic.twitter.com/kt8ipY6ZKE
作るのにかかった時間は「1時間と15分」。初日から思いっきりオーバーしてます。
コードは以下に記載。制限時間を超えてる上にめっさ汚ぇ…
PVector Pos;//球の位置 PVector Vec;//球の速度 int size;//球のサイズ float Ang;//球を発射する角度 PVector Wall;//壁の穴の始点位置と長さ PVector Target;//的の位置 String Phase; int Time;//経過時間 int Count;//反射回数 void setup() { size(800, 450); reset_field(); textSize(20); } void draw() { background(0); stroke(255, 0, 0); if (Phase.equals("clear") || Phase.equals("failure")) { textAlign(CENTER, CENTER); textSize(50); if (Phase.equals("clear")) text("CLEAR! (SCORE : " + Time * (10 - Count) + " )", width / 2, height / 2 - 50); else text("FAILURE...", width / 2, height / 2 - 50); textSize(20); text("(RESTART)[SHIFT], (RESET)[ALT]", width / 2, height / 2 + 50); return; } textSize(20); if (Phase.equals("move")) { if (Pos.x <= 0 || Pos.x >= width) reflection(false); if (Pos.y <= 0 || Pos.y >= height) reflection(true); if (Pos.x <= 400 && Pos.x + Vec.x >= 400 && Pos.y >= Wall.x && Pos.y <= Wall.x + Wall.y) reflection(false); if (Pos.x >= 400 && Pos.x + Vec.x <= 400 && Pos.y >= Wall.x && Pos.y <= Wall.x + Wall.y) reflection(false); if (Pos.dist(Target) <= (size + 50) / 2) Phase = "clear"; Pos.add(Vec); } if (Time < 0 || Count > 9) Phase = "failure"; Time--; if (Phase.equals("set")) line(Pos.x, Pos.y, 100 + cos(Ang) * 300, 225 + sin(Ang) * 300); stroke(255); fill(255); line(400, Wall.x, 400, Wall.x + Wall.y); ellipse(Target.x, Target.y, 50, 50); ellipse(Pos.x, Pos.y, size, size);//球の描画 textAlign(LEFT, CENTER); text("TIME:" + Time / 60, 10, 15); text("COUNT:" + Count, 10, 40); text("(MOVE)[UP & DOWN]", 10, 65); text("(GO)[ENTER]", 10, 90); text("(RESTART)[SHIFT]", 10, 115); text("(RESET)[ALT]", 10, 140); } void reflection(boolean isHeight) { if (isHeight) Vec.y = -Vec.y; else Vec.x = -Vec.x; Count++; } void restart() { Pos = new PVector(100, 225); Vec = new PVector(0, 0); Ang = 0; Phase = "set"; Time = 1800; Count = 0; } void reset_field() { restart(); size = 8; Wall = new PVector(random(450 - 300), 300); Target = new PVector(725, random(25, 425)); } void keyPressed() { switch(keyCode) { case UP: Ang -= PI / 180; break; case DOWN: Ang += PI / 180; break; case ENTER: if (!Phase.equals("set")) break; Phase = "move"; Vec = new PVector(cos(Ang) * 10, sin(Ang) * 10); break; case SHIFT: restart(); break; case ALT: reset_field(); break; } }