He estado buscando problemas con esto desde hace un tiempo y necesito ayuda. Solo quiero dibujar 25 líneas desde el centro de mi pantalla (160,200) a una separación de 14.4 grados. He estado usando esta línea de código en un bucle donde x es el multiplicador de 14,4 grados -Gráficos básicos: dibujando una línea en un ángulo
UIImage*backgroundImage = [UIImage imageNamed:@"Primate Background Only.png"];
[backgroundImage drawInRect:CGRectMake(0, 0, 320, 480)];
// Dibujar Outer Circle
rect = CGRectMake(0.0, 35.0, 320.0, 320.0);
CGContextRef contextRef = UIGraphicsGetCurrentContext(); // Get the contextRef
CGContextSetLineWidth (contextRef, 0.5); // Set the border width
CGContextSetRGBFillColor (contextRef, (219.0f/255.0f), (219.0f/255.0f), (219.0f/255.0f), 0.05f); // Set the circle fill color to GREEN
CGContextSetRGBStrokeColor (contextRef, 0.0, 0.0, 0.0, 0.2); // Set the circle border color to BLACK
CGContextFillEllipseInRect (contextRef, rect); // Fill the circle with the fill color
CGContextStrokeEllipseInRect (contextRef, rect); // Draw the circle border
// Dibujar círculo interior
rect = CGRectMake(25.0, 60.0, 270.0, 270.0); // Get the contextRef
CGContextSetLineWidth (contextRef, 0.5); // Set the border width
CGContextSetRGBFillColor (contextRef, (219.0f/255.0f), (219.0f/255.0f), (219.0f/255.0f), 0.25f);
CGContextSetRGBStrokeColor (contextRef, 0.0, 0.0, 0.0, 0.2); // Set the circle border color to BLACK
CGContextFillEllipseInRect (contextRef, rect); // Fill the circle with the fill color
CGContextStrokeEllipseInRect (contextRef, rect);
// Dibujar segmentos
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0.0, 0.0);
for (x=1; x<26; x++) {
CGContextSetLineWidth (context, 0.5);
CGContextSetRGBStrokeColor (context, 0.0, 0.0, 0.0, 0.25);
CGContextMoveToPoint (context, 160, 200);
CGContextAddLineToPoint (context, (160.0 * (cos((x*14.4)*(M_PI/180)))), (160.0 * (sin((x*14.4)*(M_PI/180))))); // The angle is in degrees
CGContextAddLineToPoint (context, 200, 65);
CGContextAddLineToPoint (context, 160, 200);
CGContextStrokePath(context); // Why is this not showing both line color and infill?
CGContextSetFillColorWithColor (context, [UIColor whiteColor].CGColor);
CGContextFillPath (context);
CGContextRef context = UIGraphicsGetCurrentContext();
}
(¡Tenía la intención de publicar una imagen aquí, pero no me lo permite!)
¿Alguien puede por favor corregir mis funciones trigonométricas. Esto tiene como objetivo dibujar 25 líneas en el sentido de las agujas del reloj desde las 12:00 en punto hasta las 24:00. En su lugar, retrocede solo 90 grados y luego regresa, todas las líneas también tienen una longitud de salida.
muy agradecidos
Por encima es una muestra más grande del código utilizado para dibujar círculos exteriores de remolque y los segmentos interiores conforme a lo solicitado. Intentaré y subiré la imagen a continuación.
La trigonometría se ve bien, ¿nos puede mostrar más de su código? El ciclo que itera 'x', etc. –
Gustav tiene razón. Además, si puede cargar la imagen en otro lugar y proporcionarle un enlace, alguien con suficiente reputación puede editar su publicación para ponerla en línea. – Tommy
Reformatearé tu código pero es demasiado ... ¿puedes formatearlo para que sea legible? Excepto que intentas ofuscarlo intencionalmente :) –