示例#1
0
void FractalCreator::run(string filename)
{
    addZoom(Zoom(_width/2, _height/2, 4.0/_width));
    addZoom(Zoom(295, _height - 202, 0.1));
    addZoom(Zoom(312, _height - 304, 0.1));

    calculateIteration();
    calculateRangeTotal();
    drawFractal();
    writeBitmap(filename);
}
void ofx2DFormMapping::setZoomFactor(int factor) {

	int old_zoom_factor = zoom_factor;

	zoom_factor += factor;
	if(zoom_factor < 0)
		zoom_factor = 0;

	ofPoint zoom_point_old = zoom_point;

	ofPoint tmp_zoom_point;
	tmp_zoom_point.x = ofGetMouseX() - mapping_rect_dst.x - zoom_point_offset.x;
	tmp_zoom_point.y = ofGetMouseY() - mapping_rect_dst.y - zoom_point_offset.y;

	ofVec2f diff = tmp_zoom_point - zoom_point_old;

	if(old_zoom_factor == 0) {
		diff = ofPoint(0,0);
		zoom_point_offset = ofPoint(0,0);
		zoom_point_old = tmp_zoom_point;
	}

	zoom_point = zoom_point_old + removeZoom(diff);
	zoom_point_offset += tmp_zoom_point - zoom_point;
	zoom_point_scaled = addZoom(zoom_point);

}
ofPoint ofx2DFormMapping::addZoomRelativeOfDstRect(ofPoint p) {
	return addZoom(p-mapping_rect_dst.getPosition())+mapping_rect_dst.getPosition()+translation_dst;
}
void ofx2DFormMapping::draw(bool show_source) {

	ofSetColor(42);
	ofFill();
	ofDrawRectangle(this->getPosition().x, this->getPosition().y, this->getWidth(), this->getHeight()-2);

	ofxPanel::draw();

	if(show_source) {
		//ofDrawRectangle(mapping_rect_src);
		if(source_bg) {
			ofSetColor(255,60);
			source_bg->draw(
						mapping_rect_src.x,
						mapping_rect_src.y,
						mapping_rect_src.width,
						mapping_rect_src.height);
		}
		else {
			ofSetColor(0,0,0,100);
			ofFill();
			ofDrawRectangle(mapping_rect_src);
		}
	}

	ofEnableAlphaBlending();

	ofSetLineWidth(2);

	//draw dst

	if(!direct_edit) {
		mapping_front.begin();
		ofClear(0,0,0,0);
		ofTranslate(mapping_margin, mapping_margin);

		ofPushMatrix();
		ofTranslate(-mapping_rect_dst.getPosition());

		//ZOOM TRANSLATION

		translation_dst = zoom_point-zoom_point_scaled+zoom_point_offset;
		if(translation_dst.x > 0) translation_dst.x = 0;
		if(translation_dst.y > 0) translation_dst.y = 0;
		if(translation_dst.x < -addZoom(mapping_rect_dst.getWidth())+mapping_rect_dst.getWidth())
			translation_dst.x = -addZoom(mapping_rect_dst.getWidth())+mapping_rect_dst.getWidth();
		if(translation_dst.y < -addZoom(mapping_rect_dst.getHeight())+mapping_rect_dst.getHeight())
			translation_dst.y = -addZoom(mapping_rect_dst.getHeight())+mapping_rect_dst.getHeight();
		ofTranslate(translation_dst);

		ofSetColor(255,160);
		mapping_bg->draw(
					mapping_rect_dst.x,
					mapping_rect_dst.y,
					addZoom(mapping_rect_dst.width),
					addZoom(mapping_rect_dst.height));

	}

	for (unsigned int i = 0; i < shapes.size(); i++) {

//        //draw dst rectangles

//        ofNoFill();
//        ofSetColor(80,130,150);

//        ofBeginShape();
//        for(unsigned int j = 0; j < shapes[i].dst.size(); j++) {
//            ofVertex(shapes[i].dst[j]);
//        }
//        ofEndShape(true);

		//draw shape lines and fillings

		for(int j = 0; j < 2; j++) {
			if(j == 0) {
				ofFill();
				ofSetColor(shapes[i].color,40);
			}
			else {
				ofNoFill();
				if(direct_edit) {
					ofSetColor(255);
				}
				else {
					ofSetColor(shapes[i].color,255);
				}

			}
			if(!(j == 0 && direct_edit)) {
				ofBeginShape();
				for(unsigned int j = 0; j < shapes[i].polyline.size(); j++) {
					ofVertex(addZoom(shapes[i].polyline[j].x-mapping_rect_dst.x)+mapping_rect_dst.x,
							 addZoom(shapes[i].polyline[j].y-mapping_rect_dst.y)+mapping_rect_dst.y);
				}
				ofEndShape(true);
			}
		}

		//draw dragging points
		ofSetColor(255,255,255,200);
		if(parent_projector->getMappingObject(i)->editable) {
			for(unsigned int j = 0; j < shapes[i].polyline.size(); j++) {
				if (shapes[i].polyline[j].bOver) ofFill();
				else ofNoFill();
				ofDrawCircle(addZoom(shapes[i].polyline[j]-mapping_rect_dst.getPosition())+mapping_rect_dst.getPosition(),6);
			}
		}

	}

	if(!direct_edit) {
		ofPopMatrix();
		mapping_front.end();
		mapping_front.draw(mapping_rect_dst.getPosition()-ofPoint(mapping_margin, mapping_margin), mapping_front.getWidth(), mapping_front.getHeight());
	}

	//draw src

	for (unsigned int i = 0; i < shapes.size(); i++) {

		ofNoFill();
		ofSetColor(shapes[i].color,255);
		ofBeginShape();

		for(unsigned int j = 0; j < shapes[i].src.size(); j++) {
			ofVertex(shapes[i].src[j].x, shapes[i].src[j].y);
		}
		ofEndShape(true);

		//draw dragging points
		ofSetColor(255,255,255,200);
		if(parent_projector->getMappingObject(i)->editable) {
			for(unsigned int j = 0; j < shapes[i].src.size(); j++) {

				if (shapes[i].src[j].bOver) ofFill();
				else ofNoFill();
				if(j%2==0)
					ofDrawCircle(shapes[i].src[j].x, shapes[i].src[j].y,6);

			}
		}

	}

}