Google Classroom
GeoGebraTarefa

Fun with stars

Script version 2: Using Zip()

n=10 Ln = 1..n #--------------------------------------- # Position #--------------------------------------- Execute(Zip("posx"+k+" = Slider(-20, 20, 0.001, 1, 140, false, true, false, false)", k, Ln)) Execute(Zip("posy"+k+" = Slider(-20, 20, 0.001, 1, 140, false, true, false, false)", k, Ln)) Execute(Zip("SetVisibleInView(posx"+k+", 1, false)", k, Ln)) Execute(Zip("SetVisibleInView(posy"+k+", 1, false)", k, Ln)) Execute(Zip("SetValue(posx"+k+", RandomUniform(-15, 15))", k, Ln)) Execute(Zip("SetValue(posy"+k+", RandomUniform(-10, 10))", k, Ln)) #--------------------------------------- # Velocity #--------------------------------------- Execute(Zip("velx"+k+" = Slider(-0.3, 0.3, 0.001, 1, 140, false, true, false, false)", k, Ln)) Execute(Zip("vely"+k+" = Slider(-0.3, 0.3, 0.001, 1, 140, false, true, false, false)", k, Ln)) Execute(Zip("SetVisibleInView(velx"+k+", 1, false)", k, Ln)) Execute(Zip("SetVisibleInView(vely"+k+", 1, false)", k, Ln)) Execute(Zip("SetValue(velx"+k+", RandomUniform(-0.3, 0.3))", k, Ln)) Execute(Zip("SetValue(vely"+k+", RandomUniform(-0.3, 0.3))", k, Ln)) #--------------------------------------- #Attractor #--------------------------------------- Otx=Slider(-15,15, 0.001, 1, 140, false, true, false, false) Oty=Slider(-10,10, 0.001, 1, 140, false, true, false, false) SetValue(Otx, 0) SetValue(Oty, 0) SetVisibleInView(Otx, 1, false) SetVisibleInView(Oty, 1, false) A=(Otx, Oty) SetCaption(A, "Drag") #--------------------------------------- # Direction #--------------------------------------- Execute(Zip("dirx"+k+" = Otx - posx"+k+"", k, Ln)) Execute(Zip("diry"+k+" = Oty - posy"+k+"", k, Ln)) Execute(Zip("norm"+k+" = sqrt( (dirx"+k+")^2 + (diry"+k+")^2 )", k, Ln)) Execute(Zip("scalex"+k+" = RandomUniform(0.0005, 0.009)"+k+"", k, Ln)) Execute(Zip("scaley"+k+" = RandomUniform(0.0005, 0.009)"+k+"", k, Ln)) #--------------------------------------- # Acceleration #--------------------------------------- ##normalize and scale## Execute(Zip("accx"+k+"=(Otx - posx"+k+") / norm"+k+" * scalex"+k+"", k, Ln)) Execute(Zip("accy"+k+"=(Oty - posy"+k+") / norm"+k+" * scaley"+k+"", k, Ln)) #--------------------------------------- # Stars #--------------------------------------- r(α) = 1.5(0.4 + 0.1*sin(5α)) SetVisibleInView(r, 1, false) #star = Curve((r(α);α)+(x, y), α, 0, 2pi) Execute(Zip("angle"+k+"=atan2( posy"+k+", posx"+k+" )", k, Ln)) Execute(Zip("SetVisibleInView(angle"+k+", 1, false)", k, Ln)) Execute(Zip("star"+k+"= Rotate( Curve((r(α);α)+(posx"+k+", posy"+k+"), α, 0, 2pi), angle"+k+", (posx"+k+", posy"+k+") )", k, Ln)) Execute(Zip("ShowLabel(star"+k+", false)", k, Ln)) Execute(Zip("SetDynamicColor(star"+k+", 255/255, 215/255, 0/255, 1)", k, Ln)) #--------------------------------------- # For animation #--------------------------------------- Run=Slider(-5, 5, 0.01, 1, 140, false, true, false, false) ShowLabel(Run, false) SetVisibleInView(Run, 1, false) #------------------------------------------------------ #After Run is defined add this script in Update #------------------------------------------------------ #Execute(Zip("SetValue(velx"+k+", velx"+k+" + accx"+k+" )", k, Ln)) #Execute(Zip("SetValue(vely"+k+", vely"+k+" + accy"+k+" )", k, Ln)) #Execute(Zip("SetValue(posx"+k+", posx"+k+" + velx"+k+" )", k, Ln)) #Execute(Zip("SetValue(posy"+k+", posy"+k+" + vely"+k+" )", k, Ln)) #--------------------------------------- #Extra settings #--------------------------------------- SetBackgroundColor("Black") ShowAxes(false) ShowGrid(false) CenterView(A) a=false SetCaption(a, "Run") SetValue(a, false) SetColor(a, "White") #------------------------------------------------------ #After boolean is defined add this script in Update #------------------------------------------------------ #StartAnimation(Run, a)

