Fun with Printable Programming: Loops and Shapes

Slide Note
Embed
Share

Learn how to use for loops in programming with creative examples including generating beeps, constructing lego pieces, and designing wheels using geometric shapes. Explore the fun and educational world of printable programming with practical demonstrations and step-by-step visuals.


Uploaded on Dec 07, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Printable Programming For Loops

  2. for loop resetBeeper(); How many beeps? for (i = 1; i <= 4; i= i+1){ beep(); } i = 1, 2, 3, 4

  3. for loop i = 1, 2, 3, 4 4 beeps resetBeeper(); for (i = 1; i <= 4; i= i+1){ beep(); } 1 for (i = 1; i <= 6; i= i+1){ 2 for (i = 1; i < 6; i= i+1){ 3 for (i = 0; i <= 4; i= i+1){ 4 for (i = -1; i <= 4; i= i+1){ 5 for (i = 1; i <= 4; i= i+2){ 6 for (i = 4; i >1; i= i-1){ 7 for (i = 10; i > 4; i= i-1){

  4. for loop with textGeom for (i = 1; i <= 4; i = i+1){ g = textGeom(i) g.moveX(20*i); g.display(); } Play around with the code.

  5. A Lego piece

  6. A Lego piece: Step 1 L = 16; W = 1.5; H = 2; R = 0.75; HCyl = 2.2; base = cube(L,W,H).moveX(L/2); cyl1 = cylinder(R,HCyl).rotateX(90); cyl1.moveZ(H/4); cyl1.moveX(L/16); base =base.add(cyl1); base.display();

  7. A Lego piece: Step 2 L = 16; W = 1.5; H = 2; R = 0.75; HCyl = 2.2; base = cube(L,W,H).moveX(L/2); cyl1 = cylinder(R,HCyl).rotateX(90); cyl1.moveZ(H/4); cyl1.moveX(L/16);// position first object for (i = 1; i <= 8; i= i+1) {// start for loop base =base.add(cyl1);// add cyl1.moveX(L/8);// then move } base.display();

  8. Wheel wheel = torus(1,0.1); spoke1 = cylinder(0.05,2); spoke2 = cylinder(0.05,2).rotateZ(45); spoke3 = cylinder(0.05,2).rotateZ(90); spoke4 = cylinder(0.05,2).rotateZ(135); wheel = wheel.add(spoke1); wheel = wheel.add(spoke2); wheel = wheel.add(spoke3); wheel = wheel.add(spoke4); wheel.display(); Redo using for-loop.

  9. Wheel: Step 1 wheel = torus(1,0.1); spoke = cylinder(0.05,2); wheel = wheel.add(spoke); wheel.display();

  10. Wheel wheel = torus(1,0.1); spoke = cylinder(0.05,2);// position first object for (i=1; i<=4; i=i+1){// start for loop wheel = wheel.add(spoke);// add wheel.rotateZ(45);// then rotate } wheel.display();

  11. Wheel with more spokes

  12. Wheel with more spokes wheel = torus(1,0.1); spoke = cylinder(0.05,2);// position first object for (i=1; i<=8; i=i+1){// start for loop wheel = wheel.add(spoke);// add wheel.rotateZ(22.5);// then rotate } wheel.display();

More Related Content