Search Results

Search found 902 results on 37 pages for 'circle'.

Page 5/37 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Python: writing a program to compute the area of a circle and square

    - by user1672504
    I have a question with an assignment. I'm not sure how to write this program and I really need help! Could someone help me with this? This is the assignment: Write a program that asks the user to enter two values: an integer choice and a real number x. If choice is 1, compute and display the area of a circle of radius x. If choice is 2, compute and display the are of a square with sides of length x. If choice is neither 1, nor 2, will display the text Invalid choice. Sample run: Enter choice: 2 Enter x: 8 The area is: 64.0 Sample run: Enter choice: 1 Enter x: 8 The area is: 201.06176 My attempt: choice = input ('Enter Choice:') choice_1 = int (choice) if (choice_1==1): radius = (int) print('Enter x:',radius) pi = 3.14159 area = ( radius ** 2 ) * pi print ( 'The Area is=' , area )

    Read the article

  • Find most right and left point of a horizontal circle in 3d Vector environment

    - by Olivier de Jonge
    I'm drawing a 3D pie chart that is rendered with in 3D vectors, projected to 2D vectors and then drawn on a Graphics object. I want to calculate the most left and right point of the circle The method to create a vector, draw and project to a 2d vector are below. Anyone knows the answer? public class Vector3d { public var x:Number; public var y:Number; public var z:Number; //the angle that the 3D is viewed in tele or wide angle. public static var viewDist:Number = 700; function Vector3d(x:Number, y:Number, z:Number){ this.x = x; this.y = y; this.z = z; } public function project2DNew():Vector { var p:Number = getPerspective(); return new Vector(p * x, p * y); } public function getPerspective():Number{ return viewDist / (this.z + viewDist); } }

    Read the article

  • Collision detection of huge number of circles

    - by Tomek Tarczynski
    What is the best way to check collision of huge number of circles? It's very easy to detect collision between two circles, but if we check every combination then it is O(n^2) which definitely not an optimal solution. We can assume that circle object has following properties: -Coordinates -Radius -Velocity -Direction Velocity is constant, but direction can change. I've come up with two solutions, but maybe there are some better solutions. Solution 1 Divide whole space into overlapping squares and check for collision only with circles that are in the same square. Squares needs to overlap so there won't be a problem when circle moves from one square to another. Solution 2 At the beginning distances between every pair of circles need to be calculated. If the distance is small then these pair is stored in some list, and we need to check for collision in every update. If the distance is big then we store after which update there can be a collision (it can be calculated because we know the distance and velocitites). It needs to be stored in some kind of priority queue. After previously calculated number of updates distance needs to be checked again and then we do the same procedure - put it on the list or again in the priority queue.

    Read the article

  • How do I know when to increase or decrease angle to get a specific angle?

    - by Thomas
    Hi. I am programming a game and I have come to a very hard spot. Basically I have a circle and I have 2 angles on this circle. Angle 1 (A) is a point I want angle 2 (B) to go to. During my game every frame I need to check weither or not to increase or decrease my angle value by a certain amount (speed) to eventually reach the first angle. My question is how do I do this? I tried doing this but I don't seem to be doing it right. bool increase = false; float B = [self radiansToDegrees:tankAngle]; float A = [self radiansToDegrees:tankDestinationAngle]; float newAngle = B; if(B < A) { float C = B - (360 - A); float D = A - B; if(C < D) increase = false; else increase = true; } else if(B A) { float C = B - A; float D = A - (360 - B); if(C < D) increase = false; else increase = true; } if(increase) { newAngle += 1.0; } else { newAngle -= 1.0; } if(newAngle 360.0) { newAngle = 0 + (newAngle - 360.0); } else if(newAngle < 0.0) { newAngle = 360 + newAngle; } if(newAngle == 0) newAngle = 360; newAngle = [self degreesToRadians:newAngle]; [self setTanksProperPositionRotation:newAngle]; The basic effect I am trying to achieve is when the user makes a new point, which would be angle 1, angle 2 would move towards angle 1 choosing the fastest direction. I think I have spent around 4 hours trying to figure this out.

    Read the article

  • how to rotate the Circle in DrawRect?

    - by senthilmuthu
    HI, i want to draw a circle in DrawRect through context like pie chart(took from tutorial) thorugh UITouch? i have given the code as follows,how can i rotate ? any help please? define PI 3.14159265358979323846 define snapshot_start 360 define snapshot_finish 360 static inline float radians(double degrees) { return degrees * PI / 180; } - (void)drawRect:(CGRect)rect { // Drawing code CGRect parentViewBounds = self.bounds; CGFloat x = CGRectGetWidth(parentViewBounds)/2; CGFloat y = CGRectGetHeight(parentViewBounds)*0.55; // Get the graphics context and clear it CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextClearRect(ctx, rect); // define stroke color CGContextSetRGBStrokeColor(ctx, 1, 1, 1, 1.0); // define line width CGContextSetLineWidth(ctx, 4.0); // need some values to draw pie charts double snapshotCapacity =20; double rawCapacity = 100; double systemCapacity = 1; int offset = 5; double pie1_start = 315.0; double pie1_finish = snapshotCapacity *360.0/rawCapacity; double system_finish = systemCapacity*360.0/rawCapacity; CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor greenColor] CGColor])); CGContextMoveToPoint(ctx, x+2*offset, y); CGContextAddArc(ctx, x+2*offset, y, 100, radians(snapshot_start), radians(snapshot_start+snapshot_finish), 0); CGContextClosePath(ctx); CGContextFillPath(ctx); // system capacity CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor colorWithRed:15 green:165/255 blue:0 alpha:1 ] CGColor])); CGContextMoveToPoint(ctx, x+offset,y); CGContextAddArc(ctx, x+offset, y, 100, radians(snapshot_start+snapshot_finish+offset), radians(snapshot_start+snapshot_finish+system_finish), 0); CGContextClosePath(ctx); CGContextFillPath(ctx); /* data capacity */ CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor colorWithRed:99/255 green:184/255 blue:255/255 alpha:1 ] CGColor])); CGContextMoveToPoint(ctx, x, y); CGContextAddArc(ctx, x, y, 100, radians(snapshot_start+snapshot_finish+system_finish+offset), radians(snapshot_start), 0); CGContextClosePath(ctx); CGContextFillPath(ctx); }

    Read the article

  • rotating a circle in UIView?

    - by senthilmuthu
    HI, i want to draw a circle in DrawRect through context like pie chart(took from tutorial) thorugh UITouch? i have given the code as follows,how can i rotate ? any help please? define PI 3.14159265358979323846 define snapshot_start 360 define snapshot_finish 360 static inline float radians(double degrees) { return degrees * PI / 180; } - (void)drawRect:(CGRect)rect { // Drawing code CGRect parentViewBounds = self.bounds; CGFloat x = CGRectGetWidth(parentViewBounds)/2; CGFloat y = CGRectGetHeight(parentViewBounds)*0.55; // Get the graphics context and clear it CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextClearRect(ctx, rect); // define stroke color CGContextSetRGBStrokeColor(ctx, 1, 1, 1, 1.0); // define line width CGContextSetLineWidth(ctx, 4.0); // need some values to draw pie charts double snapshotCapacity =20; double rawCapacity = 100; double systemCapacity = 1; int offset = 5; double pie1_start = 315.0; double pie1_finish = snapshotCapacity *360.0/rawCapacity; double system_finish = systemCapacity*360.0/rawCapacity; CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor greenColor] CGColor])); CGContextMoveToPoint(ctx, x+2*offset, y); CGContextAddArc(ctx, x+2*offset, y, 100, radians(snapshot_start), radians(snapshot_start+snapshot_finish), 0); CGContextClosePath(ctx); CGContextFillPath(ctx); // system capacity CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor colorWithRed:15 green:165/255 blue:0 alpha:1 ] CGColor])); CGContextMoveToPoint(ctx, x+offset,y); CGContextAddArc(ctx, x+offset, y, 100, radians(snapshot_start+snapshot_finish+offset), radians(snapshot_start+snapshot_finish+system_finish), 0); CGContextClosePath(ctx); CGContextFillPath(ctx); /* data capacity */ CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor colorWithRed:99/255 green:184/255 blue:255/255 alpha:1 ] CGColor])); CGContextMoveToPoint(ctx, x, y); CGContextAddArc(ctx, x, y, 100, radians(snapshot_start+snapshot_finish+system_finish+offset), radians(snapshot_start), 0); CGContextClosePath(ctx); CGContextFillPath(ctx); }

    Read the article

  • moving image to bounce or rotate in a circle

    - by BlueMonster
    I found this small application that i've been playing around with for the past little while. I was wondering, if i wanted to simply rotate the image in a circle? or make the entire image just bounce up and down, how would i modify this program to do so? Everything i've tried will just stretch the image - even if i do get it to move to the left or to the right. Any ideas on what i can do? Code is below public partial class Form1 : Form { private int width = 15; private int height = 15; Image pic = Image.FromFile("402.png"); private Button abort = new Button(); Thread t; public Form1() { abort.Text = "Abort"; abort.Location = new Point(190, 230); abort.Click += new EventHandler(Abort_Click); Controls.Add(abort); SetStyle(ControlStyles.DoubleBuffer| ControlStyles.AllPaintingInWmPaint| ControlStyles.UserPaint, true); t = new Thread(new ThreadStart(Run)); t.Start(); } protected void Abort_Click(object sender, EventArgs e) { t.Abort(); } protected override void OnPaint( PaintEventArgs e ) { Graphics g = e.Graphics; g.DrawImage(pic, 10, 10, width, height); base.OnPaint(e); } public void Run() { while (true) { for(int i = 0; i < 200; i++) { width += 5; Invalidate(); Thread.Sleep(30); } } } }

    Read the article

  • How to get location of sprite placed on rotating circle in cocos2d android?

    - by Real_steel4819
    I am developing a game using cocos2d and i got stuck here when finding location of sprite placed on rotating circle on background, so that when i hit at certain position on circle its not getting hit at wanted position,but its going away from it and placing target there.I tried printing the position of hit on spriteMoveFinished() and ccTouchesEnded(). Its giving initial position and not rotated position. CGPoint location = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(event.getX(), event.getY())); This is what i am using to get location.

    Read the article

  • If I project a sphere in 3D will it be a circle?

    - by yuumei
    Assuming I have infinite vertices to represent the sphere, if I project the sphere from any position/scale in 3D to 2D, will it be a circle? I know it will not be a circle on the screen, because of scaling and different resolutions. But do field of view and aspect ratio effect the results? Edit: Sorry yes, I am talking about perspective projection. Seems the answer is no then, perspective will distort the sphere. Thanks!

    Read the article

  • Multiple circles -> One Polygon?

    - by Josh
    Using Google Maps API v3, I was able to create multiple google.maps.Circle objects on my map. However, I now need to "connect" them somehow. I have the following map with multiple circles: I now need to get it to look something like this: I've looked all over the Internet for solutions, but to no avail. Any ideas?

    Read the article

  • QuickBox2D poly behaviour vs box or circle

    - by Ben Kanizay
    Hi I've played a little with Box2D before and have just started using QuickBox2D which makes things heaps easier. I am however getting different behaviour with a specific poly shape than I am with a box. All other properties are the same. I've included 3 simple examples and their source below. What I really want to work is Example 1 with both objects as poly. As you can see, it seems like the 'paddle' poly is the one that's failing - the 'ball' (whether it's a poly or circle) just falls straight through it instead of bouncing off as it does with a box 'paddle' object. Would appreciate some help or insight. As I can only post one line at this stage, the swf previews of the 3 examples can be seen here Example 1 source: package { import com.actionsnippet.qbox.QuickBox2D; import com.actionsnippet.qbox.QuickObject; import flash.display.MovieClip; public class Eg1 extends MovieClip { private var sim:QuickBox2D; private var paddle:QuickObject; private var ball:QuickObject; public function Eg1() { this.sim = new QuickBox2D(this); this.paddle = this.sim.addPoly({ x:13, y:19, angle:0, density:0, draggable:false, isBullet:true, verts:[[-3.84,-0.67,-2.84,-1,-2.17,-0.33,2.17,-0.33,2.84,-1,3.84,-0.67,2.84,1,-2.51,1]] }); this.ball = this.sim.addPoly({ x:13, y:1, restitution:1, friction:1, draggable:false, isBullet:true, verts:[[-0.34,-1,0.34,-1,0.67,-0.33,0.67,0.33,0.34,1,-0.34,1,-0.67,0.33,-0.67,-0.33]] }); this.sim.start(); } }} Example 2 source: package { import com.actionsnippet.qbox.QuickBox2D; import com.actionsnippet.qbox.QuickObject; import flash.display.MovieClip; public class Eg2 extends MovieClip { private var sim:QuickBox2D; private var paddle:QuickObject; private var ball:QuickObject; public function Eg2() { this.sim = new QuickBox2D(this); this.paddle = this.sim.addBox({ x:13, y:19, angle:0, density:0, draggable:false, isBullet:true, width:8 }); this.ball = this.sim.addPoly({ x:13, y:1, restitution:1, friction:1, draggable:false, isBullet:true, verts:[[-0.34,-1,0.34,-1,0.67,-0.33,0.67,0.33,0.34,1,-0.34,1,-0.67,0.33,-0.67,-0.33]] }); this.sim.start(); } }} Example 3 source: package { import com.actionsnippet.qbox.QuickBox2D; import com.actionsnippet.qbox.QuickObject; import flash.display.MovieClip; public class Eg3 extends MovieClip { private var sim:QuickBox2D; private var paddle:QuickObject; private var ball:QuickObject; public function Eg3() { this.sim = new QuickBox2D(this); this.paddle = this.sim.addPoly({ x:13, y:19, angle:0, density:0, draggable:false, isBullet:true, verts:[[-3.84,-0.67,-2.84,-1,-2.17,-0.33,2.17,-0.33,2.84,-1,3.84,-0.67,2.84,1,-2.51,1]] }); this.ball = this.sim.addCircle({ x:13, y:1, restitution:1, friction:1, draggable:false, isBullet:true, radius:1 }); this.sim.start(); } }}

    Read the article

  • Animated Circular bar on hover

    - by Anthony
    I'm building a portfolio website and want to implement a skill set page which feature an animated circular bar which represent each of my skills. There will be 6 buttons around the circle which when the user hovers over, and when one is hovered I want a circular bar to animate anti-clockwise. I've made a quick .gif in photoshop to demonstrate But I can't find any tutorial to help. I found this website which features a similar concept on the left hand side at the top, an animated pie chart - Website Example And this is a quick .gif Mockup I did in photoshop of what I am trying to achieve - Animated Circular Bar Animation

    Read the article

  • suggest an algorithm for the following puzzle!!

    - by garima
    There are n petrol bunks arranged in circle. Each bunk is separated from the rest by a certain distance. You choose some mode of travel which needs 1litre of petrol to cover 1km distance. You can't infinitely draw any amount of petrol from each bunk as each bunk has some limited petrol only. But you know that the sum of litres of petrol in all the bunks is equal to the distance to be covered. ie let P1, P2, ... Pn be n bunks arranged circularly. d1 is distance between p1 and p2, d2 is distance between p2 and p3. dn is distance between pn and p1.Now find out the bunk from where the travel can be started such that your mode of travel never runs out of fuel.

    Read the article

  • Collision detection problems...

    - by thyrgle
    Hi, I have written the following: -(void) checkIfLineCollidesWithAll { float slope = ((160-L1Circle1.position.y)-(160-L1Circle2.position.y))/((240-L1Circle1.position.x)-(240-L1Circle2.position.x)); float b = (160-L1Circle1.position.y) - slope * (240-L1Circle1.position.x); if ((240-L1Sensor1.position.x) < (240-L1Circle1.position.x) && (240-L1Sensor1.position.x) < (240-L1Circle2.position.x) || ((240-L1Sensor1.position.x) > (240-L1Circle1.position.x) && (240-L1Sensor1.position.x) > (240-L1Circle2.position.x))) { [L1Sensor1 setTexture:[[CCTextureCache sharedTextureCache] addImage:@"SensorOk.png"]]; } else if (slope == INFINITY || slope == -INFINITY) { if (L1Circle1.position.y + 16 >= L1Sensor1.position.y || L1Circle1.position.y - 16 <= L1Sensor1.position.y) { [L1Sensor1 setTexture:[[CCTextureCache sharedTextureCache] addImage:@"SensorBad.png"]]; } else { [L1Sensor1 setTexture:[[CCTextureCache sharedTextureCache] addImage:@"SensorOk.png"]]; } } else if (160-L1Sensor1.position.y + 12 >= slope*(240-L1Sensor1.position.x) + b && 160-L1Sensor1.position.y - 12 <= slope*(240-L1Sensor1.position.x) + b) { [L1Sensor1 setTexture:[[CCTextureCache sharedTextureCache] addImage:@"SensorBad.png"]]; } else { [L1Sensor1 setTexture:[[CCTextureCache sharedTextureCache] addImage:@"SensorOk.png"]]; } } Basically what this does is finds m and b in the well known equation: y = mx + b and then substitutes coordinates of the L1Sensor1 (the circle I'm trying to detect if it it intersects with the line segment) to see if y = mx + b hold true. But, there are two problems, first, when slope approaches infinity the range of what the L1Sensor1 should "react" to (it "reacts" by changing its image) becomes smaller. Also, the code that should handle infinity is not working. Thanks for the help in advanced.

    Read the article

  • Box2d Cocos2d circle crash on contact with ground

    - by Oliver Cooper
    this is my first question here so sorry if I do something wrong or this is too long. I have been reading this tutorial by Ray Wenderlich, I have modified it so it is flatter and gradually goes down hill. Basically I have a ball roll down a bumpy hill, but at the moment the ball only drops from about 100 pixels above. When ever the touch the app crashes (the app is a Mac Cocos2d Box2d app). The ball code is this: CGSize winSize = [CCDirector sharedDirector].winSize; self.oeva = [CCSprite spriteWithTexture:[[CCTextureCache sharedTextureCache] addImage:@"Ball.png"]rect:CGRectMake(0, 0, 64, 64)]; _oeva.position = CGPointMake(68, winSize.height/2); [self addChild:_oeva z:1]; b2BodyDef oevaBodyDef; oevaBodyDef.type = b2_dynamicBody; oevaBodyDef.position.Set(68/PTM_RATIO, (winSize.height/2)/PTM_RATIO); // oevaBodyDef.userData = _oeva; _oevaBody = world->CreateBody(&oevaBodyDef); b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; bodyDef.position.Set(60/PTM_RATIO, 400/PTM_RATIO); bodyDef.userData = _oeva; b2Body *body = world->CreateBody(&bodyDef); // Define another box shape for our dynamic body. b2CircleShape dynamicBox; dynamicBox.m_radius = 70/PTM_RATIO;//These are mid points for our 1m box // Define the dynamic body fixture. b2FixtureDef fixtureDef; fixtureDef.shape = &dynamicBox; fixtureDef.density = 1.0f; fixtureDef.friction = 0.3f; body->CreateFixture(&fixtureDef); That works fine. This is the terrain code, this also works fine: -(void)generateTerrainWithWorld: (b2World *) inputWorld: (int) hillSize;{ b2BodyDef bd; bd.position.Set(0, 0); body = inputWorld->CreateBody(&bd); b2PolygonShape shape; b2FixtureDef fixtureDef; currentSlope = 0; CGSize winSize = [CCDirector sharedDirector].winSize; float xf = 0; float yf = (arc4random() % 10)+winSize.height/3; int x = 200; for(int i = 0; i < maxHillPoints; ++i) { hillPoints[i] = CGPointMake(xf, yf); xf = xf+ (arc4random() % x/2)+x/2; yf = ((arc4random() % 30)+winSize.height/3)-currentSlope; currentSlope +=10; } int hSegments; for (int i=0; i<maxHillPoints-1; i++) { CGPoint p0 = hillPoints[i-1]; CGPoint p1 = hillPoints[i]; hSegments = floorf((p1.x-p0.x)/cosineSegmentWidth); float dx = (p1.x - p0.x) / hSegments; float da = M_PI / hSegments; float ymid = (p0.y + p1.y) / 2; float ampl = (p0.y - p1.y) / 2; CGPoint pt0, pt1; pt0 = p0; for (int j = 0; j < hSegments+1; ++j) { pt1.x = p0.x + j*dx; pt1.y = ymid + ampl * cosf(da*j); fullHillPoints[fullHillPointsCount++] = pt1; pt0 = pt1; } } b2Vec2 p1v, p2v; for (int i=0; i<fullHillPointsCount-1; i++) { p1v = b2Vec2(fullHillPoints[i].x/PTM_RATIO,fullHillPoints[i].y/PTM_RATIO); p2v = b2Vec2(fullHillPoints[i+1].x/PTM_RATIO,fullHillPoints[i+1].y/PTM_RATIO); shape.SetAsEdge(p1v, p2v); body->CreateFixture(&shape, 0); } } However when ever the two collide the app crashes. The crash error is: Thread 6 CVDisplayLink: Program received signal: "SIGABRT" The error occurs on line 96 of b2ContactSolver.cpp: b2Assert(kNormal > b2_epsilon); The error log is: Assertion failed: (kNormal 1.19209290e-7F), function b2ContactSolver, file /Users/coooli01/Documents/Xcode Projects/Cocos2d/Hill Slide/Hill Slide/libs/Box2D/Dynamics/Contacts/b2ContactSolver.cpp, line 96. Sorry if I rambled on for too long, i've been stuck on this for ages.

    Read the article

  • rotating circle with swipe question

    - by Joe
    Okay so I'm making something that basically works as a knob, but only half on the screen -- so I just need horizontal swipes to cause it to rotate. I have it nearly all sorted with one exception: if you change direction of your swipe in mid-swipe, the rotation doesn't change direction. I even can see the problem, but not sure what to do about a solution. So in my touchesMoved, I get the swipe into radians in the predictable way: CGFloat radians = atan2f(location.y - centerY, location.x - centerX); I then store radians, add/subtract it to previous rotation and then give the result to the CATransform3D. So the prob is that even though the swipe changes direction, there is a "balance" which doesn't allow an immediate change of direction. Does this make any sense?

    Read the article

  • How can I correctly display my AVL Tree in LaTex? A solo left-child hangs straight down....

    - by cb
    The below code almost works perfectly, however the child of 9, 7, hangs straight down instead of as a left-child. How can I correct this? \usepackage{tikz} \usepackage{xytree} \begin{tikzpicture}[level/.style={sibling distance=60mm/#1}] \node [circle,draw] {4} child { node [circle,draw] {2} child {node [circle,draw] {1} } child { node [circle,draw]{3} } } child {node [circle,draw] {6} child {node [circle,draw] {5} } child {node [circle,draw] {9} child {node [circle, draw] {7}} } }; \end{tikzpicture}} Thanks, CB

    Read the article

  • Place text based divs in relative locations within a circle

    - by NickG
    Direct question - How would I place certain objects or small text within a certain area. For example, how would I replace the following image with html/javascript. --- I don't have enough reps to post an image :/ but try this URL - http://i.imgur.com/a3eWL.jpg Big picture - I am trying to create a kml file for Google Earth that when the point is clicked, the balloon description window pops up and I can display my html formatted diagram showing where the satellites are at that instant. Google Earth and KML docs allow for pretty much any html formatting within it, so currently looking for a good way to do this. Disclaimer: It has been a few years since i have done any html or javascript editing, so general examples and insight is greatful. Thanks

    Read the article

  • Oval collision detection not working properly

    - by William
    So I'm trying to implement a test where a oval can connect with a circle, but it's not working. edist = (float) Math.sqrt(Math.pow((px + ((pwidth/2) )) - (bx + (bsize/2)), 2) + Math.pow(-((py + ((pwidth/2)) ) - (bx + (bsize/2))), 2)); and here is the full code (requires Slick2D): import org.newdawn.slick.AppGameContainer; import org.newdawn.slick.BasicGame; import org.newdawn.slick.Color; import org.newdawn.slick.GameContainer; import org.newdawn.slick.Graphics; import org.newdawn.slick.Input; import org.newdawn.slick.SlickException; public class ColTest extends BasicGame{ float px = 50; float py = 50; float pheight = 50; float pwidth = 50; float bx = 200; float by = 200; float bsize = 200; float edist; float pspeed = 3; Input input; public ColTest() { super("ColTest"); } @Override public void init(GameContainer gc) throws SlickException { } @Override public void update(GameContainer gc, int delta) throws SlickException { input = gc.getInput(); try{ if(input.isKeyDown(Input.KEY_UP)) py-=pspeed; if(input.isKeyDown(Input.KEY_DOWN)) py+=pspeed; if(input.isKeyDown(Input.KEY_LEFT)) px-=pspeed; if(input.isKeyDown(Input.KEY_RIGHT)) px+=pspeed; } catch(Exception e){} } public void render(GameContainer gc, Graphics g) throws SlickException { g.setColor(new Color(255,255,255)); g.drawString("col: " + col(), 10, 10); g.drawString("edist: " + edist + " dist: " + dist, 10, 100); g.fillRect(px, py, pwidth, pheight); g.setColor(new Color(255,0,255)); g.fillOval(px, py, pwidth, pheight); g.setColor(new Color(255,255,255)); g.fillOval(200, 200, 200, 200); } public boolean col(){ edist = (float) Math.sqrt(Math.pow((px + ((pwidth/2) )) - (bx + (bsize/2)), 2) + Math.pow(-((py + ((pwidth/2)) ) - (bx + (bsize/2))), 2)); if(edist <= (bsize/2) + (px + (pwidth/2))) return true; else return false; } public float rotate(float x, float y, float ox, float oy, float a, boolean b) { float dst = (float) Math.sqrt(Math.pow(x-ox,2.0)+ Math.pow(y-oy,2.0)); float oa = (float) Math.atan2(y-oy,x-ox); if(b) return (float) Math.cos(oa + Math.toRadians(a))*dst+ox; else return (float) Math.sin(oa + Math.toRadians(a))*dst+oy; } public static void main(String[] args) throws SlickException { AppGameContainer app = new AppGameContainer( new ColTest() ); app.setShowFPS(false); app.setAlwaysRender(true); app.setTargetFrameRate(60); app.setDisplayMode(800, 600, false); app.start(); } }

    Read the article

  • Can we identify individual sectors of a circle component uniquely in flex?

    - by Angeline Aarthi
    I have a custom circle component in my application, which is divided into 3 sectors as of now.Can we uniquely identify each segments of this circle? I want to drag and drop text or images from another container to this circle component. But I want to place different images in the different sectors. Is it possible to distinguish the individual sectors of the circle component? Here is my code: <mx:TabNavigator width="624" height="100%"> <mx:VBox id="currQuote" label="Currents Quote" width="100%"> <comp:MyCircle x1="175" y1="150" radius="150"/> <comp:MyCircle x1="175" y1="150" radius="120"/> <comp:MyCircle x1="175" y1="150" radius="25"/> <comp:MyLine x1="160" y1="122"/> </mx:VBox> <mx:VBox label="Quote Comparison" width="100%"/> <mx:VBox label="Reports" width="100%"/> </mx:TabNavigator> Circle component: package components { import mx.core.UIComponent; public class MyCircle extends UIComponent { public var x1:int; public var y1:int; public var radius:int; override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { graphics.lineStyle(1, 0x000000); graphics.drawCircle(x1, y1, radius); } } } Line component: package components { import mx.core.UIComponent; public class MyLine extends UIComponent { public var x1:int; public var y1:int; override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { graphics.lineStyle(1, 0x000000); graphics.moveTo(100,0); graphics.lineTo(x1, y1); graphics.moveTo(250,0); graphics.lineTo(185,120); } } } Actually I want the circle to be divided into 6 sectors, but for now just divided it into 3 sectors. But is it possible to uniqulely identify the individual sectors of the circle so that I can drag different images or texts into those particular sectors?

    Read the article

  • Drawing Quadratic Bezier circles with a given radius: how to determine control points

    - by Casey
    Just to clarify; the code below works, but I don't understand where the formula for the variable "controlRadius" comes from. I wrote this function by dissecting an example I found elsewhere, but I can't find any explanation and the original code comments were not able to be translated. Thanks in advance //returns an array of quadratic Bezier segments public static function generateCircularQuadraticBezierSegments(radius:Number, numControlPoints:uint, centerX:Number, centerY:Number):Array { var segments:Array = []; var arcLength:Number = 2 * Math.PI / numControlPoints; var controlRadius:Number; var segment:QuadraticBezierSegment; for (var i:int = 0; i < numControlPoints; i++) { var startX:Number = centerX + radius * Math.cos(arcLength * i); var startY:Number = centerY + radius * Math.sin(arcLength * i); //control radius formula //where does it come from, why does it work? controlRadius = radius / Math.cos(arcLength * .5); //the control point is plotted halfway between the arcLength and uses the control radius var controlX:Number = centerX + controlRadius * Math.cos(arcLength * (i + 1) - arcLength * .5); var controlY:Number = centerY + controlRadius * Math.sin(arcLength * (i + 1) - arcLength * .5); var endX:Number = centerX + radius * Math.cos(arcLength * (i + 1)); var endY:Number = centerY + radius * Math.sin(arcLength * (i + 1)); segment = new QuadraticBezierSegment(new Point(startX, startY), new Point(controlX, controlY), new Point(endX, endY)); segments.push(segment); } return segments; }

    Read the article

  • Get all Vector2 Points Within Radius

    - by CheapDevotion
    I am looking for a formula that will give me all of the Vector2 Points within a certain radius given the center. Essentially what I am trying to do is change the color of each pixel in a 256 x 256 texture that is within a certain radius from a specific pixel (Using the Unity3d Game Engine). Programming Language doesn't really matter, as I can probably convert it to something I can use.

    Read the article

  • How to keep text inside a circle using Cairo?

    - by miguelrios
    I a drawing a graph using Cairo (pycairo specifically) and I need to know how can I draw text inside a circle without overlapping it, by keeping it inside the bounds of the circle. I have this simple code snippet that draws a letter "a" inside the circle: ''' Created on May 8, 2010 @author: mrios ''' import cairo, math WIDTH, HEIGHT = 1000, 1000 #surface = cairo.PDFSurface ("/Users/mrios/Desktop/exampleplaces.pdf", WIDTH, HEIGHT) surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, WIDTH, HEIGHT) ctx = cairo.Context (surface) ctx.scale (WIDTH/1.0, HEIGHT/1.0) # Normalizing the canvas ctx.rectangle(0, 0, 1, 1) # Rectangle(x0, y0, x1, y1) ctx.set_source_rgb(255,255,255) ctx.fill() ctx.arc(0.5, 0.5, .4, 0, 2*math.pi) ctx.set_source_rgb(0,0,0) ctx.set_line_width(0.03) ctx.stroke() ctx.arc(0.5, 0.5, .4, 0, 2*math.pi) ctx.set_source_rgb(0,0,0) ctx.set_line_width(0.01) ctx.set_source_rgb(255,0,255) ctx.fill() ctx.set_source_rgb(0,0,0) ctx.select_font_face("Georgia", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) ctx.set_font_size(1.0) x_bearing, y_bearing, width, height = ctx.text_extents("a")[:4] print ctx.text_extents("a")[:4] ctx.move_to(0.5 - width / 2 - x_bearing, 0.5 - height / 2 - y_bearing) ctx.show_text("a") surface.write_to_png ("/Users/mrios/Desktop/node.png") # Output to PNG The problem is that my labels have variable amount of characters (with a limit of 20) and I need to set the size of the font dynamically. It must fit inside the circle, no matter the size of the circle nor the size of the label. Also, every label has one line of text, no spaces, no line breaks. Any suggestion?

    Read the article

  • Can some explain why this wont draw a circle? It is drawing roughly 3/4?

    - by Brandon Shockley
    If we want to use n small lines to outline our circle then we can just divide both the circumference and 360 degrees by n (i.e , (2*pi*r)/n and 360/n). Did I not do that? import turtle, math window = turtle.Screen() window.bgcolor('blue') body = turtle.Turtle() body.pencolor('black') body.fillcolor('white') body.speed(10) body.width(3) body.hideturtle() body.up() body.goto(0, 200) lines = 40 toprad = 40 top_circum = 2 * math.pi * toprad sol = top_circum / lines circle = 360 / lines for stops in range(lines): body.pendown() body.left(sol) body.forward(circle) window.exitonclick()

    Read the article

  • Got a question I don't understand, can anyone make sense of it?

    - by user275074
    Question on a on-line resource paper: Create javascript so that the following methods produce the output listed next it. circle = new Circle(); console.log(circle.get_area()); // 3.141592653589793 circle.set_radius(10); console.log(circle.get_area()); // 314.1592653589793 console.log(circle); // the radius of my circle is 10 and it's area is 314.1592653589793 Can anyone understand what is being asked?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >