Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.62 KB | None | 0 0
  1. #include "ofApp.h"
  2.  
  3. struct BallProperties {
  4.     float xpos;
  5.     float ypos;
  6.     float radius;
  7.     int facets;
  8.     ofColor c1;
  9.     ofColor c2;
  10.     float yrot;
  11.     float zrot;
  12. };
  13.  
  14. //--------------------------------------------------------------
  15. void ofApp::setup(){
  16.     width = ofGetWidth();
  17.     height = ofGetHeight();
  18.  
  19.     // Grid
  20.     padding = height*5.0/100.0;
  21.     numVLines = 16;
  22.     numHLines = 13;
  23.     gridSizeX = width-2*padding;
  24.     gridSizeY = height-2*padding;
  25.    
  26.     // Ball Physics
  27.     x = width/2;
  28.     y = height/3;
  29.     ySpeed = 0.0;
  30.     yAcceleration = 0.25;
  31.     xSpeed = 3.4;
  32.    
  33.     // Ball look
  34.     facets = 7;
  35.     rotation = glm::radians(15.0);
  36.     //color1 = ofColor(255,255,255);
  37.     //color2 = ofColor(255,0,0);
  38.     //color1.r = 255; color1.g = 255; color1.b=255;
  39.     //color2.r = 255; color2.g = 0; color2.b=0;
  40.     rotSpeed = PI/150;
  41.     radius = 100;
  42. }
  43.  
  44. //--------------------------------------------------------------
  45. void ofApp::update(){
  46.     // Update the balls x position
  47.     x += xSpeed;
  48.     if (x < radius){
  49.         xSpeed = -xSpeed;
  50.     }
  51.     if (x > width - radius){
  52.         xSpeed = -xSpeed;
  53.     }
  54.  
  55.     // Update y position by using acceleration (physics)
  56.     y += ySpeed;
  57.     if (y > height - radius ){
  58.         ySpeed = - ySpeed;
  59.     } else {
  60.         ySpeed += yAcceleration;
  61.     }
  62.  
  63. }
  64.  
  65. //--------------------------------------------------------------
  66. void ofApp::draw(){
  67.     // Clear the screen with a color
  68.     ofClear(50, 50, 50);
  69.    
  70.     // Draw the grid
  71.     ofSetColor(155, 29, 227);
  72.     ofSetLineWidth(3);
  73.  
  74.     float xpos = padding;
  75.     float ypos = padding;
  76.  
  77.     float xStep = gridSizeX/(numVLines-1);
  78.     float yStep = gridSizeY/(numHLines-1);
  79.  
  80.     for (int vlines = 0; vlines < numVLines; vlines++) {
  81.         ofDrawLine(xpos, padding, xpos, padding+gridSizeY);
  82.         xpos += xStep;
  83.     }
  84.  
  85.     for (int hlines = 0; hlines < numHLines; hlines++) {
  86.         ofDrawLine(padding, ypos, padding+gridSizeX, ypos);
  87.         ypos += yStep;
  88.     }
  89.    
  90.     // Draw the balls shadow
  91.     ofSetColor(0, 0, 0, 110);
  92.     ofDrawCircle(x+20, y+20, radius);
  93.  
  94.     // Finally draw our ball
  95.     drawAmigaBall(x,y, radius, facets, color1, color2, x*rotSpeed, rotation);
  96.  
  97. }
  98.  
  99. //--------------------------------------------------------------
  100. void ofApp::keyPressed(int key){
  101.  
  102. }
  103.  
  104. //--------------------------------------------------------------
  105. void ofApp::keyReleased(int key){
  106.  
  107. }
  108.  
  109. //--------------------------------------------------------------
  110. void ofApp::mouseMoved(int x, int y ){
  111.  
  112. }
  113.  
  114. //--------------------------------------------------------------
  115. void ofApp::mouseDragged(int x, int y, int button){
  116.  
  117. }
  118.  
  119. //--------------------------------------------------------------
  120. void ofApp::mousePressed(int x, int y, int button){
  121.  
  122. }
  123.  
  124. //--------------------------------------------------------------
  125. void ofApp::mouseReleased(int x, int y, int button){
  126.  
  127. }
  128.  
  129. //--------------------------------------------------------------
  130. void ofApp::mouseEntered(int x, int y){
  131.  
  132. }
  133.  
  134. //--------------------------------------------------------------
  135. void ofApp::mouseExited(int x, int y){
  136.  
  137. }
  138.  
  139. //--------------------------------------------------------------
  140. void ofApp::windowResized(int w, int h){
  141.     width = w;
  142.     height = h;
  143.    
  144.     padding = height*5.0/100.0;
  145.     gridSizeX = width-2*padding;
  146.     gridSizeY = height-2*padding;
  147. }
  148.  
  149. //--------------------------------------------------------------
  150. void ofApp::gotMessage(ofMessage msg){
  151.  
  152. }
  153.  
  154. //--------------------------------------------------------------
  155. void ofApp::dragEvent(ofDragInfo dragInfo){
  156.  
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement