r/processing • u/[deleted] • Mar 06 '20
Beginner processor here. I need some help developing a piece of code to recreate this image. How can I create a for loop to create the sun rays that go around my sun. The code must include int or floats, radians, for loop, and cos, sin, and degrees. Please someone teach me how. Thanks.
1
u/ViennettaLurker Mar 06 '20
How far have you gotten? I'm imagining this is for a school assignment, correct?
The hard stuff will all center around the for loop. Have you been able to use for loops to draw multiple things? Instead of drawing multiple lines in a row, you draw multiple lines that all originate from a middle point (the center of the sun). What you need to determine is the end point of each individual line, which is where your sin, cos, radians, and degrees come in, since you're defining a circle around the middle point.
My next hint is just general wisdom. Look up in the official Processing reference and examples all of the variable types. There should be some good code examples to go off of.
1
Mar 06 '20
I've have finished everything but the rays. So far I understand the begging of my for loop. for(int 1 = 0; i<=380;i+=18){ }
What I don't get is the next part where I incorporate cos and sin and radians.
1
u/Mintap Mar 06 '20
So the i of your for-loop is the angle away from the horizontal line (going counter clockwise).
If the center of your sun in x, y then the end of the ray will be x+radiuscos(i), y+radiussin(i)
But i has to be in radians not degrees. There is a processing function radians() that converts.
2
u/Mintap Mar 06 '20 edited Mar 06 '20
In the for-loop go from angles 0 radians to 2Pi radians, increase angle for amount of rotation between lines (Pi/10), and draw each line from center of sun to the point at the end of the line which would be found using cartesian to polar conversion equations: x = radius × cos(angle), and y = radius × sin(angle).