0% found this document useful (0 votes)
17 views1 page

Pseudocode

Pseudocode is an English-like representation of a simplified programming language that is used to design and communicate algorithms in a way that is understandable to programmers regardless of their specific programming language. It avoids the syntax details of real code but shows the structure of program elements like loops, decisions, variables, and parameter passing. The exact details are left to the programmer during implementation.

Uploaded by

tedzone9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

Pseudocode

Pseudocode is an English-like representation of a simplified programming language that is used to design and communicate algorithms in a way that is understandable to programmers regardless of their specific programming language. It avoids the syntax details of real code but shows the structure of program elements like loops, decisions, variables, and parameter passing. The exact details are left to the programmer during implementation.

Uploaded by

tedzone9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Pseudocode

Pseudocode is an English-like representation of a simplified programming


language. It is used in planning to design and communicate algorithms in a way
that doesn’t get bogged down with the detail of syntax and that programmers
from any language can understand. It’s not real code, but it does show the
structure of loops, decisions, passing parameters and working with variables.
Leave the exact detail up to the programmer in the Implementing phase.

Hello world Linear search


REM This prints “Hello World” BEGIN findBiggest(array)
PRINT “Hello Word” REM Returns the biggest value in an array (0 if empty)
IF array.length>0 THEN
Biggest of 2 numbers biggest=array(0)
BEGIN biggest(num1, num2) FOR i=1 to array.length-1
REM Returns the biggest of 2 numbers IF array(i) > biggest THEN
IF num1 > num2 THEN BIGGEST = array(i)
biggest = num1 END IF
ELSE NEXT i
biggest = num2 RETURN biggest
END IF ELSE
RETURN biggest RETURN 0
END IF END IF
END

Processing program: Mouse tail


This program uses an array to record the last 100 x,y positions that the mouse has been to. Each position is a record which combines two integer fields – x
& y. There are 100 of these records in an array called positions. See what happens if you change the number of items in the array. Challenge yourself by
adding a fill colour to the position record and then drawing the mouse trail in the draw loop, so that each item in the array continually loses colour until the
fill colour is 0.

BEGIN
This is mostly just a pseudocode description of how
Define a ‘position’ record as
all Processing programs work – when they start
int x,y;
they define any global variables, run the setup()
Initialise ‘positions’ as an array of 50 position records
procedure, then they keep running the draw()
procedure as a loop until the program is stopped.
setup()
WHILE true
Notice the definition of the position record data
draw()
structure and the array of 50 positions before
END WHILE
setup
END
BEGIN setup()
Set the screen size to 500, 500
FOR i=0 to positions.length-1 STEP 1
positions(i) = new position();
positions(i).x = 0 This FOR loop iterates through all of the items in the positions array
positions(i).y = 0 and sets their initial values to 0
NEXT i
END setup

You don’t actually need any code in the draw loop


BEGIN draw()
for this program as all the logic happens when the
REM No code needed - processing done in mouseMoved()
mouse moves. You do, however, need to include it
END draw
otherwise Processing gets upset 

BEGIN mouseMoved()
Set the background colour to 0
FOR i=0 to positions.length-2 STEP 1
Set the ith position’s x value to the (i+1)th position’s x value
A FOR loop to shuffle the
Set the ith position’s y value to the (i+1)th position’s y value
values in the array along by 1
Set the fill colour to i
Draw an ellipse at the ith position’s x & y values
NEXT i
positions[positions.length-1].x=mouseX; Store the current mouse position
positions[positions.length-1].y=mouseY; in the last record of the array.
END mouseMoved

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy