File tree Expand file tree Collapse file tree 1 file changed +13
-35
lines changed Expand file tree Collapse file tree 1 file changed +13
-35
lines changed Original file line number Diff line number Diff line change 1- //Half of these are useless but I do not wish to deal with this bull rn
2- let r = 10 ;
3- let rDir = 1 ;
4- let rEnabled = 1 ;
5- let rMax ;
6- let R = 2 ;
7- let RDir = 10 ;
8- let REnabled = 0 ;
9- let RMax ;
10- let O = 30 ;
11- let ODir = 2.5 ;
12- let OMax ;
1+ //Defines each variable required for spirographhs
2+ let r ;
3+ let R ;
4+ let O ;
135let frame = 0 ;
14- let frameMod = 20 ;
6+ let frameMod = 40 ;
157
168//Runs once at the start and sets environment variable
179function setup ( ) {
10+ //R has to stay constant to take up the whole canvas
11+ R = ( windowWidth / 4 ) + 1 ;
12+
13+ //P5JS canvas setup
1814 createCanvas ( windowWidth , windowHeight ) ;
19- rMax = 70 //windowWidth/8;
20- OMax = windowWidth / 4 ;
21- R = windowWidth / 4 + 1 ;
22- background ( 0 ) ;
2315 stroke ( 0 , 100 , 0 ) ;
24- frameRate ( 30 ) ;
16+ frameRate ( frameMod * ( 2 / 3 ) ) ;
2517}
2618
2719//Runs ever frame
2820function draw ( ) {
2921 background ( 0 ) ;
22+ //Calculate current r and O values and draw the next step of spiro graph
23+ r = 9 + Math . abs ( 60 - ( Math . floor ( frame / 20 ) % 120 ) ) ;
24+ O = 20 + Math . abs ( 20 - ( Math . floor ( frame / 100 ) % 40 ) ) ;
3025 for ( let t = 0 ; t < ( 100 / frameMod ) * ( frame % frameMod ) ; t += 0.025 ) {
3126 line ( x ( t ) , y ( t ) , x ( t + 0.025 ) , y ( t + 0.025 ) ) ;
3227 }
33- //This does cool maths to make it move, I've changed it so much I no longer know what it does
34- if ( frame % frameMod == 0 ) {
35- //Code in this runs ever 20 frames
36- r += rDir ;
37- if ( O == r ) {
38- r += rDir ;
39- }
40- if ( r >= rMax || r <= 9 ) {
41- rDir *= - 1 ;
42- }
43- if ( frame % ( frameMod * 7 ) == 0 ) {
44- O += ODir ;
45- if ( O >= 40 || O <= 20 ) {
46- ODir *= - 1 ;
47- }
48- }
49- }
5028 frame ++ ;
5129}
5230
You can’t perform that action at this time.
0 commit comments