Script version 1: Using Sequence()

#--------------------------------------- # Position #--------------------------------------- n=10 Execute(Sequence("A"+i+"=Slider(-20, 20, 0.001, 1, 140, false, true, false, false)", i, 1, n)) Execute(Sequence("B"+i+"=Slider(-20, 20, 0.001, 1, 140, false, true, false, false)", i, 1, n)) Execute(Sequence("SetVisibleInView(A"+i+", 1, false)", i, 1, n)) Execute(Sequence("SetVisibleInView(B"+i+", 1, false)", i, 1, n)) Execute(Sequence("SetValue(A"+i+", RandomUniform(-15, 15))", i, 1, n)) Execute(Sequence("SetValue(B"+i+", RandomUniform(-10, 10))", i, 1, n)) #--------------------------------------- # Velocity #--------------------------------------- Execute(Sequence("E"+i+"=Slider(-0.3, 0.3, 0.001, 1, 140, false, true, false, false)", i, 1, n)) Execute(Sequence("F"+i+"=Slider(-0.3, 0.3, 0.001, 1, 140, false, true, false, false)", i, 1, n)) Execute(Sequence("SetVisibleInView(E"+i+", 1, false)", i, 1, n)) Execute(Sequence("SetVisibleInView(F"+i+", 1, false)", i, 1, n)) Execute(Sequence("SetValue(E"+i+", RandomUniform(-0.3, 0.3))", i, 1, n)) Execute(Sequence("SetValue(F"+i+", RandomUniform(-0.3, 0.3))", i, 1, n)) #--------------------------------------- #Attractor #--------------------------------------- Otx=Slider(-15,15, 0.001, 1, 140, false, true, false, false) Oty=Slider(-10,10, 0.001, 1, 140, false, true, false, false) SetVisibleInView(Otx, 1, false) SetVisibleInView(Oty, 1, false) A=(Otx, Oty) #--------------------------------------- # Direction #--------------------------------------- Execute(Sequence("G"+i+"=Otx-A"+i+"", i, 1, n)) Execute(Sequence("H"+i+"=Oty-B"+i+"", i, 1, n)) Execute(Sequence("I"+i+"=sqrt( (G"+i+")^2+(H"+i+")^2 )", i, 1, n)) Execute(Sequence("S"+i+"=RandomUniform(0.0005, 0.009)"+i+"", i, 1, n)) Execute(Sequence("T"+i+"=RandomUniform(0.0005, 0.009)"+i+"", i, 1, n)) #scale=0.06 #--------------------------------------- # Acceleration #--------------------------------------- ##normalize and scale## Execute(Sequence("J"+i+"=(Otx-A"+i+")/I"+i+"*S"+i+"", i, 1, n)) Execute(Sequence("K"+i+"=(Oty-B"+i+")/I"+i+"*T"+i+"", i, 1, n)) #--------------------------------------- # Stars #--------------------------------------- r(α) = 1.5(0.4 + 0.1*sin(5α)) SetVisibleInView(r, 1, false) #star = Curve((r(α);α)+(x, y), α, 0, 2pi) Execute(Sequence("C"+i+"=atan2(B"+i+", A"+i+")", i, 1, n)) Execute(Sequence("SetVisibleInView(C"+i+", 1, false)", i, 1, n)) Execute(Sequence("D"+i+"= Rotate( Curve((r(α);α)+(A"+i+", B"+i+"), α, 0, 2pi), C"+i+", (A"+i+", B"+i+") )", i, 1, n)) Execute(Sequence("SetDynamicColor(D"+i+", 255/255, 215/255, 0/255, 1)", i, 1, n)) #--------------------------------------- # For animation #--------------------------------------- Run=Slider(-5, 5, 0.01, 1, 140, false, true, false, false) ShowLabel(Run, false) SetVisibleInView(Run, 1, false) #------------------------------------------------------ #After Run is defined add this script in Update #------------------------------------------------------ #Execute(Sequence("SetValue(E"+i+", E"+i+" + J"+i+" )", i, 1, n)) #Execute(Sequence("SetValue(F"+i+", F"+i+" + K"+i+" )", i, 1, n)) #Execute(Sequence("SetValue(A"+i+", A"+i+" + E"+i+" )", i, 1, n)) #Execute(Sequence("SetValue(B"+i+", B"+i+" + F"+i+" )", i, 1, n)) #--------------------------------------- #Extra settings #--------------------------------------- SetBackgroundColor("Black") ShowAxes(false) ShowGrid(false) a=false SetValue(a, false) SetColor(a, "White")