現在、Processingのexampleで紹介されていたSpringというコードを改良して、様々な図形の色がそれぞれ、カーソルが触れた時に色を変えるというプログラムを書いています。
参考コードのSpring:https://processing.org/examples/spring.html
現状では以下の様になっており、四角形の物体に触れた時のみ、全ての図形の色が変わる様になっています。それぞれの物体を制御するにはどうしたら良いでしょうか。
// Spring drawing constants for top bar int springHeight = 32; // Height int left; // Left position int right; // Right position boolean over = false; // If mouse over boolean move = false; // If mouse down and over float R = 150; // Rest position // Spring simulation variables float ps = R; // Position void setup() { size(640, 360); rectMode(CORNERS); noStroke(); left = width/2 - 100; right = width/2 + 100; } void draw() { background(102); updateSpring(); drawSpring(); } void drawSpring() { // Set color and draw top bar if(over || move) { fill(#CE2828); } else { fill(204); } rect(left, ps, right, ps + springHeight); ellipse(30,30, 50,50); ellipse(100, 50, 80, 80); } void updateSpring() { // Test if mouse is over the top bar if(mouseX > left && mouseX < right && mouseY > ps && mouseY < ps + springHeight) { over = true; } else { over = false; } }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/07/02 04:56