void drawTrace(Position oldPosition, Position position, SDL_Surface* ecran) { /* AFFICHAGE NOUVEAU POINT */ //# SDL_Surface *mouseTrace = SDL_CreateRGBSurface(SDL_HWSURFACE, 10, 10, 32, 0, 255, 0, 0); Uint32 color = SDL_MapRGB(ecran->format, 180, 0, 0); // Hide real cursor drawDot(ecran, position.x, position.y, color); // Blit onto main surface //# SDL_BlitSurface(mouseTrace, NULL, ecran, &dst); /* AFFICHAGE MOITIE (completion) */ if (!seCroisent(position, oldPosition)){ // calc milieu // afficher milieu // draw gauche // draw droite Position milieu; milieu.x = (position.x + oldPosition.x)/2; milieu.y = (position.y + oldPosition.y)/2; drawDot(ecran, milieu.x, milieu.y, color); drawTrace(position, milieu, ecran); drawTrace(milieu, oldPosition, ecran); } }
void MapView::normalPlanetDrawer(QPainter &painter, const Planet *planet, const QPoint &pos) { long seen = planet->SeenBy(player); if(seen == 0) { noInfoPlanetDrawer(painter, planet, pos); return; } const Player *owner = planet->GetOwner(); int diameter = 3; if(seen & SEEN_OWNER) { if(owner != NULL) { long relation = player->GetRelations(owner); if(relation == PR_SELF) { if(planet->IsHW()) { diameter += 1; } fillCircle(painter, pos, diameter, Qt::green); } else if(relation == PR_FRIEND) { fillCircle(painter, pos, diameter, Qt::yellow); } else { fillCircle(painter, pos, diameter, Qt::red); } } else { drawDot(painter, pos, Qt::white); } } else { drawDot(painter, pos, Qt::white); } if(seen & SEEN_HULL) { const deque<SpaceObject *> *alsoHere = planet->GetAlsoHere(); if(alsoHere && !alsoHere->empty()) { diameter += 3; painter.setPen(Qt::white); drawCircle(painter, pos, diameter); } if(planet->GetBaseDesign() != NULL) { fillCircle(painter, pos + QPoint(3, -3), 2, Qt::yellow); } } }
void ShiftTraceTool::drawControlRect() { if (m_ghostIndex < 0 || m_ghostIndex > 1) return; int row = m_row[m_ghostIndex]; if (row < 0) return; int col = TApp::instance()->getCurrentColumn()->getColumnIndex(); TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); TXshCell cell = xsh->getCell(row, col); if (cell.isEmpty()) return; TImageP img = cell.getImage(false); if (!img) return; TRectD box; if (TRasterImageP ri = img) { TRasterP ras = ri->getRaster(); box = (convert(ras->getBounds()) - ras->getCenterD()) * ri->getSubsampling(); } else if (TToonzImageP ti = img) { TRasterP ras = ti->getRaster(); box = (convert(ras->getBounds()) - ras->getCenterD()) * ti->getSubsampling(); } else if (TVectorImageP vi = img) { box = vi->getBBox(); } else { return; } glPushMatrix(); tglMultMatrix(getGhostAff()); TPixel32 color; color = m_highlightedGadget == TranslateGadget ? TPixel32(200, 100, 100) : TPixel32(120, 120, 120); tglColor(color); glBegin(GL_LINE_STRIP); glVertex2d(box.x0, box.y0); glVertex2d(box.x1, box.y0); glVertex2d(box.x1, box.y1); glVertex2d(box.x0, box.y1); glVertex2d(box.x0, box.y0); glEnd(); color = m_highlightedGadget == 2000 ? TPixel32(200, 100, 100) : TPixel32::White; double r = 4 * sqrt(tglGetPixelSize2()); drawDot(box.getP00(), r, color); drawDot(box.getP01(), r, color); drawDot(box.getP10(), r, color); drawDot(box.getP11(), r, color); if (m_curveStatus == NoCurve) { color = m_highlightedGadget == 2001 ? TPixel32(200, 100, 100) : TPixel32::White; TPointD c = m_center[m_ghostIndex]; drawDot(c, r, color); } glPopMatrix(); }
void drawSierpinski(GLIntPoint* points, int length){ int index = random() % length; GLIntPoint point = points[index]; drawDot(point); for(int i =0; i<10000; i++){ index = random() % length; point.x = (point.x + points[index].x)/2; point.y = (point.y + points[index].y)/2; drawDot(point); } }
bool PowerUp::init(GameWorld* instance) { if(!CCDrawNode::init()) return false; game_world_ = instance; time_left_ = MAX_POWERUP_WAIT_ON_SCREEN / 2 + CCRANDOM_0_1() * MAX_POWERUP_WAIT_ON_SCREEN / 2; speed_ = CCPoint(CCRANDOM_MINUS1_1() * 2, CCRANDOM_MINUS1_1() * 2); drawDot(CCPointZero, POWERUP_ICON_OUTER_RADIUS, ccc4f(0.73725f, 0.5451f, 0, 1)); drawDot(CCPointZero, POWERUP_ICON_OUTER_RADIUS - 3, ccc4f(0, 0, 0, 1)); setScale(0.0f); return true; }
void sierpin(GLfloatPoint *corner) { int index = rand()%3; GLfloatPoint point = corner[index]; drawDot(point.x,point.y); int i; for(i=0;i<50000;i++) { index = rand()%3; point.x=(point.x + corner[index].x)/2; point.y=(point.y + corner[index].y)/2; drawDot(point.x,point.y); } SOIL_save_screenshot("output/sierpinMouse.bmp",SOIL_SAVE_TYPE_BMP,0,0,640,600); }
void draw() { drawPacman(pacman.row, pacman.col); drawString4(SCREENHEIGHT-TEXT_HEIGHT, 0, string, WHITEINDEX); for (int i = 0; i < NUMDOTS; i++) drawDot(i); }
void myMouse(int button, int state, int x, int y) { // If left button was clicked if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { // Store where the user clicked, note Y is backwards. abc[NUMPOINTS].setxy((float)x,(float)(SCREEN_HEIGHT - y)); NUMPOINTS++; // Draw the red dot. drawDot(x, SCREEN_HEIGHT - y); // If 3 points are drawn do the curve. if(NUMPOINTS == 4) { glColor3f(0,1.0,0); drawLine(abc[0], abc[1]); drawLine(abc[1], abc[2]); drawLine(abc[2], abc[3]); glColor3f(1.0,1.0,1.0); //This line is where we specify everything //the first parameter is which style: // 1 = Sampling // 2 = Forward Differentiation // 3 = Subdivision // and the last parameter is how many subdivisions drawBezierLine(3,abc[0], abc[1], abc[2], abc[3], 10000); NUMPOINTS = 0; } } }
void myMouse(int button, int state, int x, int y) { // If left button was clicked if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { // Store where the user clicked, note Y is backwards. abc[NUMPOINTS].setxy((float)x,(float)(SCREEN_HEIGHT - y)); NUMPOINTS++; // Draw the red dot. drawDot(x, SCREEN_HEIGHT - y); // If 3 points are drawn do the curve. if(NUMPOINTS == 3) { glColor3f(1.0,1.0,1.0); // Draw two legs of the triangle drawLine(abc[0], abc[1]); drawLine(abc[1], abc[2]); point POld = abc[0]; /* Draw each segment of the curve. Make t increment in smaller amounts for a more detailed curve. */ for(double t = 0.0;t <= 1.0; t += 0.1) { point P = drawBezier(abc[0], abc[1], abc[2], t); drawLine(POld, P); POld = P; } glColor3f(1.0,0.0,0.0); NUMPOINTS = 0; } } }
void MapView::valuePlanetDrawer(QPainter &painter, const Planet *planet, const QPoint &pos) { long seen = planet->SeenBy(player); if(seen == 0) { noInfoPlanetDrawer(painter, planet, pos); return; } if((seen & SEEN_PLANETHAB) == 0) { drawDot(painter, pos, Qt::white); return; } const int diameter = 10; const int diameter2 = 8; int hab = player->HabFactor(planet); QPainterPath path, patho; if(hab > 0) { path.addEllipse(pos, diameter * hab / 100, diameter * hab / 100); painter.fillPath(path, QBrush(Qt::darkGreen)); patho.addEllipse(pos, diameter2 * hab / 100, diameter2 * hab / 100); painter.fillPath(patho, QBrush(Qt::green)); } else { path.addEllipse(pos, diameter * hab / 100, diameter * hab / 100); painter.fillPath(path, QBrush(Qt::darkRed)); patho.addEllipse(pos, diameter2 * hab / 100, diameter2 * hab / 100); painter.fillPath(patho, QBrush(Qt::red)); } }
void initialize() { drawTitle(); setPalette(Pacman_palette, PACMAN_PALETTE_SIZE, PACMAN_PALETTE_OFFSET); setPalette(ghost_palette, PACMAN_PALETTE_SIZE, GHOST_PALETTE_OFFSET); DOT emptyDot; emptyDot.rect.row = 0; emptyDot.rect.col = 0; emptyDot.rect.height = 0; emptyDot.rect.width = 0; emptyDot.del = 0; emptyDot.isGhost = 0; for (int i = 0; i < NUMDOTS; i++) dots[i] = oldDots[i] = emptyDot; ghostFrequency = 32; score = 0; // Make Pacman and his shadow pacman.height = pacman.width = 16; pacman.row = (SCREENHEIGHT-pacman.height-TEXT_HEIGHT)/2; pacman.col = 0; // Make dots for (int i = 0; i < NUMDOTS; i++) { initDot(i); drawDot(i); } oldPacman = pacman; for (int i = 0; i < NUMDOTS; i++) oldDots[i] = dots[i]; }
void FocusLayer::addCircle(const Vec2& pos, float radius, onTouchCallback callback) { auto node = DrawNode::create(); node->setPosition(pos); node->drawDot(Vec2::ZERO, radius, Color4F(1, 1, 1, 1)); node->setTag(_circleIdx); addChild(node); node->retain(); BlendFunc blend; blend.src = GL_DST_COLOR; blend.dst = GL_ONE; node->setBlendFunc(blend); circleData data; data._pos = pos; data._radius = radius; data._callback = callback; data._node = node; _circleList.insert(std::make_pair(_circleIdx++, data)); node->setScale(0); node->runAction(EaseBackOut::create(ScaleTo::create(0.4f, 1.0f))); }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object auto closeItem = MenuItemImage::create( "CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 , origin.y + closeItem->getContentSize().height/2)); // create menu, it's an autorelease object auto menu = Menu::create(closeItem, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); _winSize = Director::getInstance()->getWinSize(); auto drawNode = DrawNode::create(); drawNode->drawSegment(Point(0, _winSize.height/2), Point(_winSize.width, _winSize.height/2), 1, Color4F(1.0f, 1.0f, 1.0f, 1.0f)); drawNode->drawSegment(Point(_winSize.width/2, _winSize.height), Point(_winSize.width/2, 0), 1, Color4F(1.0f, 1.0f, 1.0f, 1.0f)); Point centerPoint = Point(_winSize.width/2, _winSize.height/2); float R = 128; std::vector<Color4F> colors = { Color4F(1.0f, 0.0f, 0.0f, 0.6f), Color4F(0.0f, 1.0f, 0.0f, 0.6f), Color4F(0.0f, 0.0f, 1.0f, 0.6f), Color4F(0.5f, 0.5f, 0.0f, 0.6f), Color4F(0.0f, 0.5f, 0.5f, 0.6f), Color4F(0.5f, 0.5f, 0.5f, 0.5f), }; for (float angles = 0, i = 0; angles < 360; angles += 60, i++) { float x = R * cos(CC_DEGREES_TO_RADIANS(angles)); float y = R * sin(CC_DEGREES_TO_RADIANS(angles)); drawNode->drawDot(centerPoint + Point(x, y), R/2, colors[i]); auto label = LabelTTF::create("angle:" + std::to_string((int)(angles)), "Arial", 24); label->setPosition(centerPoint + Point(x, y)); drawNode->addChild(label); } this->addChild(drawNode, 1, 1); // auto label = LabelTTF::create("angle(000)", "Arial", 48); // label->setColor(Color3B::WHITE); // label->setTag(TAG_LABEL); // this->addChild(label, TAG_LABEL, TAG_LABEL); // label->setPosition(Point(winSize.width/2, winSize.height/2)); // enableTouchEvent(true); return true; }
void sierpinski_render() { glClear(GL_COLOR_BUFFER_BIT); GLPoints T[3] = { { 10, 10 }, { 600, 10 }, { 300, 600 } }; int index = rand() % 3; GLPoints point = T[index]; drawDot(point.x, point.y); for (int i = 0; i < 55000; i++) { index = rand() % 3; point.x = (point.x + T[index].x) / 2; point.y = (point.y + T[index].y) / 2; drawDot(point.x, point.y); } glFlush(); }
void ShiftTraceTool::drawCurve() { if (m_curveStatus == NoCurve) return; double r = 4 * sqrt(tglGetPixelSize2()); double u = getPixelSize(); if (m_curveStatus == TwoPointsCurve) { TPixel32 color = m_highlightedGadget == 1000 ? TPixel32(200, 100, 100) : TPixel32::White; drawDot(m_p0, r, color); glColor3d(0.2, 0.2, 0.2); tglDrawSegment(m_p0, m_p1); drawDot(m_p1, r, TPixel32::Red); } else if (m_curveStatus == ThreePointsCurve) { TPixel32 color = m_highlightedGadget == 1000 ? TPixel32(200, 100, 100) : TPixel32::White; drawDot(m_p0, r, color); color = m_highlightedGadget == 1001 ? TPixel32(200, 100, 100) : TPixel32::White; drawDot(m_p1, r, color); glColor3d(0.2, 0.2, 0.2); TPointD center; if (circumCenter(center, m_p0, m_p1, m_p2)) { double radius = norm(center - m_p1); glBegin(GL_LINE_STRIP); int n = 100; for (int i = 0; i < n; i++) { double t = (double)i / n; TPointD p = (1 - t) * m_p0 + t * m_p2; p = center + radius * normalize(p - center); tglVertex(p); } for (int i = 0; i < n; i++) { double t = (double)i / n; TPointD p = (1 - t) * m_p2 + t * m_p1; p = center + radius * normalize(p - center); tglVertex(p); } glEnd(); } else { tglDrawSegment(m_p0, m_p1); } color = m_highlightedGadget == 1002 ? TPixel32(200, 100, 100) : TPixel32::White; drawDot(m_p2, r, color); } }
void sierpin(void) { glClear(GL_COLOR_BUFFER_BIT); GLfloatPoint T[3] = {{10,10},{600,10},{300,600}}; int index = rand()%3; GLfloatPoint point = T[index]; drawDot(point.x,point.y); int i; for(i=0;i<50000;i++) { index = rand()%3; point.x=(point.x + T[index].x)/2; point.y=(point.y + T[index].y)/2; drawDot(point.x,point.y); } SOIL_save_screenshot("output/sierpin.bmp",SOIL_SAVE_TYPE_BMP,0,0,640,600); glFlush(); }
void Selector::drawAtPosition() { glPushMatrix(); glTranslated(column*COL_SPACING, 0, row*ROW_SPACING); draw(); glPopMatrix(); glPushMatrix(); glTranslated(dotX*COL_SPACING, 0, dotY*ROW_SPACING); drawDot(); glPopMatrix(); drawArrow(); }
/** Displays the Sierpinski Triangle @param corner1, corner2, corner 3 The three points to form a triangle @param seed A point to be used as a seed to generate the triangle */ void sierpinskiRender(GLintPoint corner1, GLintPoint corner2, GLintPoint corner3, GLintPoint seed) { glClear(GL_COLOR_BUFFER_BIT); // clear the screen GLintPoint T[3] = { { corner1.x, corner1.y }, { corner2.x, corner2.y }, { corner3.x, corner3.y } }; // vertices of the triangle for (int i = 0; i < numberDots; i++) { int index = random(3); GLint x = (seed.x + T[index].x) / 2; // generate midpoint between randomly chosen vertice and seed GLint y = (seed.y + T[index].y) / 2; drawDot(x, y); seed = { x, y }; // the seed becomes the midpoint } glFlush(); // draw the new triangle }
void GraphView::drawRect(KDContext * ctx, KDRect rect) const { ctx->fillRect(rect, KDColorWhite); drawGrid(ctx, rect); drawAxes(ctx, rect, Axis::Horizontal); drawAxes(ctx, rect, Axis::Vertical); drawLabels(ctx, rect, Axis::Horizontal, true); drawLabels(ctx, rect, Axis::Vertical, true); for (int series = 0; series < Store::k_numberOfSeries; series++) { if (!m_store->seriesIsEmpty(series)) { KDColor color = Palette::DataColor[series]; float regressionParameters[2] = {(float)m_store->slope(series), (float)m_store->yIntercept(series)}; drawCurve(ctx, rect, [](float abscissa, void * model, void * context) { float * params = (float *)model; return params[0]*abscissa+params[1]; }, regressionParameters, nullptr, color); for (int index = 0; index < m_store->numberOfPairsOfSeries(series); index++) { drawDot(ctx, rect, m_store->get(series, 0, index), m_store->get(series, 1, index), color); } drawDot(ctx, rect, m_store->meanOfColumn(series, 0), m_store->meanOfColumn(series, 1), color, true); drawDot(ctx, rect, m_store->meanOfColumn(series, 0), m_store->meanOfColumn(series, 1), KDColorWhite); } } }
void myMouse(int button, int state, int x, int y){ const int size = 3; static int clickCount = 0; static GLIntPoint points[size]; if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN && clickCount < size){ points[clickCount].x = x; points[clickCount].y = HEIGHT - y; drawDot(points[clickCount]); clickCount++; if(clickCount == size){ drawSierpinski(points,size); } } }
void MapView::populationPlanetDrawer(QPainter &painter, const Planet *planet, const QPoint &pos) { long seen = planet->SeenBy(player); if(seen == 0) { noInfoPlanetDrawer(painter, planet, pos); return; } if((seen & SEEN_PLANETPOP) == 0) { drawDot(painter, pos, Qt::white); return; } int hab = player->HabFactor(planet); fillCircle(painter, pos, 2 + (8 * planet->GetDisplayPop()) / planet->GetMaxPop(), hab > 0 ? Qt::green : Qt::red); }
void MapView::noInfoPlanetDrawer(QPainter &painter, const Planet*, const QPoint &pos) { drawDot(painter, pos, Qt::gray); }
static int read_frame_small(void) { struct v4l2_buffer buf; unsigned int i; CLEAR(buf); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; if (ioctl(fd, VIDIOC_DQBUF, &buf) < 0) { printf("ioctl() VIDIOC_DQBUF failed.\n"); return -1; } assert(buf.index < n_buffers); printf ("Buffer: index = %d\n", buf.index); void* data_pointer = buffers[buf.index].start; /* two loops = 13.5ms util_timestamp_int(); for(i = 0; i < image_size/2; i++) { *((unsigned char*)data_pointer + i) = ( *((unsigned char*)data_pointer + (2*i)) + *((unsigned char*)data_pointer + (2*i + 1)))/2; } for(i = 0; i < image_size/4; i++) { unsigned int ind = i+320*(int)(i/320); *((unsigned char*)data_pointer + i) = ( *((unsigned char*)data_pointer + (ind)) + *((unsigned char*)data_pointer + (ind + 320)))/2; }*/ // One loop = 6.8ms //util_timestamp_int(); /*for(i = 0; i < image_size/4; i++) { // (x,y) = AVERAGE[(2x,4y)+(2x+1,4y)+(2x,4y+1)+(2x+1,4y+1)] // i = x + 640y // x = i%640, y = i/640 unsigned int fact = 2*(i%640) + 2560*((int)(i/640)); *((unsigned char*)data_pointer + i) = ( *((unsigned char*)data_pointer + (fact)) + *((unsigned char*)data_pointer + (fact + 1)) + *((unsigned char*)data_pointer + (fact + 640)) + *((unsigned char*)data_pointer + (fact + 641)))/4; }*/ /* NEON Optimised = XX.Xms util_timestamp_int(); struct buffer* output_image = NULL; output_image = calloc(1, sizeof(*output_image)); output_image[0].length = buf.length; output_image[0].start = mmap(NULL, buf.length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, buf.m.offset); unsigned char* output_image_pointer = (char*) output_image[0].start; halfsize(output_image_pointer, (unsigned char*)data_pointer, 640, 480); */ //printf("Time to downsample frame = %d microseconds\n", util_timestamp_int()); //printf("Y = %i U = %i V = %i\n", *((unsigned char*)data_pointer + 38560), *((unsigned char*)data_pointer + 86480), *((unsigned char*)data_pointer + 105680)); /**((unsigned char*)data_pointer + 38560) = 0; *((unsigned char*)data_pointer + 86480) = 0; *((unsigned char*)data_pointer + 105680) = 0;*/ //findBlob(data_pointer, 91, 100, 130, 136, 160, 240); void* greyscale_pointer = malloc(WIDTH*HEIGHT*sizeof(char)); convert2grey(greyscale_pointer, data_pointer); int numcorners; //util_timestamp_int(); /* FAST9 b=40: [email protected] FAST10 b=35: [email protected] FAST11 b=30: [email protected] FAST12 b=27: [email protected] */ xy* corners = fast12_detect_nonmax((const byte*) greyscale_pointer, WIDTH, HEIGHT, WIDTH, 27, (int*)&numcorners); printf("Corners found = %i\n", numcorners); //printf("Time to find FAST corners = %d microseconds\n", util_timestamp_int()); unsigned int j; for (j=0; j<numcorners; j++) { drawDot(data_pointer, corners[j].x, corners[j].y, 6); } fwrite(/*(void*)output_image_pointer*/data_pointer, image_size, 1, file_fd); if (ioctl(fd, VIDIOC_QBUF, &buf) < 0) { printf("ioctl() VIDIOC_QBUF failed.\n"); return -1; } return 1; }
void createTextures() { //set color of the cube for (int k=0; k<6; k++) { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { sides[k][i][j][0] = 0xFF; sides[k][i][j][1] = 0xFF; sides[k][i][j][2] = 0xFF; sides[k][i][j][3] = 0xFF; } } } //one drawDot(0, 4, 4); //two drawDot(1, 2, 2); drawDot(1, 6, 6); //three drawDot(2, 2, 2); drawDot(2, 4, 4); drawDot(2, 6, 6); //four drawDot(3, 2, 2); drawDot(3, 6, 2); drawDot(3, 6, 6); drawDot(3, 2, 6); //five drawDot(4, 2, 2); drawDot(4, 6, 2); drawDot(4, 6, 6); drawDot(4, 2, 6); drawDot(4, 4, 4); //six drawDot(5, 2, 2); drawDot(5, 4, 2); drawDot(5, 6, 2); drawDot(5, 2, 6); drawDot(5, 4, 6); drawDot(5, 6, 6); }
void Block::update(float delta) { // children' tags: // 0 - circle // 1, 2, 3, 4 - squares if (getChildByTag(0) == nullptr) { auto d = DrawNode::create(); d->drawDot(Point(Block::size/2, Block::size/2), Block::size/2, _color); addChild(d, 0, 0); } auto x = getPosition().x; auto y = getPosition().y; auto s = Block::size; /* // top left if ((! neighbor[0][1] || neighbor[0][1]->getType() != BLOCK_AIR) || (! neighbor[1][0] || neighbor[1][0]->getType() != BLOCK_AIR)) { if (! getChildByTag(1)) { auto d = DrawNode::create(); Point b[] = {Point(0,s),Point(s/2,s),Point(s/2,s/2),Point(0,s/2)}; d->drawPolygon(b, 4, _color, 0, _color); addChild(d, 0, 1); } } else { if (getChildByTag(1)) removeChildByTag(1); } // top right if ((! neighbor[0][1] || neighbor[0][1]->getType() != BLOCK_AIR) || (! neighbor[1][2] || neighbor[1][2]->getType() != BLOCK_AIR)) { if (! getChildByTag(2)) { auto d = DrawNode::create(); Point b[] = {Point(s/2,s),Point(s,s),Point(s,s/2),Point(s/2,s/2)}; d->drawPolygon(b, 4, _color, 0, _color); addChild(d, 0, 1); } } else { if (getChildByTag(2)) removeChildByTag(2); } // down left if ((! neighbor[1][0] || neighbor[1][0]->getType() != BLOCK_AIR) || (! neighbor[2][1] || neighbor[2][1]->getType() != BLOCK_AIR)) { if (! getChildByTag(3)) { auto d = DrawNode::create(); Point b[] = {Point(0,s/2),Point(s/2,s/2),Point(s/2,0),Point(0,0)}; d->drawPolygon(b, 4, _color, 0, _color); addChild(d, 0, 1); } } else { if (getChildByTag(3)) removeChildByTag(3); } // down right if ((! neighbor[2][1] || neighbor[2][1]->getType() != BLOCK_AIR) || (! neighbor[1][2] || neighbor[1][2]->getType() != BLOCK_AIR)) { if (! getChildByTag(4)) { auto d = DrawNode::create(); Point b[] = {Point(s/2,s/2),Point(s,s/2),Point(s,0),Point(s/2,0)}; d->drawPolygon(b, 4, _color, 0, _color); addChild(d, 0, 1); } } else { if (getChildByTag(4)) removeChildByTag(4); }*/ }
bool MainScene::init(){ if(!Layer::init()){ return false; } auto winSize = Director::getInstance()->getWinSize(); //TJA読み込み Tja tja = Tja(); tja.loadTja(); _noteTimes = tja.getNoteTimes(); auto background = Sprite::create("background.png"); background->setPosition(Vec2(winSize.width / 2.0, winSize.height / 2.0)); this->addChild(background); auto scoreLabel = Label::createWithSystemFont(StringUtils::toString(_score), "Marker Felt", FONT_SIZE); scoreLabel->enableShadow(Color4B::BLACK, Size(0.5, 0.5), 3); scoreLabel->enableOutline(Color4B::BLACK, 1.5); scoreLabel->setPosition(Vec2(winSize.width / 2 * 1.5, winSize.height - 40)); this->setScoreLabel(scoreLabel); this->addChild(scoreLabel); auto scoreLabelHeader = Label::createWithSystemFont("SCORE", "Marker Felt", FONT_SIZE); scoreLabelHeader->setPosition(Vec2(winSize.width / 2 * 1.5, winSize.height - 20)); this->addChild(scoreLabelHeader); int second = static_cast<int>(_second); auto secondLabel = Label::createWithSystemFont(StringUtils::toString(second), "Marker Felt", FONT_SIZE); secondLabel->setPosition(Vec2(winSize.width / 2, winSize.height - 40)); this->setSecondLabel(secondLabel); this->addChild(secondLabel); auto secondLabelHeader = Label::createWithSystemFont("TIME", "Marker Felt", FONT_SIZE); secondLabelHeader->setPosition(Vec2(winSize.width / 2, winSize.height - 20)); this->addChild(secondLabelHeader); //当たり判定 auto hitDetection = DrawNode::create(); hitDetection->drawDot(INIT_PLAYER_POSITION, 10.0f, Color4F(1.0f, 6.0f, 5.0f, 1.0f)); this->addChild(hitDetection); auto listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = [this](Touch *touch, Event *event){ this->setTouchLocation(touch->getLocation()); return true; }; listener->onTouchMoved = [this](Touch *touch, Event *event){ SwipeDirection swipeDirection = this->getSwipeDirection(touch); if(swipeDirection != SwipeDirection::NONE){ // if(swipeDirection == SwipeDirection::RIGHT){ // if(_isSwipeTimeRight <= 0){ // this->initSwipeTime(); // this->setIsSwipeTimeRight(SWIPE_WAIT_TIME); // //音 // CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("dong.mp3"); // //エフェクト // auto explosion = ParticleFire::create(); // explosion->setPosition(INIT_PLAYER_POSITION); // explosion->setDuration(0.0001); // this->addChild(explosion); // explosion->setAutoRemoveOnFinish(true); // 表示が終わったら自分を親から削除! // } // } // else if(swipeDirection == SwipeDirection::LEFT){ // if(_isSwipeTimeLeft <= 0){ // this->initSwipeTime(); // this->setIsSwipeTimeLeft(SWIPE_WAIT_TIME); // //音 // CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("dong.mp3"); // //エフェクト // auto explosion = ParticleFire::create(); // explosion->setPosition(INIT_PLAYER_POSITION); // explosion->setDuration(0.0001); // explosion->setAutoRemoveOnFinish(true); // 表示が終わったら自分を親から削除! // this->addChild(explosion); // } // } if(swipeDirection == SwipeDirection::UP){ if(_isSwipeTimeUp <= 0){ this->initSwipeTime(); this->setIsSwipeTimeUp(SWIPE_WAIT_TIME); //音 CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("dong.mp3"); //エフェクト auto explosion = ParticleFire::create(); explosion->setPosition(INIT_PLAYER_POSITION); explosion->setDuration(0.0001); explosion->setAutoRemoveOnFinish(true); // 表示が終わったら自分を親から削除! this->addChild(explosion); } } else if(swipeDirection == SwipeDirection::DOWN){ if(_isSwipeTimeDown <= 0){ this->initSwipeTime(); this->setIsSwipeTimeDown(SWIPE_WAIT_TIME); //音 CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("dong.mp3"); //エフェクト auto explosion = ParticleFire::create(); explosion->setPosition(INIT_PLAYER_POSITION); explosion->setDuration(0.0001); explosion->setAutoRemoveOnFinish(true); // 表示が終わったら自分を親から削除! this->addChild(explosion); } } this->setTouchLocation(touch->getLocation()); } }; Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this); //this->scheduleUpdate(); schedule(schedule_selector(MainScene::test), SFRAME_RATE); return true; }
void drawPendulum(pstate *states, int states_len) { int left_loopings = 0, right_loopings = 0; int green_color = COLOR_GREEN; int red_color = COLOR_RED; int blue_color = COLOR_BLUE; // clear surface if (whitebg) { generic_surface_fill(sf, COLOR_WHITE); green_color = 0xff009600; red_color = 0xff960000; blue_color = 0xff000096; } else generic_surface_fill(sf, COLOR_BLACK); // precompute scaling double maxpendlength = l1 + l2b; // this scale is in pixels per meter double scale = (double)(sf->width < sf->height ? sf->width : sf->height) / 2.0 * (4.0/5.0) / maxpendlength; // draw center (main axis of pendulum) drawDot(sf, sf->width/2, sf->height/2, red_color); // draw maximum reach of common axis and outer pendulum drawCircle(sf, sf->width/2, sf->height/2, scale*l1, red_color); drawCircle(sf, sf->width/2, sf->height/2, scale*(l1+l2b), red_color); // draw data int last_xpos, last_ypos, xpos, ypos; int last_section, cur_section; double xpos_, ypos_; for (int i = 0; i < states_len; i++) { pstate *s = &states[i]; pstateToCartesianEnd(s, &xpos_, &ypos_); xpos = (int)(xpos_ * scale); ypos = (int)(ypos_ * scale); xpos += sf->width/2; ypos += sf->height/2; cur_section = s->phi2/(M_PI/2); if (cur_section < 0) cur_section *= -1; cur_section = cur_section%4; assert(cur_section >= 0 && cur_section < 4); if (i != 0) { // the first point does not have a previous one // to which we could draw a line, so ignore it //fprintf(stderr, "(%d|%d)->(%d|%d)\n", last_xpos, last_ypos, xpos, ypos); int color = green_color; if (last_section == 1/*upper left*/ && cur_section == 2/*upper right*/) { color = red_color; right_loopings++; } if (last_section == 2/*upper right*/ && cur_section == 1/*upper left*/) { color = blue_color; left_loopings++; } if (show_normal_lines || color != green_color) { drawBresenhamLine(sf, last_xpos, last_ypos, xpos, ypos, color); } } last_xpos = xpos; last_ypos = ypos; last_section = cur_section; } fprintf(stderr, "pendulum rendered. %d loopings to the left, %d loopings to the right.\n", left_loopings, right_loopings); }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object auto closeItem = MenuItemImage::create( "CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 , origin.y + closeItem->getContentSize().height/2)); // create menu, it's an autorelease object auto menu = Menu::create(closeItem, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24); // position the label on the center of the screen label->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - label->getContentSize().height)); // add the label as a child to this layer this->addChild(label, 1); // add "HelloWorld" splash screen" auto sprite = Sprite::create("HelloWorld.png"); // position the sprite on the center of the screen sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); sprite->runAction(MoveTo::create(3.0, Vec2(100, 100))); // add the sprite as a child to this layer this->addChild(sprite, 0); auto draw = DrawNode::create(); draw->drawDot(Vec2(visibleSize/2), 10.0f, Color4F::WHITE); this->addChild(draw); // イベントリスナー作成 auto listener = EventListenerTouchOneByOne::create(); // シングルタッチ // イベントを飲み込むかどうか listener->setSwallowTouches(true); // タッチ開始 listener->onTouchBegan = [](Touch* touch, Event* event){ // タッチ開始時の処理を書く auto location = touch->getLocation(); CCLOG("x=%f, y=%f", location.x, location.y); return true; }; // イベントリスナーを登録 this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this); // 定期的に実行するタイマー this->schedule([](float dt){CCLOG("update");}, 5.0f, "Update"); // 一度だけ実行するタイマー this->scheduleOnce([](float dt){CCLOG("once");}, 3.0f, "Once"); return true; }
void ShapeEllipse::draw() { if (this->isSolid) { int x = 0, y = this->yrad; unsigned int width = 1; long a2 = (long)this->xrad * this->xrad, b2 = (long)this->yrad * this->yrad; long crit1 = -(a2 / 4 + this->xrad % 2 + b2); long crit2 = -(b2 / 4 + this->yrad % 2 + a2); long crit3 = -(b2 / 4 + this->yrad % 2); long t = -a2 * y; long dxt = 2 * b2 * x, dyt = -2 * a2 * y; long d2xt = 2 * b2, d2yt = 2 * a2; while (y >= 0 && x <= this->xrad) { if (t + b2*x <= crit1 || t + a2*y <= crit3) { incx(); width += 2; } else if (t - a2*y > crit2) { drawBox(this->x - x, this->y - y, width, 1, color, ctype); if (y != 0) drawBox(this->x - x, this->y + y, width, 1, color, ctype); incy(); } else { drawBox(this->x - x, this->y - y, width, 1, color, ctype); if (y != 0) drawBox(this->x - x, this->y + y, width, 1, color, ctype); incx(); incy(); width += 2; } } if (this->yrad == 0) drawBox(this->x - this->xrad, this->y, 2*this->xrad + 1, 1, color, ctype); } else { int x = this->xrad; int y = 0; int twoAsquare = 2 * this->xrad * this->xrad; int twoBsquare = 2 * this->yrad * this->yrad; int xchange = this->yrad * this->yrad * (1 - 2 * this->xrad); int ychange = this->xrad * this->xrad; int ellipseerror = 0; int stoppingX = twoBsquare * this->xrad; int stoppingY = 0; while (stoppingX >= stoppingY) { drawDot(this->x + x, this->y + y, color, ctype); drawDot(this->x - x, this->y + y, color, ctype); drawDot(this->x - x, this->y - y, color, ctype); drawDot(this->x + x, this->y - y, color, ctype); y++; stoppingY += twoAsquare; ellipseerror += ychange; ychange += twoAsquare; if ((2* ellipseerror + xchange) > 0) { x--; stoppingX -= twoBsquare; ellipseerror += xchange; xchange += twoBsquare; } } x = 0; y = this->yrad; xchange = this->yrad * this->yrad; ychange = this->xrad * this->xrad * (1 - 2 * this->yrad); ellipseerror = 0; stoppingX = 0; stoppingY = twoAsquare * this->yrad; while (stoppingX <= stoppingY) { drawDot(this->x + x, this->y + y, color, ctype); drawDot(this->x - x, this->y + y, color, ctype); drawDot(this->x - x, this->y - y, color, ctype); drawDot(this->x + x, this->y - y, color, ctype); x++; stoppingX += twoBsquare; ellipseerror += xchange; xchange += twoBsquare; if ((2* ellipseerror + ychange) > 0) { y--; stoppingY -= twoAsquare; ellipseerror += ychange; ychange += twoAsquare; } } } }
void GLAnalyzer2::paintGL() { // Compute the dT since the last call to paintGL and update timings timeval tv; gettimeofday(&tv, nullptr); double currentTime = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0; show.dT = currentTime - show.timeStamp; show.timeStamp = currentTime; // Clear frame glClear(GL_COLOR_BUFFER_BIT); // Shitch to MODEL matrix and reset it to default glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Fade the previous drawings. /* glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glBegin( GL_TRIANGLE_STRIP ); glColor4f( 0.0f, 0.0f, 0.0f, 0.2f ); glVertex2f( 10.0f, 10.0f ); glVertex2f( -10.0f, 10.0f ); glVertex2f( 10.0f, -10.0f ); glVertex2f( -10.0f, -10.0f ); glEnd();*/ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); float alphaN = show.paused ? 0.2 : (frame.energy / 10.0), alphaP = show.paused ? 1.0 : (1 - frame.energy / 20.0); if (alphaN > 1.0) alphaN = 1.0; if (alphaP < 0.1) alphaP = 0.1; glBindTexture(GL_TEXTURE_2D, w2Texture); setTextureMatrix(show.rotDegrees, 0.707 * alphaP); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(1.0, 1.0); glVertex2f(10.0f, 10.0f); glTexCoord2f(0.0, 1.0); glVertex2f(-10.0f, 10.0f); glTexCoord2f(1.0, 0.0); glVertex2f(10.0f, -10.0f); glTexCoord2f(0.0, 0.0); glVertex2f(-10.0f, -10.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, w1Texture); setTextureMatrix(-show.rotDegrees * 2, 0.707); glColor4f(1.0f, 1.0f, 1.0f, alphaN); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(1.0, 1.0); glVertex2f(10.0f, 10.0f); glTexCoord2f(0.0, 1.0); glVertex2f(-10.0f, 10.0f); glTexCoord2f(1.0, 0.0); glVertex2f(10.0f, -10.0f); glTexCoord2f(0.0, 0.0); glVertex2f(-10.0f, -10.0f); glEnd(); setTextureMatrix(0.0, 0.0); glDisable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE); // Here begins the real draw loop // some updates to the show show.rotDegrees += 40.0 * show.dT; frame.rotDegrees += 80.0 * show.dT; // handle the 'pause' status if (show.paused) { if (show.pauseTimer > 0.5) { if (show.pauseTimer > 0.6) show.pauseTimer -= 0.6; drawFullDot(0.0f, 0.4f, 0.8f, 1.0f); drawFullDot(0.0f, 0.4f, 0.8f, 1.0f); } show.pauseTimer += show.dT; return; } if (dotTexture) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, dotTexture); } else glDisable(GL_TEXTURE_2D); glLoadIdentity(); // glRotatef( -frame.rotDegrees, 0,0,1 ); glBegin(GL_QUADS); // Particle * particle = particleList.first(); // for (; particle; particle = particleList.next()) { glColor4f(0.0f, 1.0f, 0.0f, 1.0f); drawDot(0, 0, kMax(10.0, (10.0 * frame.energy))); glColor4f(1.0f, 0.0f, 0.0f, 1.0f); drawDot(6, 0, kMax(10.0, (5.0 * frame.energy))); glColor4f(0.0f, 0.4f, 1.0f, 1.0f); drawDot(-6, 0, kMax(10.0, (5.0 * frame.energy))); } glEnd(); }