SlideShare una empresa de Scribd logo
1 de 30
Descargar para leer sin conexión
Introduction
to
coding
using JavaScript and codeguppy.com
Part I: Introduction
• About codeguppy.com
• Creating accounts in codeguppy.com
• Environment overview
Part II: Steps into coding
• Drag and drop coding
• Drawing with code
• Animations
Agenda
codeguppy.com
About codeguppy.com
• Online coding platform for kids, teens and
code newbies
• Text-based coding
• JavaScript language
• Based on p5.js (Processing API)
• Code animations, games and other fun
programs
• Built-in assets (backgrounds, sprites, etc.)
• Tons of projects. Browse – Remix – Share
• Free!
Why learn JavaScript?
• JavaScript is a super-popular real-world programming language
used both by beginners but also by professional software
developers. (The entire codeguppy.com was coded in JavaScript)
• People use JavaScript to build websites, online games and do
creative coding. On codeguppy.com, you can use JavaScript to draw
with code, implement animations, build games and other fun
projects.
• Coding in a text-based language such as JavaScript has also other
benefits beyond the world of programming. It enhances problem-
solving skills but also attention to details.
Programming is like
writing a book...
… except if you miss out a
single comma on page 349
the whole thing you wrote
makes no sense.
- Anonymous
codeguppy.com
Let’s open an account with codeguppy.com
• codeguppy.com gives you unlimited space in the cloud to write and
store tons of programs
• But first you need to open an account with codeguppy.com
• You need to provide a valid email address and a password (website
doesn’t ask any other personal details)
Note: After registration, you should get an email from codeguppy.com.
Please verify your email by clicking the link in the email.
JOIN FOR FREE
Email:
Password:
REGISTER NOW
Register with email
1
2
3
Code Editor
Type here your
program
Assets Toolbar
Browse sprite
library, colors,
etc.
Run / Stop Button
Run or Stop your program.
Output Canvas
Here you’ll see the
output of your
program.
Exploring
action bar
Let’s play with built-in assets
sprite('adventure_girl.idle', 400, 300, 0.5); sprite('knight.idle', 400, 300, 0.5);
You don’t have to write the above code. Just drag and drop a sprite from the palette in the code editor to have this code generated for you.
music('Fun Background');
background('Field');
sprite('plane.fly', 400, 300, 0.5);
Build a program using drag-and-drop
Step 1: Drag and drop a music
file
Step 2: Drag and drop a
background image or color
Step 3: Drag and drop a sprite
Press “Play” when ready.
Built-in instruction that asks
computer to display a sprite on
the canvas.
The actual sprite is specified in
between quotes inside the
parenthesis as a “parameter”.
Parameters of the instruction.
Parameters specify what sprite to display, where to
display it on the canvas and at what coordinates.
Experiment: Try to change the 400 and 300
numbers with other numbers between 0 and 800.
Press “Play” / “Stop”
after each
modification to run /
stop the program.
sprite('adventure_girl.idle', 400, 300, 0.5);
• Programs can write and draw on a graphical canvas of 800x600 pixels
• Origin is in the top-left corner
• Middle of the canvas is at about (400, 300)
• x coordinate goes from 0 to 800 (left to right)
• y coordinate goes from 0 to 600 (top to bottom)
(400, 300)
Output canvas
Our first type-in program
circle(400, 300, 300);
• Type carefully this line in the
code editor.
• Make sure you use the same
casing as illustrated and
include all the punctuation
signs.
• When ready, press the Play /
Run button
circle(400, 300, 300);
Built-in instruction that asks
computer to draw a circle on the
canvas.
codeguppy.com has many built-
in instructions for different
purposes (remember the sprite
instruction used before).
Parameters of the instruction.
There are 3 parameters inside
parenthesis and separated by comma:
- 400, 300 - coordinates of circle
center
- 300 – radius of the circle
Try to modify the
parameters of this
instruction and
notice the effect.
Don’t forget to press
“Play” / “Stop” after
each modification.
codeguppy.com/code.html
// Draw bear face
circle(400, 300, 200);
// Draw left ear
circle(250, 100, 50);
circle(270, 122, 20);
// Draw right ear
circle(550, 100, 50);
circle(530, 122, 20);
// Draw left eye
circle(300, 220, 30);
circle(315, 230, 10);
// Draw right eye
circle(500, 220, 30);
circle(485, 230, 10);
// Draw nose
circle(400, 400, 90);
circle(400, 350, 20);
Multiple instructions
in a program
Other graphical instructions
circle(400, 300, 200);
ellipse(400, 300, 300, 200);
rect(400, 300, 300, 200);
line(400, 300, 500, 500);
triangle(400, 100, 200, 400, 600, 500);
arc(400, 300, 300, 200, 0, 180);
point(400, 300);
text('JavaScript', 400, 300); JavaScript
(400, 300)
200
(400, 300)
300
200
(400, 300)
300
200
(400, 300)
(500, 500)
(200, 400) (600, 500)
(400, 100)
(400, 300)
(400, 300)
(400, 300)
Practicing graphical instructions
• Exercise 1: On a blank piece of paper
draw an object / scene using only basic
shapes such as circles, lines, rectangles.
Convert that drawing into code!
OR
• Exercise 2: Download the “Draw with
code” booklet from the downloads
section. Choose any drawing, print the
page and type-in the program.
Note: Programs from the “Draw with code” booklet may have more instructions then presented here. Try to discover their purpose.
Introducing variables
let r = 100;
let r2 = 100 - 4;
circle(100, 100, r);
circle(100, 100, r2);
OR
• JavaScript allows users to define variables to hold various values or the result of complex calculations
• You can name variables however you prefer… but don’t start them with number or weird symbols
• Variables are super important in programming
Expressions and variables instead of scalars
circle(100, 100, 100);
circle(100, 100, 96);
You can let the computer do
calculations. At the end of the
day, your computer is also a
powerful calculator.
circle(100, 100, 100);
circle(100, 100, 100 - 4);
let r2 = 100 – 4;
circle(100, 100, 100);
circle(100, 100, r2);
Building our own custom instructions
circle2();
function circle2()
{
circle(100, 100, 100);
circle(100, 100, 100 - 4);
}
• We placed the two circle
instructions inside a code block
(delimited by curly brackets)
• The block is the body of function
circle2. Notice carefully the
syntax.
• The function circle2 is our new
custom instructions. However,
exactly like circle, it doesn’t do
anything until we call it.
1
2
3
1
2
3
Functions with parameters
circle2(400, 300, 100);
function circle2(x, y, r)
{
circle(x, y, r);
circle(x, y, r - 4);
}
Now this is a useful
function! It can be used to
draw a double-circle on the
canvas.
We can control the
position and radius of the
double circle!
Exercise: Design your own custom instruction (e.g. function) to draw something useful.
Modularizing code with functions
• Functions can also be used to modularize big pieces of code into smaller pieces
• The smaller pieces can then be assembled or reused exactly like Lego pieces
Exercise: Copy or type-in the “Car” program
from the “Draw with code” booklet /
playground.
If you typed everything correctly you should see
the following drawing when running the
program.
Modularizing the code
function background()
{
// Background
noStroke();
fill(180, 199, 231);
rect(0, 0, 800, 500);
fill(191, 144, 0);
rect(0, 500, 800, 100);
}
function sun()
{
// Sun
fill("yellow");
circle(750, 50, 150);
stroke("yellow");
strokeWeight(6);
line(480, 60, 561, 47);
line(548, 224, 602, 172);
line(740, 304, 747, 236);
}
function car()
{
// Car
stroke("black");
strokeWeight(1);
fill(112, 173, 71);
rect(175, 340, 223, 54);
rect(108, 394, 362, 74);
fill(132,60,12);
circle(168, 468, 32);
circle(408, 468, 32);
}
background();
sun();
car();
This is main body of our new program. Of course, this program calls the
specified functions.
In big programs, functions can be moved outside the main program in
external module or libraries.
Defining loop() function
function background()
{
...
}
function sun()
{
...
}
function car()
{
...
}
function loop()
{
background();
sun();
car();
}
• loop() is a special
function.
• We don’t have to
call it.
• The system will call
it automatically
about 60 times /
second.
Parametrize car() function
car(108);
function car(x)
{
// Car
stroke("black");
strokeWeight(1);
fill(112, 173, 71);
rect(x + 67, 340, 223, 54);
rect(x, 394, 362, 74);
fill(132,60,12);
circle(x + 60, 468, 32);
circle(x + 300, 468, 32);
}
We’ll update function car() to
accept a parameter x
representing the x coordinate
where the car will be drawn.
x = 108 x = 400 x = 650
… …
function loop()
{
Step 1: Clear the frame
Step 2: Redraw the
scene and car at
position x
Step 3: Increase
position x by 1
}
Animations
Increasing / decreasing variables
x++;
x += 1;
x = x + 1;
x--;
x -= 1;
x = x - 1;
Increasing the value Decreasing the value
Note: x++ and x-- forms always modify the value by 1.
The other forms can be used to modify the value by an arbitrary amount.
OR
OR
OR
OR
let x = 0;
function loop()
{
clear();
background();
sun();
car(x);
x++;
}
function car(x)
{
// Car
stroke("black");
strokeWeight(1);
fill(112, 173, 71);
rect(x + 67, 340, 223, 54);
rect(x, 394, 362, 74);
fill(132,60,12);
circle(x + 60, 468, 32);
circle(x + 300, 468, 32);
}
function background()
{
// Background
noStroke();
fill(180, 199, 231);
rect(0, 0, 800, 500);
fill(191, 144, 0);
rect(0, 500, 800, 100);
}
function sun()
{
// Sun
fill("yellow");
circle(750, 50, 150);
stroke("yellow");
strokeWeight(6);
line(480, 60, 561, 47);
line(548, 224, 602, 172);
line(740, 304, 747, 236);
}
Program
listing
Next steps
• Complete the exercises presented today. Don’t
be frustrated if you’ll encounter errors. Coding
required lots of practice until you get
comfortable writing programs.
• When working on a program, try to run the
program from time to time to avoid
accumulation of errors.
• Explore the other tutorials and projects from
the codeguppy.com website and don’t forget to
visit also the downloads section.
Algorithms More…
Games
Animations
https://codeguppy.com
Free coding platform

Más contenido relacionado

Similar a Introduction to Coding

A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsMichael Pirnat
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconftutorialsruby
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconftutorialsruby
 
The Ring programming language version 1.5.3 book - Part 57 of 184
The Ring programming language version 1.5.3 book - Part 57 of 184The Ring programming language version 1.5.3 book - Part 57 of 184
The Ring programming language version 1.5.3 book - Part 57 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 47 of 184
The Ring programming language version 1.5.3 book - Part 47 of 184The Ring programming language version 1.5.3 book - Part 47 of 184
The Ring programming language version 1.5.3 book - Part 47 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 58 of 210
The Ring programming language version 1.9 book - Part 58 of 210The Ring programming language version 1.9 book - Part 58 of 210
The Ring programming language version 1.9 book - Part 58 of 210Mahmoud Samir Fayed
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicsamitsarda3
 
How to make a video game
How to make a video gameHow to make a video game
How to make a video gamedandylion13
 
ma project
ma projectma project
ma projectAisu
 
Computer graphics
Computer graphics Computer graphics
Computer graphics shafiq sangi
 
Circles graphic
Circles graphicCircles graphic
Circles graphicalldesign
 
Displaying information within a window.68
Displaying information within a window.68Displaying information within a window.68
Displaying information within a window.68myrajendra
 
Arduino coding class part ii
Arduino coding class part iiArduino coding class part ii
Arduino coding class part iiJonah Marrs
 
Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfShaiAlmog1
 
The Ring programming language version 1.7 book - Part 50 of 196
The Ring programming language version 1.7 book - Part 50 of 196The Ring programming language version 1.7 book - Part 50 of 196
The Ring programming language version 1.7 book - Part 50 of 196Mahmoud Samir Fayed
 
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorUnreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorNick Pruehs
 
Ember.js Tokyo event 2014/09/22 (English)
Ember.js Tokyo event 2014/09/22 (English)Ember.js Tokyo event 2014/09/22 (English)
Ember.js Tokyo event 2014/09/22 (English)Yuki Shimada
 
The Ring programming language version 1.5.4 book - Part 47 of 185
The Ring programming language version 1.5.4 book - Part 47 of 185The Ring programming language version 1.5.4 book - Part 47 of 185
The Ring programming language version 1.5.4 book - Part 47 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 53 of 202
The Ring programming language version 1.8 book - Part 53 of 202The Ring programming language version 1.8 book - Part 53 of 202
The Ring programming language version 1.8 book - Part 53 of 202Mahmoud Samir Fayed
 

Similar a Introduction to Coding (20)

A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
 
The Ring programming language version 1.5.3 book - Part 57 of 184
The Ring programming language version 1.5.3 book - Part 57 of 184The Ring programming language version 1.5.3 book - Part 57 of 184
The Ring programming language version 1.5.3 book - Part 57 of 184
 
The Ring programming language version 1.5.3 book - Part 47 of 184
The Ring programming language version 1.5.3 book - Part 47 of 184The Ring programming language version 1.5.3 book - Part 47 of 184
The Ring programming language version 1.5.3 book - Part 47 of 184
 
The Ring programming language version 1.9 book - Part 58 of 210
The Ring programming language version 1.9 book - Part 58 of 210The Ring programming language version 1.9 book - Part 58 of 210
The Ring programming language version 1.9 book - Part 58 of 210
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
How to make a video game
How to make a video gameHow to make a video game
How to make a video game
 
ma project
ma projectma project
ma project
 
Computer graphics
Computer graphics Computer graphics
Computer graphics
 
Ch3
Ch3Ch3
Ch3
 
Circles graphic
Circles graphicCircles graphic
Circles graphic
 
Displaying information within a window.68
Displaying information within a window.68Displaying information within a window.68
Displaying information within a window.68
 
Arduino coding class part ii
Arduino coding class part iiArduino coding class part ii
Arduino coding class part ii
 
Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdf
 
The Ring programming language version 1.7 book - Part 50 of 196
The Ring programming language version 1.7 book - Part 50 of 196The Ring programming language version 1.7 book - Part 50 of 196
The Ring programming language version 1.7 book - Part 50 of 196
 
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorUnreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal Editor
 
Ember.js Tokyo event 2014/09/22 (English)
Ember.js Tokyo event 2014/09/22 (English)Ember.js Tokyo event 2014/09/22 (English)
Ember.js Tokyo event 2014/09/22 (English)
 
The Ring programming language version 1.5.4 book - Part 47 of 185
The Ring programming language version 1.5.4 book - Part 47 of 185The Ring programming language version 1.5.4 book - Part 47 of 185
The Ring programming language version 1.5.4 book - Part 47 of 185
 
The Ring programming language version 1.8 book - Part 53 of 202
The Ring programming language version 1.8 book - Part 53 of 202The Ring programming language version 1.8 book - Part 53 of 202
The Ring programming language version 1.8 book - Part 53 of 202
 

Más de Fabio506452

Lo_real_y_lo_virtual_-_Tomas_Maldonado.pdf
Lo_real_y_lo_virtual_-_Tomas_Maldonado.pdfLo_real_y_lo_virtual_-_Tomas_Maldonado.pdf
Lo_real_y_lo_virtual_-_Tomas_Maldonado.pdfFabio506452
 
Infografia Cambio de hábitos
Infografia Cambio de hábitosInfografia Cambio de hábitos
Infografia Cambio de hábitosFabio506452
 
Robotica 2 Actividad 1.pdf
Robotica 2 Actividad  1.pdfRobotica 2 Actividad  1.pdf
Robotica 2 Actividad 1.pdfFabio506452
 
Alfabetización Academica
Alfabetización AcademicaAlfabetización Academica
Alfabetización AcademicaFabio506452
 
Tutorial - Cómo ingresar al aula
Tutorial - Cómo ingresar al aulaTutorial - Cómo ingresar al aula
Tutorial - Cómo ingresar al aulaFabio506452
 
Entre lo sólido y lo espectral
Entre lo sólido y lo espectralEntre lo sólido y lo espectral
Entre lo sólido y lo espectralFabio506452
 
Cajas Navideñas
Cajas NavideñasCajas Navideñas
Cajas NavideñasFabio506452
 
Santa Fe Hace un siglo
Santa Fe Hace un sigloSanta Fe Hace un siglo
Santa Fe Hace un sigloFabio506452
 
Avalos-Katherine-Investigacion.pdf
Avalos-Katherine-Investigacion.pdfAvalos-Katherine-Investigacion.pdf
Avalos-Katherine-Investigacion.pdfFabio506452
 
CreditosHipotecarios.pdf
CreditosHipotecarios.pdfCreditosHipotecarios.pdf
CreditosHipotecarios.pdfFabio506452
 
Archivo fotografico FC Santa Fe
Archivo fotografico FC Santa FeArchivo fotografico FC Santa Fe
Archivo fotografico FC Santa FeFabio506452
 

Más de Fabio506452 (12)

Lo_real_y_lo_virtual_-_Tomas_Maldonado.pdf
Lo_real_y_lo_virtual_-_Tomas_Maldonado.pdfLo_real_y_lo_virtual_-_Tomas_Maldonado.pdf
Lo_real_y_lo_virtual_-_Tomas_Maldonado.pdf
 
Defensa Garello
Defensa GarelloDefensa Garello
Defensa Garello
 
Infografia Cambio de hábitos
Infografia Cambio de hábitosInfografia Cambio de hábitos
Infografia Cambio de hábitos
 
Robotica 2 Actividad 1.pdf
Robotica 2 Actividad  1.pdfRobotica 2 Actividad  1.pdf
Robotica 2 Actividad 1.pdf
 
Alfabetización Academica
Alfabetización AcademicaAlfabetización Academica
Alfabetización Academica
 
Tutorial - Cómo ingresar al aula
Tutorial - Cómo ingresar al aulaTutorial - Cómo ingresar al aula
Tutorial - Cómo ingresar al aula
 
Entre lo sólido y lo espectral
Entre lo sólido y lo espectralEntre lo sólido y lo espectral
Entre lo sólido y lo espectral
 
Cajas Navideñas
Cajas NavideñasCajas Navideñas
Cajas Navideñas
 
Santa Fe Hace un siglo
Santa Fe Hace un sigloSanta Fe Hace un siglo
Santa Fe Hace un siglo
 
Avalos-Katherine-Investigacion.pdf
Avalos-Katherine-Investigacion.pdfAvalos-Katherine-Investigacion.pdf
Avalos-Katherine-Investigacion.pdf
 
CreditosHipotecarios.pdf
CreditosHipotecarios.pdfCreditosHipotecarios.pdf
CreditosHipotecarios.pdf
 
Archivo fotografico FC Santa Fe
Archivo fotografico FC Santa FeArchivo fotografico FC Santa Fe
Archivo fotografico FC Santa Fe
 

Último

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 

