Processingで回転する物体とそうでない物体を共存
前回の続きです。
風車のように回転する花に茎をつけて、中心を黄色くしてみました。
かなり花っぽくなりました。
gifだとこんな感じ。
*実際はもっと滑らかに動いてて、いい感じなんです!
ソースコードの変更箇所は以下。
class Flowers { float sizeX; float sizeY; float posX; float posY; float centerX; float centerY; float speed; int startCnt; color colorFlower; float rotateCenter; float mikiX; float mikiY; float mikiSizeX; float mikiSizeY; float mikiCenterX; float mikiCenterY; color mikiColor; float circleX; float circleY; float circleSizeX; float circleSizeY; float circleCenterX; float circleCenterY; color circleColor; Flowers() { posX = random(width); posY = random(height); sizeX = random(0)+60; sizeY = random(0)+60; centerX = posX + sizeX/2; centerY = posY + sizeY/2; speed = random(15)+ 10; colorFlower = color(random(150)+100, random(150)+100, random(150)+100, 220); startCnt = int(random(250)); //rotateCenter = random(200) + 100; rotateCenter =0; //茎のパラメーター。名称は幹になってます・・・ mikiCenterX = centerX; mikiSizeX = 10; mikiSizeY = 60; mikiX = mikiCenterX - mikiSizeX/2; mikiY = centerY; mikiColor = color(0,200,100,100); //中心の黄色の部分のパラメーター。名称不明なのでcircle、でも四角形を描画・・・ circleCenterX = centerX; circleCenterY = centerY; circleSizeX = 20; circleSizeY = 20; circleX = centerX - circleSizeX/2; circleY = centerY - circleSizeY/2; circleColor = color(200,200,0,255); } void rotateRect(int cnt) { if (cnt > startCnt) { fill(colorFlower); pushMatrix(); //茎は回転させず、花びらの後ろに描画するため、座標変換前に茎を描画。 fill(mikiColor); rect(mikiX,mikiY,mikiSizeX,mikiSizeY); translate(centerX, centerY); rotate((cnt-startCnt)*radians(speed)); translate(-centerX - rotateCenter, -centerY - rotateCenter); fill(colorFlower); rect(posX, posY, sizeX, sizeY); //rect(random(width), random(height), sizeX, sizeY); popMatrix(); //中心の黄色いやつは回転させず、回転体(花びら)の前面に描画するため、 //popMatrix後に記述。 fill(circleColor); rect(circleX, circleY, circleSizeX, circleSizeY); } } }