void drawSet(double zoom_factor, double offset) { clock_t start = clock(); /* (x,y) is the pixel coordinate with respect to the center (x0,y0) (xp,yp) is the pixel coordinate with respect to the image corner. */ double xp, yp, r, g, b; int iteration = 0; struct complex c; int color; /* Complex plane scaling */ double xp_max = ( 1.25 * scaleX - offset ) / zoom_factor; double xp_min = ( -1.75 * scaleX - offset ) / zoom_factor; double yp_max = ( 1.5 * scaleY - offset ) / zoom_factor; double yp_min = ( -1.5 * scaleY - offset ) / zoom_factor; // Lock surface if needed if (SDL_MUSTLOCK(screen)) if (SDL_LockSurface(screen) < 0) return; for (xp = 0; xp < sizeX; xp++) { for (yp = 0; yp < sizeY; yp++) { /* Scaling */ c.real = ( (xp_max - xp_min) * xp ) / sizeX + xp_min; c.imag = ( (yp_max - yp_min) * yp ) / sizeY + yp_min; // printf("x is: %f, y is: %f\n", x, y); iteration = mandelbrotCalc(c); // printf("iteration: %d\n", iteration); /* Define the color sets that are going to be used. */ if (iteration > max_iteration) { color = 0x000000; } else { double i = (iteration * 255 / max_iteration); r = round(sin(0.2 * i + 0) * 127 + 128); g = round(sin(0.2 * i + 2) * 127 + 128); b = round(sin(0.2 * i + 4) * 127 + 128); color = createRGB(r,g,b); } putpixel(xp,yp,color); iteration = 0; } } // Unlock if needed if (SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); // update the whole screen SDL_UpdateRect(screen, 0, 0, sizeX, sizeY); clock_t end = clock(); clock_t millis = end - start; printf("Elapsed time: %lu\n", millis); }
static void battery_update_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); // Find the width of the bar float percent = ((float)s_battery_level / 100.0F); int width = (int)(float)(percent * bounds.size.w); // Draw the background GColor bgcolor = GColorFromHEX(persist_read_int(MESSAGE_KEY_BackgroundColor)); GColor batterycolor; //graphics_context_set_fill_color(ctx, GColorClear); //graphics_fill_rect(ctx, bounds, 0, GCornerNone); // Draw the bar int g = (255 * percent); int r = (255 * (1 - percent)); int b = 0; int rgb = createRGB(r, g, b); if (s_battery_level == 100) { r = 85; g = 255; } if (s_battery_level == 50) { rgb = 0xFFAA00; } int x = persist_read_int(MESSAGE_KEY_Battery); APP_LOG(APP_LOG_LEVEL_INFO, "Battery Preference: %d", x); if (persist_read_int(MESSAGE_KEY_Battery) != 102) { APP_LOG(APP_LOG_LEVEL_INFO, "RGB"); batterycolor = GColorFromHEX(rgb); } else { batterycolor = gcolor_legible_over(bgcolor); } PBL_IF_BW_ELSE(graphics_context_set_fill_color(ctx, batterycolor), graphics_context_set_fill_color(ctx, batterycolor)); //APP_LOG(APP_LOG_LEVEL_INFO, GColorFromHEX(rgb)); /* if (s_battery_level <= 20) { graphics_context_set_fill_color(ctx, PBL_IF_BW_ELSE(GColorBlack, GColorRed)); } else if (s_battery_level == 100) { graphics_context_set_fill_color(ctx, PBL_IF_BW_ELSE(GColorBlack, GColorBrightGreen)); } */ GRect frame = grect_inset(bounds, GEdgeInsets(10)); //graphics_context_set_fill_color(ctx, GColorBlack); PBL_IF_ROUND_ELSE(graphics_fill_radial(ctx, frame, GOvalScaleModeFitCircle, 5, DEG_TO_TRIGANGLE(125+((1-percent)*110)), DEG_TO_TRIGANGLE(235)), graphics_fill_rect(ctx, GRect(0, 0, width, bounds.size.h), 0, GCornerNone)); }
//drawing void DrawingManager::draw(ofxVectorGraphics &output, bool history){ bool dselect = false; int rv=70; if (mode == SELECT_M ||mode == DIRECT_M ) dselect = true; if(history){ int lDp = dP-4; if(lDp<0)lDp=0; for(int i = dP-1;i>=lDp;i--){ int color = createRGB(255,rv,rv); if(i>=0 && i<savedDrawings.size()){ for(int j=0;j<savedDrawings[i].size();j++){ savedDrawings[i][j]->draw(output,color); } } rv+=70; if(rv>255){ rv=255; } } /* rv=70; int kDp = dP+4; if(kDp>savedDrawings.size()-1)kDp=savedDrawings.size()-1; for(int i = dP+1;i<=kDp;i++){ int color = createRGB(rv,255,rv); for(int j=0;j<savedDrawings[i].size();j++){ savedDrawings[i][j]->draw(output,dselect,color); } rv+=70; if(rv>255){ rv=255; } }*/ } if(currentShapes!=NULL){ for(int i=0;i<currentShapes->size();i++){ (*currentShapes)[ i ]->draw(output); } } }