Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ofApp.h"
- struct BallProperties {
- float xpos;
- float ypos;
- float radius;
- int facets;
- ofColor c1;
- ofColor c2;
- float yrot;
- float zrot;
- };
- //--------------------------------------------------------------
- void ofApp::setup(){
- width = ofGetWidth();
- height = ofGetHeight();
- // Grid
- padding = height*5.0/100.0;
- numVLines = 16;
- numHLines = 13;
- gridSizeX = width-2*padding;
- gridSizeY = height-2*padding;
- // Ball Physics
- x = width/2;
- y = height/3;
- ySpeed = 0.0;
- yAcceleration = 0.25;
- xSpeed = 3.4;
- // Ball look
- facets = 7;
- rotation = glm::radians(15.0);
- //color1 = ofColor(255,255,255);
- //color2 = ofColor(255,0,0);
- //color1.r = 255; color1.g = 255; color1.b=255;
- //color2.r = 255; color2.g = 0; color2.b=0;
- rotSpeed = PI/150;
- radius = 100;
- }
- //--------------------------------------------------------------
- void ofApp::update(){
- // Update the balls x position
- x += xSpeed;
- if (x < radius){
- xSpeed = -xSpeed;
- }
- if (x > width - radius){
- xSpeed = -xSpeed;
- }
- // Update y position by using acceleration (physics)
- y += ySpeed;
- if (y > height - radius ){
- ySpeed = - ySpeed;
- } else {
- ySpeed += yAcceleration;
- }
- }
- //--------------------------------------------------------------
- void ofApp::draw(){
- // Clear the screen with a color
- ofClear(50, 50, 50);
- // Draw the grid
- ofSetColor(155, 29, 227);
- ofSetLineWidth(3);
- float xpos = padding;
- float ypos = padding;
- float xStep = gridSizeX/(numVLines-1);
- float yStep = gridSizeY/(numHLines-1);
- for (int vlines = 0; vlines < numVLines; vlines++) {
- ofDrawLine(xpos, padding, xpos, padding+gridSizeY);
- xpos += xStep;
- }
- for (int hlines = 0; hlines < numHLines; hlines++) {
- ofDrawLine(padding, ypos, padding+gridSizeX, ypos);
- ypos += yStep;
- }
- // Draw the balls shadow
- ofSetColor(0, 0, 0, 110);
- ofDrawCircle(x+20, y+20, radius);
- // Finally draw our ball
- drawAmigaBall(x,y, radius, facets, color1, color2, x*rotSpeed, rotation);
- }
- //--------------------------------------------------------------
- void ofApp::keyPressed(int key){
- }
- //--------------------------------------------------------------
- void ofApp::keyReleased(int key){
- }
- //--------------------------------------------------------------
- void ofApp::mouseMoved(int x, int y ){
- }
- //--------------------------------------------------------------
- void ofApp::mouseDragged(int x, int y, int button){
- }
- //--------------------------------------------------------------
- void ofApp::mousePressed(int x, int y, int button){
- }
- //--------------------------------------------------------------
- void ofApp::mouseReleased(int x, int y, int button){
- }
- //--------------------------------------------------------------
- void ofApp::mouseEntered(int x, int y){
- }
- //--------------------------------------------------------------
- void ofApp::mouseExited(int x, int y){
- }
- //--------------------------------------------------------------
- void ofApp::windowResized(int w, int h){
- width = w;
- height = h;
- padding = height*5.0/100.0;
- gridSizeX = width-2*padding;
- gridSizeY = height-2*padding;
- }
- //--------------------------------------------------------------
- void ofApp::gotMessage(ofMessage msg){
- }
- //--------------------------------------------------------------
- void ofApp::dragEvent(ofDragInfo dragInfo){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement