Shelly Dancer is a strange creature dancing with a funny mode. Everytime arms finish swinging a roung(out and back), the two arms will swap their front and back positions. That is, if right now the left arm is in front of the body while the right arm is behind , when they both finish an out-and-back round the right arm will be in front of the body instead.
Demo/Visual Documentation:
Development and Technical Implementation
The most difficult part for me is the arms waving. To be specific, the problem is how to make two arms change their front and back position everytime they finish an out-and-back motion.
To deal with it, I defined this.waveCounterRight=true / this.waveCounterLeft=false to operate two arms seperately and this.waveChangeRight / this.waveChangeLeft to make sure arms won’t be flashing at the end point of streching (because I use this.deg+=this.speed/this.speed=random(3,8) , it is impossible to say wave=sin(ran) (where ran=radians(this.deg)) can reach -1 or 1 in every round
//background //right arm if (this.waveCounterRight==false){ push(); stroke(r+30,g+40,b+40) strokeWeight(8) translate(12,-19) rotate(wave*1.4-0.3) line(0,0,0,58) pop(); }//left arm if(this.waveCounterLeft==false){ push(); stroke(r+60,g+50,b+60) strokeWeight(8) translate(-12,-19) rotate(wave*1.4+0.3) line(0,0,0,58) pop(); }
…//other elements
//foreground //right arm if (this.waveCounterRight==true){ push(); stroke(r+50,g+50,b+50) strokeWeight(8) translate(12,-19) rotate(wave*1.4-0.3) line(0,0,0,58) pop(); }//left arm if(this.waveCounterLeft==true){ push(); stroke(r+50,g+50,b+50) strokeWeight(8) translate(-12,-19) rotate(wave*1.4+0.3) line(0,0,0,58) pop(); }//right if (wave<=-0.95 && this.preChangeRight==false) { this.waveCounterRight=!this.waveCounterRight } if (wave<=-0.95 && this.preChangeRight==false){ this.preChangeRight=true }else if(wave>-0.95){ this.preChangeRight=false }//left if (wave>=0.95 && this.preChangeLeft==false) { this.waveCounterLeft=!this.waveCounterLeft } if (wave>=0.95 && this.preChangeLeft==false){ this.preChangeLeft=true }else if(wave<0.95){ this.preChangeLeft=false }
Reflection/Lessons Learned
What is the benefit of your class not relying on any code outside of its own definition?
It is obvious that I can call the class directly and repeatedly without checking relevant codes or worrying about errors.
If I set some random parameters or other alterable variables, I can easily and repeatedly graw the creature with slight differences.
What make it challenging to write code that has to harmonize with the code other people have written?
The code written by other people directly use some default parameters like strokeWeight(1) without typing down it. So I have to either put a strokeWeight(1) at the end of my own code or add a pair of push() and pop() clamping my code.
Describe the terms modularity and reusability using the example of your dancer class.
reusability means I can simply call my class of dancer repeatedly in draw function with a single sentence of code but no changes.
As for the modularity here, it has to be considered with the relationship between draw function(ot the whole code) and the class of dancer. It means the dancer can be written in the draw function, but it will make the code complex and easy to cause errors. So the class of dancer here make the dancer a module and simplifies the code dancer in draw function, which make the code reusable, clear, and readable.