I officially earned an important geek merit badge just now: I wrote my first complex class from scratch. Sure, I’ve hacked around code before, and tinkered with excellent suggestions from ITP’s awesome residents & professors — but now, I identified the need for an object, and wrote the damm thing myself (starting, of course, with Amelia’s exhaustive geometry-drawing functions).
Something about the whole “from scratch” thing makes me think of good ‘ol Sagan. Source code after the break.
#include “testApp.h”
//————————————————————–
void testApp::setup(){
ofBackground(255,255,255);
//set booleans initially equal to false
directContact=false;
sleepPose = 0;
}
//————————————————————–
void testApp::update(){
}
//————————————————————–
void testApp::draw(){
for (int i = 0; i< sleepSet.size(); i++){
sleepSet[i]->drawShape();
}
}
//————————————————————–
void testApp::keyPressed(int key){
if (key == ‘l’){
printf(“how many sleepSets: %d\n”, int(sleepSet.size()));
printf(“xCounter: %d \n”, xCounter);
printf(“yCounter: %d \n”, yCounter);
printf(“numberOfSquaresElapsed: %d \n”, numberOfSquaresElapsed);
printf(“sleepPose: %d \n”, sleepPose);
printf(“numberOfSquaresElapsed: %d \n”, numberOfSquaresElapsed);
if (xCounter > 28){
xCounter=1;
yCounter=yCounter+2;
}else{
xCounter++;
}
//make container for each sleepState object (sleepSet)
sleepState* OBJ = new sleepState(numberOfSquaresElapsed);
sleepSet.push_back( OBJ );
sleepSet[numberOfSquaresElapsed]->storeSleepData(xCounter, yCounter, numberOfSquaresElapsed, directContact, sleepPose);
numberOfSquaresElapsed+=1;
}
//DEFINE PROXIMITY
if (key == ‘c’) {
directContact = !directContact;
}
//DEFINE POSITION
if (key == ’0′){
sleepPose = 0;
}
if (key == ’1′){
sleepPose = 1;
}
if (key == ’2′){
sleepPose = 2;
}
if (key == ’3′){
sleepPose = 3;
}
if (key == ’4′){
sleepPose = 4;
}
if (key == ’5′){
sleepPose = 5;
}
if (key == ’6′){
sleepPose = 6;
}
if (key == ’7′){
sleepPose = 7;
}
if (key == ’8′){
sleepPose = 8;
}
}
//
// sleepState.h
// REMQuilt.3.4 2
//
// Created by Justin Lange on 3/4/12.
// Copyright (c) 2012 Magic Hat Films. All rights reserved.
//
#ifndef REMQuilt_3_4_2_sleepState_h
#define REMQuilt_3_4_2_sleepState_h
#include “ofMain.h”
class sleepState
{
public:
sleepState( int _ID );
void drawShape();
void storeSleepData(int xCounter, int yCounter, int numberOfSquaresElapsed, bool directContact, int sleepPose);
int ID;
//sleep sensing variables
bool directContact;
int sleepPose;
//coordinates for entire quilt square
int xPosition;
int yPosition;
int screenWidth;
int screenHeight;
int quiltSquareWidth;
int quiltSquareHeight;
//coordinates for 2-minute quilt square geometry
int topCenterX;
int topCenterY;
int topRightX;
int topRightY;
int centerLeftX;
int centerLeftY;
int centerX;
int centerY;
int centerRightX;
int centerRightY;
int bottomLeftX;
int bottomLeftY;
int bottomCenterX;
int bottomCenterY;
int bottomRightX;
int bottomRightY;
int xCounter;
int yCounter;
int numberOfQuiltSquaresToDraw;
int numberOfSquaresElapsed;
int currentXCounter;
int currentYCounter;
};
#endif
//
// sleepState.cpp
// REMQuilt.3.4 2
//
// Created by Justin Lange on 3/4/12.
// Copyright (c) 2012 Magic Hat Films. All rights reserved.
//
#include
#include “sleepState.h”
//#define NUM 10
sleepState::sleepState( int _ID )
{
xCounter=1;
yCounter=1;
//set booleans initially equal to false
directContact=false;
sleepPose = 0;
//define coordinates for entire quilt square
xPosition=1;
yPosition=1;
screenWidth=1423;
screenHeight=1024;
// quiltSquareWidth= screenWidth/30;
// quiltSquareHeight= screenHeight/24;
quiltSquareWidth= 30;
quiltSquareHeight= 24;
//define coordinates for 2-minute quilt square geometry
topCenterX= 1;
topCenterY= 1;
topRightX=1;
topRightY=1;
centerLeftX=1;
centerLeftY=1;
centerX=1;
centerY=1;
centerRightX=1;
centerRightY=1;
bottomLeftX=1;
bottomLeftY=1;
bottomCenterX=1;
bottomCenterY=1;
bottomRightX=1;
bottomRightY=12;
numberOfQuiltSquaresToDraw=0;
}
void sleepState::storeSleepData(int xCounter, int yCounter, int numberOfSquaresElapsed, bool directContact, int sleepPose){
xPosition=(xCounter * quiltSquareWidth);
yPosition=(yCounter * quiltSquareWidth);
topCenterX= (xPosition + (quiltSquareWidth/2));
topCenterY= yPosition;
topRightX= (xPosition + quiltSquareWidth);
topRightY= ((xPosition + quiltSquareWidth),yPosition);
centerLeftX= xPosition;
centerLeftY= (yPosition + (quiltSquareHeight/2));
centerX= (xPosition + (quiltSquareWidth/2));
centerY= (yPosition + (quiltSquareHeight/2));
centerRightX= (xPosition+quiltSquareWidth);
centerRightY= (quiltSquareHeight/2);
bottomLeftX= (xPosition + quiltSquareHeight);
bottomLeftY= yPosition;
bottomCenterX= (xPosition+(quiltSquareWidth/2));
bottomCenterY= quiltSquareHeight;
bottomRightX= (xPosition+quiltSquareWidth);
bottomRightY= quiltSquareWidth;
sleepPose = sleepPose;
directContact = directContact;
}
void sleepState::drawShape()
{
//SET COLOR (based on proximity)
if (directContact==1) {
ofSetHexColor(0xA84D2C); // contact bright orange
}else{
ofSetHexColor(0x2E8270); // no contact blue
}
/*positions reference
0 no data
1 restless on back
2 restlessOnFront
3 restless looking right
4 restless looking left
5 still On Front
6 stillOnBack
7 stillLookingRight
8 stillLookingLeft
*/
//DRAW SHAPES
if (sleepPose==0){
//DRAW CIRCLE IN THE MIDDLE
ofFill();
ofCircle(centerX,centerY,(quiltSquareWidth/2));
}
if (sleepPose==1) {
ofFill();
//DRAW TWO TOP-UP TRIANGLES
ofTriangle(topCenterX, topCenterY, centerLeftX, centerLeftY, centerRightX, centerRightY); //first triangle
ofTriangle(centerX,centerY, bottomLeftX, bottomLeftY, bottomRightX, bottomRightY); //second triangle
}
if (sleepPose==2) {
ofFill();
//DRAW TWO TOP-DOWN TRIANGLES
ofTriangle(xPosition, yPosition, topRightX, topRightY,centerX,centerY); //first triangle
ofTriangle(centerLeftX, centerLeftY, centerRightX, centerRightY, bottomCenterX, bottomCenterY); //second triangle
}
if (sleepPose==3) {
ofFill();
//DRAW TWO RIGHT-FACING TRIANGLES
ofTriangle(centerRightX, centerRightY, topCenterX, topCenterY, bottomCenterX, bottomCenterY); //first triangle
ofTriangle(centerX,centerY, xPosition, yPosition, bottomLeftX, bottomLeftY); //second triangle
}
if (sleepPose==4) {
ofFill();
//DRAW TWO TOP-DOWN TRIANGLES
ofTriangle(centerRightX, centerRightY, topCenterX, topCenterY, bottomCenterX, bottomCenterY); //first triangle
ofTriangle(centerX,centerY, xPosition, yPosition, bottomLeftX, bottomLeftY); //second triangle
}
if (sleepPose==5) {
//DRAW ONE TOP-DOWN TRIANGLE
ofFill();
ofTriangle(xPosition, yPosition, topRightX, topRightY, bottomCenterX, bottomCenterY);
}
if (sleepPose==6) {
//DRAW ONE TOP-UP TRIANGLE
ofFill();
ofTriangle(bottomLeftX, bottomLeftY, topCenterX, topCenterY, bottomRightX, bottomRightY);
}
if (sleepPose==7) {
//DRAW ONE RIGHT-FACING TRIANGLE
ofFill();
ofTriangle(centerRightX, centerRightY, xPosition, yPosition, bottomLeftX, bottomLeftY);
}
if (sleepPose==8) {
//DRAW ONE LEFT-FACING TRIANGLE
ofFill();
ofTriangle(centerLeftX, centerLeftY, topRightX, topRightY, bottomRightX, bottomRightY);
}
}
//b[NUM];


















Recent Comments