Último (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 

Introduction to Coding

  • 2. Part I: Introduction • About codeguppy.com • Creating accounts in codeguppy.com • Environment overview Part II: Steps into coding • Drag and drop coding • Drawing with code • Animations Agenda
  • 3. codeguppy.com About codeguppy.com • Online coding platform for kids, teens and code newbies • Text-based coding • JavaScript language • Based on p5.js (Processing API) • Code animations, games and other fun programs • Built-in assets (backgrounds, sprites, etc.) • Tons of projects. Browse – Remix – Share • Free!
  • 4. Why learn JavaScript? • JavaScript is a super-popular real-world programming language used both by beginners but also by professional software developers. (The entire codeguppy.com was coded in JavaScript) • People use JavaScript to build websites, online games and do creative coding. On codeguppy.com, you can use JavaScript to draw with code, implement animations, build games and other fun projects. • Coding in a text-based language such as JavaScript has also other benefits beyond the world of programming. It enhances problem- solving skills but also attention to details.
  • 5. Programming is like writing a book... … except if you miss out a single comma on page 349 the whole thing you wrote makes no sense. - Anonymous
  • 6. codeguppy.com Let’s open an account with codeguppy.com • codeguppy.com gives you unlimited space in the cloud to write and store tons of programs • But first you need to open an account with codeguppy.com • You need to provide a valid email address and a password (website doesn’t ask any other personal details) Note: After registration, you should get an email from codeguppy.com. Please verify your email by clicking the link in the email. JOIN FOR FREE Email: Password: REGISTER NOW Register with email 1 2 3
  • 7. Code Editor Type here your program Assets Toolbar Browse sprite library, colors, etc. Run / Stop Button Run or Stop your program. Output Canvas Here you’ll see the output of your program.
  • 9. Let’s play with built-in assets sprite('adventure_girl.idle', 400, 300, 0.5); sprite('knight.idle', 400, 300, 0.5); You don’t have to write the above code. Just drag and drop a sprite from the palette in the code editor to have this code generated for you.
  • 10. music('Fun Background'); background('Field'); sprite('plane.fly', 400, 300, 0.5); Build a program using drag-and-drop Step 1: Drag and drop a music file Step 2: Drag and drop a background image or color Step 3: Drag and drop a sprite Press “Play” when ready.
  • 11. Built-in instruction that asks computer to display a sprite on the canvas. The actual sprite is specified in between quotes inside the parenthesis as a “parameter”. Parameters of the instruction. Parameters specify what sprite to display, where to display it on the canvas and at what coordinates. Experiment: Try to change the 400 and 300 numbers with other numbers between 0 and 800. Press “Play” / “Stop” after each modification to run / stop the program. sprite('adventure_girl.idle', 400, 300, 0.5);
  • 12. • Programs can write and draw on a graphical canvas of 800x600 pixels • Origin is in the top-left corner • Middle of the canvas is at about (400, 300) • x coordinate goes from 0 to 800 (left to right) • y coordinate goes from 0 to 600 (top to bottom) (400, 300) Output canvas
  • 13. Our first type-in program circle(400, 300, 300); • Type carefully this line in the code editor. • Make sure you use the same casing as illustrated and include all the punctuation signs. • When ready, press the Play / Run button
  • 14. circle(400, 300, 300); Built-in instruction that asks computer to draw a circle on the canvas. codeguppy.com has many built- in instructions for different purposes (remember the sprite instruction used before). Parameters of the instruction. There are 3 parameters inside parenthesis and separated by comma: - 400, 300 - coordinates of circle center - 300 – radius of the circle Try to modify the parameters of this instruction and notice the effect. Don’t forget to press “Play” / “Stop” after each modification.
  • 15. codeguppy.com/code.html // Draw bear face circle(400, 300, 200); // Draw left ear circle(250, 100, 50); circle(270, 122, 20); // Draw right ear circle(550, 100, 50); circle(530, 122, 20); // Draw left eye circle(300, 220, 30); circle(315, 230, 10); // Draw right eye circle(500, 220, 30); circle(485, 230, 10); // Draw nose circle(400, 400, 90); circle(400, 350, 20); Multiple instructions in a program
  • 16. Other graphical instructions circle(400, 300, 200); ellipse(400, 300, 300, 200); rect(400, 300, 300, 200); line(400, 300, 500, 500); triangle(400, 100, 200, 400, 600, 500); arc(400, 300, 300, 200, 0, 180); point(400, 300); text('JavaScript', 400, 300); JavaScript (400, 300) 200 (400, 300) 300 200 (400, 300) 300 200 (400, 300) (500, 500) (200, 400) (600, 500) (400, 100) (400, 300) (400, 300) (400, 300)
  • 17. Practicing graphical instructions • Exercise 1: On a blank piece of paper draw an object / scene using only basic shapes such as circles, lines, rectangles. Convert that drawing into code! OR • Exercise 2: Download the “Draw with code” booklet from the downloads section. Choose any drawing, print the page and type-in the program. Note: Programs from the “Draw with code” booklet may have more instructions then presented here. Try to discover their purpose.
  • 18. Introducing variables let r = 100; let r2 = 100 - 4; circle(100, 100, r); circle(100, 100, r2); OR • JavaScript allows users to define variables to hold various values or the result of complex calculations • You can name variables however you prefer… but don’t start them with number or weird symbols • Variables are super important in programming
  • 19. Expressions and variables instead of scalars circle(100, 100, 100); circle(100, 100, 96); You can let the computer do calculations. At the end of the day, your computer is also a powerful calculator. circle(100, 100, 100); circle(100, 100, 100 - 4); let r2 = 100 – 4; circle(100, 100, 100); circle(100, 100, r2);
  • 20. Building our own custom instructions circle2(); function circle2() { circle(100, 100, 100); circle(100, 100, 100 - 4); } • We placed the two circle instructions inside a code block (delimited by curly brackets) • The block is the body of function circle2. Notice carefully the syntax. • The function circle2 is our new custom instructions. However, exactly like circle, it doesn’t do anything until we call it. 1 2 3 1 2 3
  • 21. Functions with parameters circle2(400, 300, 100); function circle2(x, y, r) { circle(x, y, r); circle(x, y, r - 4); } Now this is a useful function! It can be used to draw a double-circle on the canvas. We can control the position and radius of the double circle! Exercise: Design your own custom instruction (e.g. function) to draw something useful.
  • 22. Modularizing code with functions • Functions can also be used to modularize big pieces of code into smaller pieces • The smaller pieces can then be assembled or reused exactly like Lego pieces Exercise: Copy or type-in the “Car” program from the “Draw with code” booklet / playground. If you typed everything correctly you should see the following drawing when running the program.
  • 23. Modularizing the code function background() { // Background noStroke(); fill(180, 199, 231); rect(0, 0, 800, 500); fill(191, 144, 0); rect(0, 500, 800, 100); } function sun() { // Sun fill("yellow"); circle(750, 50, 150); stroke("yellow"); strokeWeight(6); line(480, 60, 561, 47); line(548, 224, 602, 172); line(740, 304, 747, 236); } function car() { // Car stroke("black"); strokeWeight(1); fill(112, 173, 71); rect(175, 340, 223, 54); rect(108, 394, 362, 74); fill(132,60,12); circle(168, 468, 32); circle(408, 468, 32); } background(); sun(); car(); This is main body of our new program. Of course, this program calls the specified functions. In big programs, functions can be moved outside the main program in external module or libraries.
  • 24. Defining loop() function function background() { ... } function sun() { ... } function car() { ... } function loop() { background(); sun(); car(); } • loop() is a special function. • We don’t have to call it. • The system will call it automatically about 60 times / second.
  • 25. Parametrize car() function car(108); function car(x) { // Car stroke("black"); strokeWeight(1); fill(112, 173, 71); rect(x + 67, 340, 223, 54); rect(x, 394, 362, 74); fill(132,60,12); circle(x + 60, 468, 32); circle(x + 300, 468, 32); } We’ll update function car() to accept a parameter x representing the x coordinate where the car will be drawn.
  • 26. x = 108 x = 400 x = 650 … … function loop() { Step 1: Clear the frame Step 2: Redraw the scene and car at position x Step 3: Increase position x by 1 } Animations
  • 27. Increasing / decreasing variables x++; x += 1; x = x + 1; x--; x -= 1; x = x - 1; Increasing the value Decreasing the value Note: x++ and x-- forms always modify the value by 1. The other forms can be used to modify the value by an arbitrary amount. OR OR OR OR
  • 28. let x = 0; function loop() { clear(); background(); sun(); car(x); x++; } function car(x) { // Car stroke("black"); strokeWeight(1); fill(112, 173, 71); rect(x + 67, 340, 223, 54); rect(x, 394, 362, 74); fill(132,60,12); circle(x + 60, 468, 32); circle(x + 300, 468, 32); } function background() { // Background noStroke(); fill(180, 199, 231); rect(0, 0, 800, 500); fill(191, 144, 0); rect(0, 500, 800, 100); } function sun() { // Sun fill("yellow"); circle(750, 50, 150); stroke("yellow"); strokeWeight(6); line(480, 60, 561, 47); line(548, 224, 602, 172); line(740, 304, 747, 236); } Program listing
  • 29. Next steps • Complete the exercises presented today. Don’t be frustrated if you’ll encounter errors. Coding required lots of practice until you get comfortable writing programs. • When working on a program, try to run the program from time to time to avoid accumulation of errors. • Explore the other tutorials and projects from the codeguppy.com website and don’t forget to visit also the downloads section. Algorithms More… Games Animations