ICM Week 3: Objects and Control

Prologue: The Sensei and the Student

This week we were assigned to create a program with “rule-based animation, motion, and interaction.” Though I, admittedly, spent most of my time solving another problem that was bugging me too much to let go: how to create classes.

Last week I created a sweet little satellite ellipse that orbited a center point in a circle. Cool. This week I thought that I’d like to create some GUI elements to control different characteristics of that satellite.

At went to Shiffman to talk about using vectors to create motion, but I quickly realized that I wasn’t really asking him about code, I was asking him about basic math. Info which, I could have sat in on a seventh grade class to get. Sorry, Shiffman. 

Anyway he casually mentioned using classes but quickly dismissed on account of it coming up in class in a week or two. But Shiffman and I, we speak a different language. Another code if you will. It consists of fleeting cues, subtle hints, and the occasional wink*. While he was talking about basic vectors and acceleration, he was actually issuing me a challenge. As any good sensei would**.

*Not at all true.  Strictly for dramatic effect.

**Dan Shiffman is not my sensei. He has not agreed to be my sensei, nor have I asked him to be***.

***Although if he wants to be my sensei, I am in the market…

So I spent a bunch of time figuring out how to create a Satellite class.

Chapter I: Actually Doing the Assignment

One of the characteristics of the satellite that I thought would be cool to control is the size. It’s obvious and you’d see the effect immediately. I wanted to do this by programming a horizontal slider as the control element. The slider would move left to right and as it was dragged to the right the size of the slider and the satellite would grow correspondently.

The slider was fairly straight forward to program. I created the slider, then just make sure I got the whole class-thing, I created a Slider class.

Boom. Slider class. Satellite class. Great. Except they weren’t talking. The slider would slide and the satellite would be a satellite, but there was not communication between the two. I knew there must be a simple solution.  Getting classes to talk to each other seems like it should be a basic function. And, good news: it is. I just couldn’t figure it out on my own.

So I talked to a resident: the venerable Ryan Bartley****. He showed me the basics of setters and getters in about 10 minutes. He’s super.

Now the slider works and it’s size corresponds exactly to the size of the satellite.

****Also not my sensei. In any official, or really, unofficial, capacity. Just a smart dude with office hours.

Chapter II: The Sketch

 

 

One thought on “ICM Week 3: Objects and Control”

Comments are closed.