Neckless

advertisement
Neckless
roughNecklace@n_D :=
Block@8<, HGraphics@8Circle@D, Table@Rectangle@8Cos@tD - .05, Sin@tD - .05<,
8Cos@tD + .05, Sin@tD + .05<D, 8t, 0, 2 * Pi, 2 * Pi ê n<D<DLD
H* here the entire procedure is in one command line. it works just fine,
but it is difficult to make it do more, as it's a long, complex function *L
roughNecklace@8D
square@sideLength_, center_D := Block@8shift<,
H
shift = .5 * sideLength;
Rectangle@center - 8shift, shift<, center + 8shift, shift<D
LD
H* first we make a procedure that will create a square of a certain size,
centered at a certain point. we could do this for fixed sizes,
but it's better to make it an input-based procedure,
thereby giving it more flexibility *L
Printed by Wolfram Mathematica Student Edition
2
MyNecklace.nb
basicNecklace@n_D := Block@8beadSpots, beads<,
H
beadSpots = Table@8Cos@tD, Sin@tD<, 8t, 0, 2 Pi, 2 Pi ê n<D;
H* make a table, using trig, of n evenly spaced locations *L
beads = Table@square@.1, beadSpots@@iDDD, 8i, 1, n<D;
H* table of squares. note that we've fixed the size of squares here,
giving us a great idea of where to make this a more flexible program *L
Graphics@8Circle@D, beads<D
H* this is the command to turn stuff into graphic objects *L
H* note that Circle@D gives a unit circle. but here is
another opportunity to add more inputs, to adjust the circle *L
LD
basicNecklace@6D
Printed by Wolfram Mathematica Student Edition
MyNecklace.nb
basicNecklace@20D
H* here are some examples of what the basic program is capable of *L
secondNecklace@n_, beadSize_, laceColor_, laceSize_D :=
Block@8beadSpots, beads, lace<,
H
beadSpots = Table@8Cos@tD, Sin@tD<, 8t, 0, 2 Pi, 2 Pi ê n<D;
lace = Graphics@8Hue@laceColorD, Thickness@laceSizeD, Circle@D<D;
H* now we've made a graphics object that is our unit circle. Since
I'm giving it more inputs Hcolor and thicknessL, I've moved it
outside the Graphics command for more ease in readingêcomputing *L
beads = Table@Graphics@square@beadSize, beadSpots@@iDDDD, 8i, 1, n<D;
H* we've added beadSize, and since I made the circle a Graphics object,
I'm making the beads intoa table of Graphics as well *L
Show@lace, beadsD
H* now I'm displaying the Graphics *L
LD
Printed by Wolfram Mathematica Student Edition
3
4
MyNecklace.nb
secondNecklace@8, .2, .5, .05D
thirdNecklace@n_, beadSize_, laceColor_, laceSize_, beadColor_D :=
Block@8beadSpots, beads, lace<,
H
beadSpots = Table@8Cos@tD, Sin@tD<, 8t, 0, 2 Pi, 2 Pi ê n<D;
lace = Graphics@8Hue@laceColorD, Thickness@laceSizeD, Circle@D<D;
H* there are a few ways of making the beads colored *L
beads =
Table@Graphics@8Hue@beadColorD, square@beadSize, beadSpots@@iDDD<D, 8i, 1, n<D;
H* since this is where the squares are converted to graphics,
this is where we add color details to those squares *L
Show@lace, beadsD
LD
Printed by Wolfram Mathematica Student Edition
MyNecklace.nb
thirdNecklace@8, .2, .7, .05, .5D
rainbowNecklace@n_, beadSize_, laceSize_D := Block@8beadSpots, beads, lace<,
H
beadSpots = Table@8Cos@tD, Sin@tD<, 8t, 0, 2 Pi, 2 Pi ê n<D;
lace = Graphics@8Thickness@laceSizeD, Circle@D<D;
H* I went back to a black lace *L
beads = Table@
Graphics@8Hue@1 - i * 1 ê nD, square@beadSize, beadSpots@@iDDD<D, 8i, 1, n<D;
Show@lace, beadsD
LD
Printed by Wolfram Mathematica Student Edition
5
6
MyNecklace.nb
rainbowNecklace@20, .1, .01D
randomNeckless@n_D := Block@8unitC, beads, coloredBeads<,
H
unitC = Graphics@8Thickness@.02D, Circle@D<D;
beads = Table@Rectangle@8Cos@tD - .1, Sin@tD - .1<,
8Cos@tD + .1, Sin@tD + .1<D, 8t, 0, 2 * Pi, 2 * Pi ê n<D;
H* this is a one-line construction. note the length of the command *L
coloredBeads = Table@8Hue@RandomReal@DD, beads@@iDD<, 8i, 1, n<D;
H* here's one with random instead of
rainbow. and I removed the other inputs, just to see *L
Show@unitC, Graphics@coloredBeadsDD
LD
Printed by Wolfram Mathematica Student Edition
MyNecklace.nb
randomNeckless@10D
anotherNecklace@n_D := Block@8beadSpots, beads, beads2, lace, lace2, rings, rings2<,
H
beadSpots = Table@8Cos@tD, Sin@tD<, 8t, 0, 2 Pi, 2 Pi ê n<D;
lace = Graphics@8Thickness@.03D, Circle@D<D;
lace2 = Graphics@8Thickness@.01D, Circle@80, 0<, .5D<D;
beads =
Table@Graphics@8Hue@1 - i * 1 ê nD, square@.15, beadSpots@@iDDD<D, 8i, 1, n<D;
beads2 = Table@Graphics@8Hue@1 - i * 1 ê nD, square@.1, .5 * beadSpots@@iDDD<D,
8i, 1, n<D;
rings = Table@Graphics@Circle@beadSpots@@iDD, .2DD, 8i, 1, n<D;
rings2 = Table@Graphics@Circle@.5 beadSpots@@iDD, .1DD, 8i, 1, n<D;
Show@lace, lace2, beads, beads2, rings, rings2D
LD
Printed by Wolfram Mathematica Student Edition
7
8
MyNecklace.nb
anotherNecklace@20D
christmasWreath@D := Block@8green, berries1, berries2, berries3<,
H
green = Table@Graphics@8Green, PointSize@.6D, Point@8Cos@tD, Sin@tD<D<D,
8t, 0, 2 Pi, 2 Pi ê 8<D;
berries1 = Table@Graphics@8Red, PointSize@.06D, Point@8.7 Cos@tD, .7 Sin@tD<D<D,
8t, 0, 2 Pi, 2 Pi ê 10<D;
berries2 = Table@Graphics@8Red, PointSize@.06D,
Point@81.3 * Cos@tD, 1.3 * Sin@tD<D<D, 8t, 0, 2 Pi, 2 Pi ê 10<D;
berries3 = Table@Graphics@8Red, PointSize@.06D, Point@8Cos@tD, Sin@tD<D<D,
8t, 0 + 2 Pi ê 20, 2 Pi + 2 Pi ê 20, 2 Pi ê 10<D;
Show@green, berries1, berries2, berries3D
LD
Printed by Wolfram Mathematica Student Edition
MyNecklace.nb
christmasWreath@D
Printed by Wolfram Mathematica Student Edition
9
Download