C++ :: Drawing A Rectangle And Diamond Using Recursion?
Oct 23, 2013
write a code that draw a block and diamond each in a single run by using '*' in recursion.
Below are one 10X10 rectangle and 6X4 diamond.
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
**
* *
* *
* *
* *
* *
* *
* *
**
Note: I couldn't write the diamond here appropriately somehow.
View 1 Replies
ADVERTISEMENT
Nov 3, 2014
I've been given the task of converting a java application to a c# windows form application. The program displays a Mandelbrot which then allows the user to zoom into. I've managed to display the Mandelbrot and even zoom. However when dragging a box to zoom, the box its self doesn't show, meaning the user cannot see what area they will be zooming into.
I believe I need to call the update function which draws the rectangle as I drag however no matter what I try, I get errors from a red cross instead of the Mandelbrot to compile errors. Here is the code that I believe is relevant.
public void update(Graphics g) {
Color color = Color.White;
Pen myPen = new Pen(color);
g.DrawImage(myBitmap, 0, 0);
if (rectangle) {
[Code]....
View 3 Replies
View Related
Apr 24, 2015
For a Texas holdem' project I need to be able to draw out rectangles using ASCII codes and for loops. I started the code
#include <iostream>
#include <string>
#include <Windows.h>
[Code].....
View 6 Replies
View Related
Jan 23, 2015
I am trying to draw a rubber band rectangle. I have got a following code from a site but its giving an error:
Code:
class CSampleView: Public CView{
...
public:
CrectTracker m_tracker;//Changed to CRectTracker
...
};
Secondly, in the constructor to initialize the object CRectTracker document class:
CSampleDoc :: CSampleDOC () {
// Initialize tracker position, size and style.
m_tracker.m_rect.SetRect (0, 0, 10, 10);
m_tracker.m_nStyle = CRectTracker :: resizeInside |
CRectTracker :: dottedLine;
}
The error is:
error C2065: 'm_tracker' : undeclared identifier
How to get rid of this error??
View 4 Replies
View Related
May 13, 2014
Consider I have a rectangle like this:
Point p1(100,100);
Point p2(300,200);
Graph_lib::Rectangle r(p1,p2);
And also I have a function that takes a rectangle and returns a Point of that, say, top-left corner of that rectangle. For example:
Point N(Graph_lib::Rectangle R1);
My question is that, first, how to send that Rectangle r(p1,p2) to the Point N(Graph_lib::Rectangle R1) function? And then, how to return a Point from that function?
My IDE is visual studio 2012.
View 19 Replies
View Related
Jul 11, 2013
Getting close but I think I am stuck on the second loop. The input you put in will be doubled (and it's not supposed to).
Code:
int main() {
int n, i, j, k;
printf("What would you like the height to be? (Positive odd integer)
");
scanf("%d", &n);
[Code] .....
View 3 Replies
View Related
Sep 6, 2014
I feel as if I'm so close and I'm just messing up a value somewhere, but I am at a loss as to what I should change. Here is my code:
#include "stdafx.h"
#include <iomanip>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[]) {
[Code] ....
View 2 Replies
View Related
Sep 6, 2014
I have been tasked with making a diamond out of asterisks based on a given odd integer input. For some reason the bottom half of my diamond will not print. I'm not sure as to why.
Here is my code:
#include "stdafx.h"
#include <iomanip>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[]){
[Code] ....
View 2 Replies
View Related
Jan 15, 2015
#include <iostream>
using namespace std;
int main(){
return 0;
}
this is my main functions. I have problem making a program that prints in asterisks an oval, arrow and a diamond using for loop and if statements.
View 1 Replies
View Related
Jan 18, 2013
I'm in the beginning stages of designing my first video game using SDL, and have run into a bit of an impasse. I attempt to draw the map using a simple tile function and nothing prints to the screen. I am going to attach the function itself.
bool Tile::draw_tiles ( void ) {
GV gv;
//Open the map
std::ifstream map ( "test.map" );
for ( int y = 0; y < GV::MAP_HEIGHT / 64; y++ ) {
for ( int x = 0; x < GV::MAP_WIDTH / 64; x++ ) {
[Code] ....
Extra notes:
1. Compiles fine.
2. No run time errors (this function returns true).
3. Apply surface is a function that takes an x and y value for position on the
map, an image, a screen to print it to, and a rectangle to cut out the image out of.
4. I did some bug testing and added another function to print the image SDLS_tiles by itself (its just a simple sprite map) after the map.close() function, and it worked fine.
View 1 Replies
View Related
May 3, 2013
i have to make an application called " paint " in c++ . It should facilitate user to draw different shapes using a mouse. Now the biggest hurdle i am facing is the usage of mouse .. what is the header file for usage of mouse ? i am using visual studio 2010 . the syntax is creating problems ..
View 1 Replies
View Related
Mar 11, 2014
Found a good beginner's tutorial to learn Visual C++: [URL] ....
How to change the drawing so that instead of squares, the game draws circles. Can figure out that using Ellipse in the code results in circle outlines, but the fill remains as square color shapes.
The drawing code from the tutorial is below. How to substitute filled circles for filled squares.
Code:
// CSameGameView drawing
void CSameGameView::OnDraw(CDC* pDC){
// First get a pointer to the document
CSameGameDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(!pDoc)
[Code] ....
View 6 Replies
View Related
Nov 22, 2013
I'm doing a project and I need to draw a square into a pgm image if certain conditions are met, but I'm not sure how to draw the square into the image.
View 2 Replies
View Related
Oct 10, 2013
I am supposed to create a class of rectangular prism in opengl. I am having touble in writing my "draw()" function.
I have searched the web, and lots of the sites have:
glBegin(GL_Quads);
glVertex3f(x,y,z);
glVertex3f(...);
glVertex3f(...);
glVertex3f(...);
3D coordinates for each face.
For my code, I am getting a value for lengths of x, y and z like "getXlength(x_length)" etc... I would like to know how I can use these values to draw the prism rather than giving values for each coordinates in each face.
View 1 Replies
View Related
Jan 27, 2014
This is the text of exercise 4 of chapter 12 of PPP; Draw a checkers board: 8-by-8 alternating white and red squares.
Is there a way to use the loop for doing that code to minimize the size of the code?
View 9 Replies
View Related
Oct 5, 2012
I wrote a simple clock that shows the time over bitmap as follows:
Code:
void CMyClock::OnPaint()
{
CRect rect;
GetClientRect(&rect);
[Code]....
Now I got rid off the white border but everytime I draw a text it write on top of the previous text so after few seconds everything is a mess and the time is no longer readable.
View 5 Replies
View Related
Sep 23, 2014
The assignment is:
1) Write a program that asks the user for a a single character and two XY coordinates. The two X and two Y values should all be integers between 0 and 50. The character should be a printable ASCII character with values between and including ' !' (ascii value 33) and '~' (ascii value 126).
2) Your program should then draw a rectangle made up of the user selected character where the upper left corner is at X1; Y 1 and the lower right corner is at X2; Y2. Be sure to print the appropriate number of blank lines (having spaces in the blank rows is OK) in the beginning and pad each row of your rectangle with X1 leading spaces.
The Output is supposed to be similar to this:
(X1,Y1) = (0,0) , (X2,Y2) = (4,4), the character = ^
^^^^
^^^^
^^^^
^^^^
What I am having trouble understanding is printing between certain ASCII values (ASCII has never been discussed in class).
Another thing I am having trouble with is the main part of the assignment. From what we are currently discussing is loops and the assignment is covering nested loops. My code looks similar to this:
Code:
#include <stdio.h>
int main (void) {
int X1, Y1, X2, Y2;
char cRec;
printf("Enter a character: ");
scanf("%c", &cRec);
[Code] .....
My thinking on the assignment is that you want the X1 coordinate to increase to the value of X2 (same for Y1 and Y2). Is this thinking wrong?
View 12 Replies
View Related
Jan 19, 2015
Make an "analog clock" that is, a clock with hands that move. You get the time of day from the operating system through a library call. A major part of this exercise is to find the functions that give you the time of day and a way of waiting for a short period of time (e.g., a second for a clock tick) and to learn to use them based on the documentation you found. Hint: clock(), sleep().
OK, I wrote below code. It is in its primary stages and has not been completed yet.
#include <GUI.h>
#include <time.h>
#include <iostream>
using namespace Graph_lib;
[Code] .....
I expect the system in void clock_hands() (line 38) attaches hour1 (line 41) then waits for 1000 ms (using Sleep(1000)) then detaches hour1 and attaches hour2 this time. But it doesn't occur in practice. When the system reaches Sleep(1000); it seems to go into a comma! It doesn't show the hour1 so seeing the movement of clock ticks by the clock's hands will not be possible.
View 5 Replies
View Related
Jul 3, 2014
I am working on a code and first i need to initialize the array depending on the size (min size 3x3, maximum size 9x9). The initialized array will descend in order. Note that it seems like a simple code and seems to work for any size from 3x3 to 7x7, but for some reason i get a strange output in the last few rows for 8x8 and 9x9. Not sure why. The second part to my problem is the very last digit of 0. I did hard code to define it but i would like to make it a character like an underscore...what is the easy way to do this?
* Implements the Game of Fifteen (generalized to d x d).
*
* Usage: ./fifteen d
*
* whereby the board's dimensions are to be d x d,
* where d must be in [MIN,MAX]
*
* Note that usleep is obsolete, but it offers more granularity tha sleep and is simpler to use than nanosleep; `man usleep` for more.
#define _XOPEN_SOURCE 500
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
// board's minimal dimension
#define MIN 3
[Code] .....
View 14 Replies
View Related
Aug 1, 2014
I'm making a program to draw a trajectory, was using as a basis the tangent, but when I put 90 degrees, the tangent is very large, so I thought of putting an if (angle == 90) did not use the tangent.
the design is right, but after choosing it 90 degrees it stops to draw.
for example
1-30 degrees - draws
2-45 degrees ---- draws
3 draws -90 degrees ---
4-60 degrees --- not drawing
5 --- 80 degrees --- not drawing
*
*
making routine design is presented below:
void Draw() {
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINES);
convert(graus);
if (ant){
x=xx;
y=yy;
[code]....
View 4 Replies
View Related
Oct 11, 2013
I am drawing in a simple (square) MFC window. I realize that (0,0) starts in the upper left hand corner. I wanted to see how MFC handled drawing of angles, so I use this code:
Code:
double CompassDegreesToRadians(double compassDegrees) {
return((PI / 2.0f) - (compassDegrees * PI / 180.0f));
}
// Make pen
CPen penRed;
penRed.CreatePen(PS_SOLID | PS_COSMETIC, 1, RGB(255, 0, 0));
// Test Angles
[Code] .....
Using this code, and changing the value of angle1 to these values (0, 90, 180, 270) I think MFC uses the coordinate system:
Code:
180 -y
|
|
-x 270---------------- 90 +x
|
|
0 +y
This seems like a strange coordinate system to use. Am I doing something wrong? If this is correct, how can I convert my calculations to this coordinate system? (compass degrees):
Code:
0 +y
|
|
-x 270---------------- 90 +x
|
|
180 -y
View 4 Replies
View Related
Jul 6, 2014
I am trying to figure out how to create a program that will draw a triangle using *'s with a base the has a user-inputted number of *'s like so:
*
***
*****
It needs to take a user inputted number and draw a pyramid like the above pyramid with the number of *'s in the base matching the user inputted number (i.e., user enters 10, so the triangle has 10 *'s in the base). I figured it would be best to first create a loop to draw out the correct number of *'s before trying to create another loop to draw out the correct number of spaces, to properly align the *'s into a triangle shape.
int width = 0;
int height = 0;
int i = 0;
int leafWidth = 0;
[Code] .....
View 7 Replies
View Related
Oct 4, 2014
the code draws rectangle or square it depends on you (column,row) then, put number in the center of the rectangle i don't want to extra space after putting one,two,three or four digits number in the center of the rectangle
#include <stdio.h>
int main(){
int i,j;
[Code]....
View 3 Replies
View Related
Feb 9, 2015
In 2D games, what's the best way to handle the order of drawing objects? Because most games have a background, tiles to be drawn behind the player, perhaps tiles to be drawn covering up the player, etc. My point is, with my current setup of simply looping through all objects and drawing, I have no control over what objects are drawn on top of or behind the others. My best idea so far is to hold a vector of object pointers, each vector representing a different "visibility level", like so:
class Level{
//...
std::vector<Object> allObjectInstances;
std::vector<Object*> visibilityOne; //background objects
std::vector<Object*> visibilityTwo; //objects in front of background but not necessarily all the way in front
//and so on for more objects
};
If I go through with this, I'm wondering how I could loop through all my objects and add them to each vector, then shorten whatever I have to loop through for subsequent visibility vectors. handling the order of drawing objects?
View 6 Replies
View Related
Apr 23, 2014
I'm having issues with drawing a flat style dropdown menu in XP.
Here is the custom dropdown menu element:
public class FlattenCombo : ComboBox {
private Brush BorderBrush = new SolidBrush(SystemColors.WindowFrame);
private Brush ArrowBrush = new SolidBrush(SystemColors.ControlText);
private Brush DropButtonBrush = new SolidBrush(SystemColors.Control);
public Color HighlightColor { get; set; }
[Code] ....
Here is what it looks like in XP:
And here's what it should look like (this is how it's rendered in Windows Vista/7):
View 3 Replies
View Related
Jan 22, 2014
I want to show a list of graphical items in 1 or 2 columns (user selected). I will draw the items (owner-draw). I tried many hours today to find a solution with clistctrl. Is it possible to make it with clistctrl?
View 14 Replies
View Related