├── .gitattributes ├── 1 - conditions ├── conditions.md └── figs │ ├── bouncyBall.png │ ├── buggyCode.png │ ├── correctIfElse.png │ ├── flawedIfElse.png │ ├── ifCondition.png │ ├── ifElseCondition.png │ ├── ifElseExample.png │ ├── ifExample.png │ ├── nestedIfElseExercise.png │ └── original │ ├── bouncyBall.png │ ├── correctIfElse.png │ ├── flawedIfElse.png │ ├── ifCondition.png │ ├── ifElseCondition.png │ ├── ifElseExample.png │ ├── ifExample.png │ └── nestedIfElseExercise.png ├── 2 - loops ├── figs │ ├── forExample.png │ ├── forLoop.png │ ├── genericDecrementalLoop.png │ ├── genericIncrementalLoop.png │ ├── typicalLoop1toN.png │ ├── typicalLoopNto1.png │ ├── whatWillThisDo.png │ ├── whileExample.png │ └── whileLoop.png └── loops.md ├── 3 - functions ├── figs │ ├── functionMemoryDiagrams-figure0.png │ ├── functionMemoryDiagrams-figure1.png │ ├── functionMemoryDiagrams-figure2.png │ ├── functionMemoryDiagrams-figure3.png │ ├── functionMemoryDiagrams-figure4.png │ ├── functionMemoryDiagrams-figure5.png │ ├── functionMemoryDiagrams-figure6.png │ └── functionMemoryDiagrams.tex └── functions.md ├── 4 - arrays ├── .texpadtmp │ ├── arrays-figure0.md5 │ ├── arrays-figure1.md5 │ ├── arrays-figure10.md5 │ ├── arrays-figure2.md5 │ ├── arrays-figure3.md5 │ ├── arrays-figure4.md5 │ ├── arrays-figure5.md5 │ ├── arrays-figure6.md5 │ ├── arrays-figure7.md5 │ ├── arrays-figure8.md5 │ ├── arrays-figure9.md5 │ ├── arrays.aux │ ├── arrays.auxlock │ ├── arrays.log │ ├── arrays.out │ └── arrays.synctex.gz ├── arrays.md └── figs │ ├── arrays-figure0.dpth │ ├── arrays-figure0.log │ ├── arrays-figure0.png │ ├── arrays-figure1.dpth │ ├── arrays-figure1.log │ ├── arrays-figure1.png │ ├── arrays-figure2.dpth │ ├── arrays-figure2.log │ ├── arrays-figure2.png │ ├── arrays-figure3.dpth │ ├── arrays-figure3.log │ ├── arrays-figure3.png │ ├── arrays-figure4.dpth │ ├── arrays-figure4.log │ ├── arrays-figure4.png │ ├── arrays-figure5.dpth │ ├── arrays-figure5.log │ ├── arrays-figure5.png │ ├── arrays-figure6.dpth │ ├── arrays-figure6.log │ ├── arrays-figure6.png │ ├── arrays-figure7.dpth │ ├── arrays-figure7.log │ ├── arrays-figure7.png │ └── arrays.tex ├── 5 - arrays and functions ├── .texpadtmp │ ├── arraysAndFunctionMemoryDiagrams-figure0.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure1.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure2.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure3.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure4.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure5.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure6.md5 │ ├── arraysAndFunctionMemoryDiagrams.aux │ ├── arraysAndFunctionMemoryDiagrams.auxlock │ ├── arraysAndFunctionMemoryDiagrams.log │ ├── arraysAndFunctionMemoryDiagrams.out │ └── arraysAndFunctionMemoryDiagrams.synctex.gz ├── arraysAndFunctions.md └── figs │ ├── arraysAndFunctionMemoryDiagrams-figure0.dpth │ ├── arraysAndFunctionMemoryDiagrams-figure0.log │ ├── arraysAndFunctionMemoryDiagrams-figure0.png │ ├── arraysAndFunctionMemoryDiagrams-figure1.dpth │ ├── arraysAndFunctionMemoryDiagrams-figure1.log │ ├── arraysAndFunctionMemoryDiagrams-figure1.png │ ├── arraysAndFunctionMemoryDiagrams-figure2.dpth │ ├── arraysAndFunctionMemoryDiagrams-figure2.log │ ├── arraysAndFunctionMemoryDiagrams-figure2.png │ └── arraysAndFunctionMemoryDiagrams.tex ├── 6 - problem solving ├── .texpadtmp │ ├── arraysAndFunctionMemoryDiagrams-figure0.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure1.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure2.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure3.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure4.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure5.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure6.md5 │ ├── arraysAndFunctionMemoryDiagrams.aux │ ├── arraysAndFunctionMemoryDiagrams.auxlock │ ├── arraysAndFunctionMemoryDiagrams.log │ ├── arraysAndFunctionMemoryDiagrams.out │ └── arraysAndFunctionMemoryDiagrams.synctex.gz └── problemSolving.md ├── 7 - strings (optional) ├── .texpadtmp │ ├── arraysAndFunctionMemoryDiagrams-figure0.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure1.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure2.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure3.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure4.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure5.md5 │ ├── arraysAndFunctionMemoryDiagrams-figure6.md5 │ ├── arraysAndFunctionMemoryDiagrams.aux │ ├── arraysAndFunctionMemoryDiagrams.auxlock │ ├── arraysAndFunctionMemoryDiagrams.log │ ├── arraysAndFunctionMemoryDiagrams.out │ └── arraysAndFunctionMemoryDiagrams.synctex.gz └── strings.md ├── PVector.md ├── README.md ├── arrayOfPVectorObjects.md ├── comments.md └── revisionPackage ├── COMP115QuestionBank.zip ├── COMP115QuestionBank ├── questions │ ├── 01operatorsExpressions.pdf │ ├── 02conditions.pdf │ ├── 03loops.pdf │ ├── 04functions1.pdf │ ├── 05arrays.pdf │ ├── 06functions2.pdf │ └── 07strings.pdf └── solutions │ ├── 01operatorsExpressionsSolutions.pdf │ ├── 02conditionsSolutions.pdf │ ├── 03loopsSolutions.pdf │ ├── 04functions1Solutions.pdf │ ├── 05arraysSolutions.pdf │ ├── 06functions2Solutions.pdf │ └── 07stringsSolutions.pdf ├── comp115practicePrograms ├── A&SPracticePackage │ ├── MultiDimensionArrays │ │ ├── 1chessBoardHighlight │ │ │ ├── chessBoardHighlightSolution │ │ │ │ └── chessBoardHighlightSolution.pde │ │ │ └── chessBoardHighlightTemplate │ │ │ │ └── chessBoardHighlightTemplate.pde │ │ ├── 2rowsAndColumns │ │ │ ├── rowsAndColumnsOutput.png │ │ │ ├── rowsAndColumnsSolution │ │ │ │ └── rowsAndColumnsSolution.pde │ │ │ └── rowsAndColumnsTemplate │ │ │ │ └── rowsAndColumnsTemplate.pde │ │ ├── 3split │ │ │ ├── splitSolution │ │ │ │ └── splitSolution.pde │ │ │ └── splitTemplate │ │ │ │ └── splitTemplate.pde │ │ └── 4intersection │ │ │ ├── intersectionSolution │ │ │ └── intersectionSolution.pde │ │ │ └── intersectionTemplate │ │ │ └── intersectionTemplate.pde │ ├── OneDimensionArrays │ │ ├── 10onlyLowercase │ │ │ ├── onlyLowercaseSolution │ │ │ │ └── onlyLowercaseSolution.pde │ │ │ └── onlyLowercaseTemplate │ │ │ │ └── onlyLowercaseTemplate.pde │ │ ├── 11difference │ │ │ ├── differenceSolution │ │ │ │ └── differenceSolution.pde │ │ │ └── differenceTemplate │ │ │ │ └── differenceTemplate.pde │ │ ├── 12halfArray │ │ │ ├── halfArraySolution │ │ │ │ └── halfArraySolution.pde │ │ │ └── halfArrayTemplate │ │ │ │ └── halfArrayTemplate.pde │ │ ├── 13decreasing │ │ │ ├── decreasingSolution │ │ │ │ └── decreasingSolution.pde │ │ │ └── decreasingTemplate │ │ │ │ └── decreasingTemplate.pde │ │ ├── 14indexes │ │ │ ├── indexesSolution │ │ │ │ └── indexesSolution.pde │ │ │ └── indexesTemplate │ │ │ │ └── indexesTemplate.pde │ │ ├── 15mostCommon │ │ │ ├── mostCommonSolution │ │ │ │ └── mostCommonSolution.pde │ │ │ └── mostCommonTemplate │ │ │ │ └── mostCommonTemplate.pde │ │ ├── 16drawStacks │ │ │ ├── case1.PNG │ │ │ ├── case2.PNG │ │ │ ├── case3.PNG │ │ │ ├── drawStacksSolution │ │ │ │ └── drawStacksSolution.pde │ │ │ └── drawStacksTemplate │ │ │ │ └── drawStacksTemplate.pde │ │ ├── 1lines │ │ │ ├── linesSolution │ │ │ │ └── linesSolution.pde │ │ │ └── linesTemplate │ │ │ │ └── linesTemplate.pde │ │ ├── 2createArrayFunction │ │ │ ├── createArrayFunctionSolution │ │ │ │ └── createArrayFunctionSolution.pde │ │ │ └── createArrayFunctionTemplate │ │ │ │ └── createArrayFunctionTemplate.pde │ │ ├── 3patterns │ │ │ ├── patternsSolution │ │ │ │ └── patternsSolution.pde │ │ │ └── patternsTemplate │ │ │ │ └── patternsTemplate.pde │ │ ├── 4middleElement │ │ │ ├── middleElementSolution │ │ │ │ └── middleElementSolution.pde │ │ │ └── middleElementTemplate │ │ │ │ └── middleElementTemplate.pde │ │ ├── 5average │ │ │ ├── averageSolution │ │ │ │ └── averageSolution.pde │ │ │ └── averageTemplate │ │ │ │ └── averageTemplate.pde │ │ ├── 6sumEvenIndex │ │ │ ├── sumEvenIndexSolution │ │ │ │ └── sumEvenIndexSolution.pde │ │ │ └── sumEvenIndexTemplate │ │ │ │ └── sumEvenIndexTemplate.pde │ │ ├── 7sumPosNeg │ │ │ ├── sumPosNegSolution │ │ │ │ └── sumPosNegSolution.pde │ │ │ └── sumPosNegTemplate │ │ │ │ └── sumPosNegTemplate.pde │ │ ├── 8findElement │ │ │ ├── findElementSolution │ │ │ │ └── findElementSolution.pde │ │ │ └── findElementTemplate │ │ │ │ └── findElementTemplate.pde │ │ └── 9compare │ │ │ ├── compareSolution │ │ │ └── compareSolution.pde │ │ │ └── compareTemplate │ │ │ └── compareTemplate.pde │ └── Strings │ │ ├── 2extract │ │ ├── extractSolution │ │ │ └── extractSolution.pde │ │ └── extractTemplate │ │ │ └── extractTemplate.pde │ │ ├── 3splitToArray │ │ ├── splitToArraySolution │ │ │ └── splitToArraySolution.pde │ │ └── splitToArrayTemplate │ │ │ └── splitToArrayTemplate.pde │ │ ├── 4isReverse │ │ ├── isReverseSolution │ │ │ └── isReverseSolution.pde │ │ └── isReverseTemplate │ │ │ └── isReverseTemplate.pde │ │ ├── withoutVowelSolution │ │ └── withoutVowelSolution.pde │ │ └── withoutVowelTemplate │ │ └── withoutVowelTemplate.pde ├── conditionsPracticePackage │ ├── 10twoButtons │ │ ├── twoButtonsOutput.mp4 │ │ └── twoButtonsSolution │ │ │ └── twoButtonsSolution.pde │ ├── 11rebound │ │ ├── reboundOutput.mp4 │ │ └── reboundSolution │ │ │ └── reboundSolution.pde │ ├── 12flickr │ │ ├── flickrOutput.mp4 │ │ └── flickrSolution │ │ │ └── flickrSolution.pde │ ├── 1fade │ │ ├── fadeOutput.mp4 │ │ └── fadeSolution │ │ │ └── fadeSolution.pde │ ├── 2leftRight │ │ ├── leftRightOutput.mp4 │ │ └── leftRightSolution │ │ │ └── leftRightSolution.pde │ ├── 3circleShrinkGrow │ │ ├── circleShrinkGrowOutput.mp4 │ │ └── circleShrinkGrowSolution │ │ │ └── circleShrinkGrowSolution.pde │ ├── 4increasingDiameter │ │ ├── increasingDiameterOutput.mp4 │ │ └── increasingDiameterSolution │ │ │ └── increasingDiameterSolution.pde │ ├── 5highlight │ │ ├── highlightOutput.mp4 │ │ └── highlightSolution │ │ │ └── highlightSolution.pde │ ├── 6shapeChange │ │ ├── shapeChangeOutput.mp4 │ │ └── shapeChangeSolution │ │ │ └── shapeChangeSolution.pde │ ├── 7alongBorder │ │ ├── alongBorderOutput.mp4 │ │ └── alongBorderSolution │ │ │ └── alongBorderSolution.pde │ ├── 8changingBackground │ │ ├── changingBackgroundOutput.mp4 │ │ └── changingBackgroundSolution │ │ │ └── changingBackgroundSolution.pde │ ├── 9button │ │ ├── buttonOutput.mp4 │ │ └── buttonSolution │ │ │ └── buttonSolution.pde │ └── questions.txt ├── functionsPracticePackage │ ├── 10drawBorders3Param │ │ ├── drawBorders3ParamOutput.png │ │ ├── drawBorders3ParamSolution │ │ │ └── drawBorders3ParamSolution.pde │ │ └── drawBorders3ParamTemplate │ │ │ └── drawBorders3ParamTemplate.pde │ ├── 11drawBorders4Param │ │ ├── drawBorders4ParamOutput.png │ │ ├── drawBorders4ParamSolution │ │ │ └── drawBorders4ParamSolution.pde │ │ └── drawBorders4ParamTemplate │ │ │ └── drawBorders4ParamTemplate.pde │ ├── 12countDigits │ │ ├── countDigitsSolution │ │ │ └── countDigitsSolution.pde │ │ └── countDigitsTemplate │ │ │ └── countDigitsTemplate.pde │ ├── 13sumDigits │ │ ├── sumDigitsSolution │ │ │ └── sumDigitsSolution.pde │ │ └── sumDigitsTemplate │ │ │ └── sumDigitsTemplate.pde │ ├── 14highestDigit │ │ ├── highestDigitSolution │ │ │ └── highestDigitSolution.pde │ │ └── highestDigitTemplate │ │ │ └── highestDigitTemplate.pde │ ├── 15lowestDigit │ │ ├── lowestDigitSolution │ │ │ └── lowestDigitSolution.pde │ │ └── lowestDigitTemplate │ │ │ └── lowestDigitTemplate.pde │ ├── 16getDigit │ │ ├── getDigitSolution │ │ │ └── getDigitSolution.pde │ │ └── getDigitTemplate │ │ │ └── getDigitTemplate.pde │ ├── 17drawStickFigure │ │ ├── drawStickFigureSolution │ │ │ └── drawStickFigureSolution.pde │ │ └── drawStickFigureTemplate │ │ │ └── drawStickFigureTemplate.pde │ ├── 18power │ │ ├── powerSolution │ │ │ └── powerSolution.pde │ │ └── powerTemplate │ │ │ └── powerTemplate.pde │ ├── 19factorial │ │ ├── factorialSolution │ │ │ └── factorialSolution.pde │ │ └── factorialTemplate │ │ │ └── factorialTemplate.pde │ ├── 1square │ │ ├── squareSolution │ │ │ └── squareSolution.pde │ │ └── squareTemplate │ │ │ └── squareTemplate.pde │ ├── 2isEven │ │ ├── isEvenSolution │ │ │ └── isEvenSolution.pde │ │ └── isEvenTemplate │ │ │ └── isEvenTemplate.pde │ ├── 3isPositive │ │ ├── isPositiveSolution │ │ │ └── isPositiveSolution.pde │ │ └── isPositiveTemplate │ │ │ └── isPositiveTemplate.pde │ ├── 4isDigit │ │ ├── isDigitSolution │ │ │ └── isDigitSolution.pde │ │ └── isDigitTemplate │ │ │ └── isDigitTemplate.pde │ ├── 5higher │ │ ├── higherSolution │ │ │ └── higherSolution.pde │ │ └── higherTemplate │ │ │ └── higherTemplate.pde │ ├── 6highest │ │ ├── highestSolutoin │ │ │ └── highestSolutoin.pde │ │ └── highestTemplate │ │ │ └── highestTemplate.pde │ ├── 7average │ │ ├── averageSolution │ │ │ └── averageSolution.pde │ │ └── averageTemplate │ │ │ └── averageTemplate.pde │ ├── 8drawBorders1Param │ │ ├── drawBorders1ParamSolution │ │ │ └── drawBorders1ParamSolution.pde │ │ └── drawBorders1ParamTemplate │ │ │ └── drawBorders1ParamTemplate.pde │ ├── 9drawBorders2Param │ │ ├── drawBorders2ParamOutput.png │ │ ├── drawBorders2ParamSolution │ │ │ └── drawBorders2ParamSolution.pde │ │ └── drawBorders2ParamTemplate │ │ │ └── drawBorders2ParamTemplate.pde │ └── ToDo.txt ├── loopsPracticePackage │ ├── 10circlesBorder │ │ ├── circleBorderSolution │ │ │ └── circleBorderSolution.pde │ │ └── circlesBorderOutput.png │ ├── 11fibonacci │ │ ├── fibonacciOutput.png │ │ └── fibonacciSolution │ │ │ └── fibonacciSolution.pde │ ├── 12linesFromCorner │ │ ├── linesFromCornerOutput.png │ │ └── linesFromCornerSolution │ │ │ └── linesFromCornerSolution.pde │ ├── 13divisors │ │ ├── divisorsOutput.png │ │ └── divisorsSolution │ │ │ └── divisorsSolution.pde │ ├── 14gcd │ │ ├── gcdOutput.png │ │ └── gcdSolution │ │ │ └── gcdSolution.pde │ ├── 15circleGrid │ │ ├── circleGridOutput.png │ │ └── circleGridSolution │ │ │ └── circleGridSolution.pde │ ├── 16circleStaggered1 │ │ ├── circleStaggered1Output.png │ │ └── circleStaggered1Solution │ │ │ └── circleStaggered1Solution.pde │ ├── 17circleStaggered2 │ │ ├── circleStaggered2Output.png │ │ └── circleStaggered2Solution │ │ │ └── circleStaggered2Solution.pde │ ├── 18primeNumbers │ │ ├── primeNumbersOutput.png │ │ └── primeNumbersSolution │ │ │ └── primeNumbersSolution.pde │ ├── 19brickWall │ │ ├── brickWallOutput.png │ │ └── brickWallSolution │ │ │ └── brickWallSolution.pde │ ├── 1verticalLines │ │ ├── verticalLinesOutput.png │ │ └── verticalLinesSolution │ │ │ └── verticalLinesSolution.pde │ ├── 20circles │ │ ├── circlesOutput.png │ │ └── circlesSolution │ │ │ └── circlesSolution.pde │ ├── 2horizontalLines │ │ ├── horizontalLinesOutput.png │ │ └── horizontalLinesSolution │ │ │ └── horizontalLinesSolution.pde │ ├── 3alternatingColours │ │ ├── alternatingColoursOutput.png │ │ └── alternatingColoursSolution │ │ │ └── alternatingColoursSolution.pde │ ├── 4alternatingLines │ │ ├── alternatingLinesOutput.png │ │ └── alternatingLinesSolution │ │ │ └── alternatingLinesSolution.pde │ ├── 5numDigits │ │ ├── numDigitsOutput.png │ │ └── numDigitsSolution │ │ │ └── numDigitsSolution.pde │ ├── 6sumOddDigits │ │ ├── sumOddDigitsOutput.png │ │ └── sumOddDigitsSolution │ │ │ └── sumOddDigitsSolution.pde │ ├── 7triangles │ │ ├── trianglesOutput.png │ │ └── trianglesSolution │ │ │ └── trianglesSolution.pde │ ├── 8circlesAcross │ │ ├── circlesAcrossOutput.png │ │ └── circlesAcrossSolution │ │ │ └── circlesAcrossSolution.pde │ ├── 9circlesAcrossRandom │ │ ├── circlesAcrossRandomOutput.png │ │ └── circlesAcrossRandomSolution │ │ │ └── circlesAcrossRandomSolution.pde │ └── Questions.txt └── pixelsVariablesPracticePackage │ ├── 10triggeredAnimationMultipleAttributes │ ├── triggeredAnimationMultipleAttributesOutput.mp4 │ └── triggeredAnimationMultipleAttributesSolution │ │ └── triggeredAnimationMultipleAttributesSolution.pde │ ├── 11triggeredAnimationMultipleObjects │ ├── triggeredAnimationMultipleObjectsOutput.mp4 │ └── triggeredAnimationMultipleObjectsSolution │ │ └── triggeredAnimationMultipleObjectsSolution.pde │ ├── 1solidVennDiagram │ ├── solidVennDiagramOutput.png │ └── solidVennDiagramSolution │ │ └── solidVennDiagramSolution.pde │ ├── 2translucentVennDiagram │ ├── translucentVennDiagramOutput.png │ └── translucentVennDiagramSolution │ │ └── translucentVennDiagramSolution.pde │ ├── 3allShapesColors │ ├── allShapesColorsOutput.png │ └── allShapesColorsSolution │ │ └── allShapesColorsSolution.pde │ ├── 4animation │ ├── animation.mp4 │ └── animation │ │ └── animation.pde │ ├── 5animation │ ├── compositeAnimation.mp4 │ └── compositeAnimation │ │ └── compositeAnimation.pde │ ├── 6incrementalAnimation │ ├── incrementalAnimation.mp4 │ ├── incrementalAnimation │ │ └── incrementalAnimation.pde │ └── incrementalAnimationTemplate │ │ └── incrementalAnimationTemplate.pde │ ├── 7oneOffAnimation │ ├── oneOffAnimationOutput.mp4 │ └── oneOffAnimationSolution │ │ └── oneOffAnimationSolution.pde │ ├── 8triggeredAnimation │ ├── triggeredAnimationOutput.mp4 │ └── triggeredAnimationSolution │ │ └── triggeredAnimationSolution.pde │ ├── 9triggeredAnimation │ ├── growingCircleAnimation.mp4 │ └── growingCircleAnimationSolution │ │ └── growingCircleAnimationSolution.pde │ └── instructionsPV.txt ├── comp125startingQuiz ├── COMP125_week_1_revision_questions.pdf └── COMP125_week_1_revision_solutions.pdf └── sourceFilesForTeachingStaff ├── revisionCOMP115 ├── 01operators.pdf ├── 01operators.tex ├── 02conditions.tex ├── 03loops.tex ├── 04functions1.tex ├── 05arrays.tex ├── 06functions2.tex ├── 07strings.tex ├── 125_week_1_revision.tex ├── comp115questionBank.tex ├── questionHeader.tex └── solutionHeader.tex └── revisionCOMP125 ├── comp125questionBank.pdf ├── comp125questionBank.tex ├── comp125questions.pdf └── comp125solutions.pdf /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /1 - conditions/figs/bouncyBall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/bouncyBall.png -------------------------------------------------------------------------------- /1 - conditions/figs/buggyCode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/buggyCode.png -------------------------------------------------------------------------------- /1 - conditions/figs/correctIfElse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/correctIfElse.png -------------------------------------------------------------------------------- /1 - conditions/figs/flawedIfElse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/flawedIfElse.png -------------------------------------------------------------------------------- /1 - conditions/figs/ifCondition.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/ifCondition.png -------------------------------------------------------------------------------- /1 - conditions/figs/ifElseCondition.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/ifElseCondition.png -------------------------------------------------------------------------------- /1 - conditions/figs/ifElseExample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/ifElseExample.png -------------------------------------------------------------------------------- /1 - conditions/figs/ifExample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/ifExample.png -------------------------------------------------------------------------------- /1 - conditions/figs/nestedIfElseExercise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/nestedIfElseExercise.png -------------------------------------------------------------------------------- /1 - conditions/figs/original/bouncyBall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/original/bouncyBall.png -------------------------------------------------------------------------------- /1 - conditions/figs/original/correctIfElse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/original/correctIfElse.png -------------------------------------------------------------------------------- /1 - conditions/figs/original/flawedIfElse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/original/flawedIfElse.png -------------------------------------------------------------------------------- /1 - conditions/figs/original/ifCondition.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/original/ifCondition.png -------------------------------------------------------------------------------- /1 - conditions/figs/original/ifElseCondition.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/original/ifElseCondition.png -------------------------------------------------------------------------------- /1 - conditions/figs/original/ifElseExample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/original/ifElseExample.png -------------------------------------------------------------------------------- /1 - conditions/figs/original/ifExample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/original/ifExample.png -------------------------------------------------------------------------------- /1 - conditions/figs/original/nestedIfElseExercise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/1 - conditions/figs/original/nestedIfElseExercise.png -------------------------------------------------------------------------------- /2 - loops/figs/forExample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/2 - loops/figs/forExample.png -------------------------------------------------------------------------------- /2 - loops/figs/forLoop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/2 - loops/figs/forLoop.png -------------------------------------------------------------------------------- /2 - loops/figs/genericDecrementalLoop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/2 - loops/figs/genericDecrementalLoop.png -------------------------------------------------------------------------------- /2 - loops/figs/genericIncrementalLoop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/2 - loops/figs/genericIncrementalLoop.png -------------------------------------------------------------------------------- /2 - loops/figs/typicalLoop1toN.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/2 - loops/figs/typicalLoop1toN.png -------------------------------------------------------------------------------- /2 - loops/figs/typicalLoopNto1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/2 - loops/figs/typicalLoopNto1.png -------------------------------------------------------------------------------- /2 - loops/figs/whatWillThisDo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/2 - loops/figs/whatWillThisDo.png -------------------------------------------------------------------------------- /2 - loops/figs/whileExample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/2 - loops/figs/whileExample.png -------------------------------------------------------------------------------- /2 - loops/figs/whileLoop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/2 - loops/figs/whileLoop.png -------------------------------------------------------------------------------- /3 - functions/figs/functionMemoryDiagrams-figure0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/3 - functions/figs/functionMemoryDiagrams-figure0.png -------------------------------------------------------------------------------- /3 - functions/figs/functionMemoryDiagrams-figure1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/3 - functions/figs/functionMemoryDiagrams-figure1.png -------------------------------------------------------------------------------- /3 - functions/figs/functionMemoryDiagrams-figure2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/3 - functions/figs/functionMemoryDiagrams-figure2.png -------------------------------------------------------------------------------- /3 - functions/figs/functionMemoryDiagrams-figure3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/3 - functions/figs/functionMemoryDiagrams-figure3.png -------------------------------------------------------------------------------- /3 - functions/figs/functionMemoryDiagrams-figure4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/3 - functions/figs/functionMemoryDiagrams-figure4.png -------------------------------------------------------------------------------- /3 - functions/figs/functionMemoryDiagrams-figure5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/3 - functions/figs/functionMemoryDiagrams-figure5.png -------------------------------------------------------------------------------- /3 - functions/figs/functionMemoryDiagrams-figure6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/3 - functions/figs/functionMemoryDiagrams-figure6.png -------------------------------------------------------------------------------- /4 - arrays/.texpadtmp/arrays-figure0.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {6F774A836D6CA9DC3569CD1475E90174}% 2 | -------------------------------------------------------------------------------- /4 - arrays/.texpadtmp/arrays-figure1.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {0D47365E71A7336ADE450A8016505EFD}% 2 | -------------------------------------------------------------------------------- /4 - arrays/.texpadtmp/arrays-figure10.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {EABD71A5AB86F558601EFE0D17FAA1F6}% 2 | -------------------------------------------------------------------------------- /4 - arrays/.texpadtmp/arrays-figure2.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {E76BFDFD5F36B29C5C46C078E0D13F4D}% 2 | -------------------------------------------------------------------------------- /4 - arrays/.texpadtmp/arrays-figure3.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {79F77D1E9AC5EF05AFF8380982905AB3}% 2 | -------------------------------------------------------------------------------- /4 - arrays/.texpadtmp/arrays-figure4.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {B91A4D7018CF3811B68329A9FE2615F5}% 2 | -------------------------------------------------------------------------------- /4 - arrays/.texpadtmp/arrays-figure5.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {333A96AD13E9E09199E9826CAB101A9D}% 2 | -------------------------------------------------------------------------------- /4 - arrays/.texpadtmp/arrays-figure6.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {84AA578555EB24FF99A9D846BA260821}% 2 | -------------------------------------------------------------------------------- /4 - arrays/.texpadtmp/arrays-figure7.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {5158A32A522420116BCFDB9A79D59E3A}% 2 | -------------------------------------------------------------------------------- /4 - arrays/.texpadtmp/arrays-figure8.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {F48A7A61B28960F112141D9E5DC36E4E}% 2 | -------------------------------------------------------------------------------- /4 - arrays/.texpadtmp/arrays-figure9.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {CB5420E87D4CB2DEF55E5A99321658DA}% 2 | -------------------------------------------------------------------------------- /4 - arrays/.texpadtmp/arrays.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \providecommand\hyper@newdestlabel[2]{} 3 | \providecommand\HyperFirstAtBeginDocument{\AtBeginDocument} 4 | \HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined 5 | \global\let\oldcontentsline\contentsline 6 | \gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}} 7 | \global\let\oldnewlabel\newlabel 8 | \gdef\newlabel#1#2{\newlabelxx{#1}#2} 9 | \gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}} 10 | \AtEndDocument{\ifx\hyper@anchor\@undefined 11 | \let\contentsline\oldcontentsline 12 | \let\newlabel\oldnewlabel 13 | \fi} 14 | \fi} 15 | \global\let\hyper@last\relax 16 | \gdef\HyperFirstAtBeginDocument#1{#1} 17 | \providecommand\HyField@AuxAddToFields[1]{} 18 | \providecommand\HyField@AuxAddToCoFields[2]{} 19 | \ttl@finishall 20 | -------------------------------------------------------------------------------- /4 - arrays/.texpadtmp/arrays.auxlock: -------------------------------------------------------------------------------- 1 | \def \tikzexternallocked {0} 2 | -------------------------------------------------------------------------------- /4 - arrays/.texpadtmp/arrays.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/4 - arrays/.texpadtmp/arrays.out -------------------------------------------------------------------------------- /4 - arrays/.texpadtmp/arrays.synctex.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/4 - arrays/.texpadtmp/arrays.synctex.gz -------------------------------------------------------------------------------- /4 - arrays/figs/arrays-figure0.dpth: -------------------------------------------------------------------------------- 1 | 0.0pt 2 | \pgfexternal@restore {\def \pgfexternalwidth {199.88051pt}} 3 | \pgfexternal@restore {\def \pgfexternalheight {142.97502pt}} 4 | -------------------------------------------------------------------------------- /4 - arrays/figs/arrays-figure0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/4 - arrays/figs/arrays-figure0.png -------------------------------------------------------------------------------- /4 - arrays/figs/arrays-figure1.dpth: -------------------------------------------------------------------------------- 1 | 0.0pt 2 | \pgfexternal@restore {\def \pgfexternalwidth {57.61679pt}} 3 | \pgfexternal@restore {\def \pgfexternalheight {142.97502pt}} 4 | -------------------------------------------------------------------------------- /4 - arrays/figs/arrays-figure1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/4 - arrays/figs/arrays-figure1.png -------------------------------------------------------------------------------- /4 - arrays/figs/arrays-figure2.dpth: -------------------------------------------------------------------------------- 1 | 0.0pt 2 | \pgfexternal@restore {\def \pgfexternalwidth {86.06953pt}} 3 | \pgfexternal@restore {\def \pgfexternalheight {228.33325pt}} 4 | -------------------------------------------------------------------------------- /4 - arrays/figs/arrays-figure2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/4 - arrays/figs/arrays-figure2.png -------------------------------------------------------------------------------- /4 - arrays/figs/arrays-figure3.dpth: -------------------------------------------------------------------------------- 1 | 0.0pt 2 | \pgfexternal@restore {\def \pgfexternalwidth {171.42776pt}} 3 | \pgfexternal@restore {\def \pgfexternalheight {142.97502pt}} 4 | -------------------------------------------------------------------------------- /4 - arrays/figs/arrays-figure3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/4 - arrays/figs/arrays-figure3.png -------------------------------------------------------------------------------- /4 - arrays/figs/arrays-figure4.dpth: -------------------------------------------------------------------------------- 1 | 0.0pt 2 | \pgfexternal@restore {\def \pgfexternalwidth {86.06953pt}} 3 | \pgfexternal@restore {\def \pgfexternalheight {171.42776pt}} 4 | -------------------------------------------------------------------------------- /4 - arrays/figs/arrays-figure4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/4 - arrays/figs/arrays-figure4.png -------------------------------------------------------------------------------- /4 - arrays/figs/arrays-figure5.dpth: -------------------------------------------------------------------------------- 1 | 0.0pt 2 | \pgfexternal@restore {\def \pgfexternalwidth {313.69148pt}} 3 | \pgfexternal@restore {\def \pgfexternalheight {142.97502pt}} 4 | -------------------------------------------------------------------------------- /4 - arrays/figs/arrays-figure5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/4 - arrays/figs/arrays-figure5.png -------------------------------------------------------------------------------- /4 - arrays/figs/arrays-figure6.dpth: -------------------------------------------------------------------------------- 1 | 0.0pt 2 | \pgfexternal@restore {\def \pgfexternalwidth {228.33325pt}} 3 | \pgfexternal@restore {\def \pgfexternalheight {171.42776pt}} 4 | -------------------------------------------------------------------------------- /4 - arrays/figs/arrays-figure6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/4 - arrays/figs/arrays-figure6.png -------------------------------------------------------------------------------- /4 - arrays/figs/arrays-figure7.dpth: -------------------------------------------------------------------------------- 1 | 0.0pt 2 | \pgfexternal@restore {\def \pgfexternalwidth {228.33325pt}} 3 | \pgfexternal@restore {\def \pgfexternalheight {199.88051pt}} 4 | -------------------------------------------------------------------------------- /4 - arrays/figs/arrays-figure7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/4 - arrays/figs/arrays-figure7.png -------------------------------------------------------------------------------- /5 - arrays and functions/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure0.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {FDFF324E21667275CA7C4EA95D0E77A5}% 2 | -------------------------------------------------------------------------------- /5 - arrays and functions/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure1.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {14782CACEFA9156B5CBE6F003BDE88E1}% 2 | -------------------------------------------------------------------------------- /5 - arrays and functions/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure2.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {6F73D83A55D14239D45A501A0EE5C965}% 2 | -------------------------------------------------------------------------------- /5 - arrays and functions/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure3.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {B267FD8BC403B2C169BB11DF6DED68CF}% 2 | -------------------------------------------------------------------------------- /5 - arrays and functions/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure4.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {F48A7A61B28960F112141D9E5DC36E4E}% 2 | -------------------------------------------------------------------------------- /5 - arrays and functions/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure5.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {CB5420E87D4CB2DEF55E5A99321658DA}% 2 | -------------------------------------------------------------------------------- /5 - arrays and functions/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure6.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {EABD71A5AB86F558601EFE0D17FAA1F6}% 2 | -------------------------------------------------------------------------------- /5 - arrays and functions/.texpadtmp/arraysAndFunctionMemoryDiagrams.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \providecommand\hyper@newdestlabel[2]{} 3 | \providecommand\HyperFirstAtBeginDocument{\AtBeginDocument} 4 | \HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined 5 | \global\let\oldcontentsline\contentsline 6 | \gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}} 7 | \global\let\oldnewlabel\newlabel 8 | \gdef\newlabel#1#2{\newlabelxx{#1}#2} 9 | \gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}} 10 | \AtEndDocument{\ifx\hyper@anchor\@undefined 11 | \let\contentsline\oldcontentsline 12 | \let\newlabel\oldnewlabel 13 | \fi} 14 | \fi} 15 | \global\let\hyper@last\relax 16 | \gdef\HyperFirstAtBeginDocument#1{#1} 17 | \providecommand\HyField@AuxAddToFields[1]{} 18 | \providecommand\HyField@AuxAddToCoFields[2]{} 19 | \ttl@finishall 20 | -------------------------------------------------------------------------------- /5 - arrays and functions/.texpadtmp/arraysAndFunctionMemoryDiagrams.auxlock: -------------------------------------------------------------------------------- 1 | \def \tikzexternallocked {0} 2 | -------------------------------------------------------------------------------- /5 - arrays and functions/.texpadtmp/arraysAndFunctionMemoryDiagrams.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/5 - arrays and functions/.texpadtmp/arraysAndFunctionMemoryDiagrams.out -------------------------------------------------------------------------------- /5 - arrays and functions/.texpadtmp/arraysAndFunctionMemoryDiagrams.synctex.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/5 - arrays and functions/.texpadtmp/arraysAndFunctionMemoryDiagrams.synctex.gz -------------------------------------------------------------------------------- /5 - arrays and functions/figs/arraysAndFunctionMemoryDiagrams-figure0.dpth: -------------------------------------------------------------------------------- 1 | 0.0pt 2 | \pgfexternal@restore {\def \pgfexternalwidth {427.50249pt}} 3 | \pgfexternal@restore {\def \pgfexternalheight {104.23146pt}} 4 | -------------------------------------------------------------------------------- /5 - arrays and functions/figs/arraysAndFunctionMemoryDiagrams-figure0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/5 - arrays and functions/figs/arraysAndFunctionMemoryDiagrams-figure0.png -------------------------------------------------------------------------------- /5 - arrays and functions/figs/arraysAndFunctionMemoryDiagrams-figure1.dpth: -------------------------------------------------------------------------------- 1 | 0.0pt 2 | \pgfexternal@restore {\def \pgfexternalwidth {427.50249pt}} 3 | \pgfexternal@restore {\def \pgfexternalheight {118.45782pt}} 4 | -------------------------------------------------------------------------------- /5 - arrays and functions/figs/arraysAndFunctionMemoryDiagrams-figure1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/5 - arrays and functions/figs/arraysAndFunctionMemoryDiagrams-figure1.png -------------------------------------------------------------------------------- /5 - arrays and functions/figs/arraysAndFunctionMemoryDiagrams-figure2.dpth: -------------------------------------------------------------------------------- 1 | 0.0pt 2 | \pgfexternal@restore {\def \pgfexternalwidth {430.03236pt}} 3 | \pgfexternal@restore {\def \pgfexternalheight {189.58969pt}} 4 | -------------------------------------------------------------------------------- /5 - arrays and functions/figs/arraysAndFunctionMemoryDiagrams-figure2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/5 - arrays and functions/figs/arraysAndFunctionMemoryDiagrams-figure2.png -------------------------------------------------------------------------------- /6 - problem solving/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure0.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {FDFF324E21667275CA7C4EA95D0E77A5}% 2 | -------------------------------------------------------------------------------- /6 - problem solving/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure1.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {14782CACEFA9156B5CBE6F003BDE88E1}% 2 | -------------------------------------------------------------------------------- /6 - problem solving/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure2.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {6F73D83A55D14239D45A501A0EE5C965}% 2 | -------------------------------------------------------------------------------- /6 - problem solving/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure3.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {B267FD8BC403B2C169BB11DF6DED68CF}% 2 | -------------------------------------------------------------------------------- /6 - problem solving/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure4.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {F48A7A61B28960F112141D9E5DC36E4E}% 2 | -------------------------------------------------------------------------------- /6 - problem solving/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure5.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {CB5420E87D4CB2DEF55E5A99321658DA}% 2 | -------------------------------------------------------------------------------- /6 - problem solving/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure6.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {EABD71A5AB86F558601EFE0D17FAA1F6}% 2 | -------------------------------------------------------------------------------- /6 - problem solving/.texpadtmp/arraysAndFunctionMemoryDiagrams.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \providecommand\hyper@newdestlabel[2]{} 3 | \providecommand\HyperFirstAtBeginDocument{\AtBeginDocument} 4 | \HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined 5 | \global\let\oldcontentsline\contentsline 6 | \gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}} 7 | \global\let\oldnewlabel\newlabel 8 | \gdef\newlabel#1#2{\newlabelxx{#1}#2} 9 | \gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}} 10 | \AtEndDocument{\ifx\hyper@anchor\@undefined 11 | \let\contentsline\oldcontentsline 12 | \let\newlabel\oldnewlabel 13 | \fi} 14 | \fi} 15 | \global\let\hyper@last\relax 16 | \gdef\HyperFirstAtBeginDocument#1{#1} 17 | \providecommand\HyField@AuxAddToFields[1]{} 18 | \providecommand\HyField@AuxAddToCoFields[2]{} 19 | \ttl@finishall 20 | -------------------------------------------------------------------------------- /6 - problem solving/.texpadtmp/arraysAndFunctionMemoryDiagrams.auxlock: -------------------------------------------------------------------------------- 1 | \def \tikzexternallocked {0} 2 | -------------------------------------------------------------------------------- /6 - problem solving/.texpadtmp/arraysAndFunctionMemoryDiagrams.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/6 - problem solving/.texpadtmp/arraysAndFunctionMemoryDiagrams.out -------------------------------------------------------------------------------- /6 - problem solving/.texpadtmp/arraysAndFunctionMemoryDiagrams.synctex.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/6 - problem solving/.texpadtmp/arraysAndFunctionMemoryDiagrams.synctex.gz -------------------------------------------------------------------------------- /6 - problem solving/problemSolving.md: -------------------------------------------------------------------------------- 1 | # Problem Solving 2 | 3 | More often than not, you will be given a description of a problem and be required to understand how it can be solved in terms of computing. 4 | 5 | The key is to be patient and read the specifications carefully. Skipping sections because you think they are not important is the biggest mistake you can make (I've done it a few times too :pensive:) 6 | 7 | We will try to understand problem solving through examples. We will be tackling some of the HackerRank challenges 8 | 9 | https://www.hackerrank.com/challenges/birthday-cake-candles/problem 10 | 11 | https://www.hackerrank.com/challenges/apple-and-orange/problem 12 | 13 | https://www.hackerrank.com/challenges/kangaroo/problem 14 | 15 | https://www.hackerrank.com/challenges/breaking-best-and-worst-records/problem 16 | 17 | https://www.hackerrank.com/challenges/migratory-birds/problem 18 | 19 | https://www.hackerrank.com/challenges/day-of-the-programmer/problem 20 | 21 | https://www.hackerrank.com/challenges/bon-appetit/problem 22 | 23 | https://www.hackerrank.com/challenges/angry-professor/problem 24 | 25 | https://www.hackerrank.com/challenges/beautiful-days-at-the-movies/problem 26 | 27 | https://www.hackerrank.com/challenges/equality-in-a-array/problem 28 | 29 | https://www.hackerrank.com/challenges/bigger-is-greater/problem 30 | (Hint: https://stackoverflow.com/questions/1622532/algorithm-to-find-next-greater-permutation-of-a-given-string#1622539) -------------------------------------------------------------------------------- /7 - strings (optional)/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure0.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {FDFF324E21667275CA7C4EA95D0E77A5}% 2 | -------------------------------------------------------------------------------- /7 - strings (optional)/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure1.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {14782CACEFA9156B5CBE6F003BDE88E1}% 2 | -------------------------------------------------------------------------------- /7 - strings (optional)/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure2.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {6F73D83A55D14239D45A501A0EE5C965}% 2 | -------------------------------------------------------------------------------- /7 - strings (optional)/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure3.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {B267FD8BC403B2C169BB11DF6DED68CF}% 2 | -------------------------------------------------------------------------------- /7 - strings (optional)/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure4.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {F48A7A61B28960F112141D9E5DC36E4E}% 2 | -------------------------------------------------------------------------------- /7 - strings (optional)/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure5.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {CB5420E87D4CB2DEF55E5A99321658DA}% 2 | -------------------------------------------------------------------------------- /7 - strings (optional)/.texpadtmp/arraysAndFunctionMemoryDiagrams-figure6.md5: -------------------------------------------------------------------------------- 1 | \def \tikzexternallastkey {EABD71A5AB86F558601EFE0D17FAA1F6}% 2 | -------------------------------------------------------------------------------- /7 - strings (optional)/.texpadtmp/arraysAndFunctionMemoryDiagrams.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \providecommand\hyper@newdestlabel[2]{} 3 | \providecommand\HyperFirstAtBeginDocument{\AtBeginDocument} 4 | \HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined 5 | \global\let\oldcontentsline\contentsline 6 | \gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}} 7 | \global\let\oldnewlabel\newlabel 8 | \gdef\newlabel#1#2{\newlabelxx{#1}#2} 9 | \gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}} 10 | \AtEndDocument{\ifx\hyper@anchor\@undefined 11 | \let\contentsline\oldcontentsline 12 | \let\newlabel\oldnewlabel 13 | \fi} 14 | \fi} 15 | \global\let\hyper@last\relax 16 | \gdef\HyperFirstAtBeginDocument#1{#1} 17 | \providecommand\HyField@AuxAddToFields[1]{} 18 | \providecommand\HyField@AuxAddToCoFields[2]{} 19 | \ttl@finishall 20 | -------------------------------------------------------------------------------- /7 - strings (optional)/.texpadtmp/arraysAndFunctionMemoryDiagrams.auxlock: -------------------------------------------------------------------------------- 1 | \def \tikzexternallocked {0} 2 | -------------------------------------------------------------------------------- /7 - strings (optional)/.texpadtmp/arraysAndFunctionMemoryDiagrams.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/7 - strings (optional)/.texpadtmp/arraysAndFunctionMemoryDiagrams.out -------------------------------------------------------------------------------- /7 - strings (optional)/.texpadtmp/arraysAndFunctionMemoryDiagrams.synctex.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/7 - strings (optional)/.texpadtmp/arraysAndFunctionMemoryDiagrams.synctex.gz -------------------------------------------------------------------------------- /PVector.md: -------------------------------------------------------------------------------- 1 | # PVector type in Processing 2 | 3 | ## PVector represents a point on the display window 4 | 5 | ### Declaring a PVector variable (actually, an object): 6 | 7 | ```java 8 | PVector a = new PVector(50, 70); //stores location (50, 70) in PVector `a`. 9 | ``` 10 | 11 | ### Components: 12 | 13 | Each `PVector` object has two components - `x` and `y` (also `z` but we aren't doing 3D rendering). 14 | 15 | Given PVector `a`, you can access these values using `a.x` and `a.y`. 16 | 17 | Thus, you can draw a circle centred at the location `a` as: 18 | 19 | ```java 20 | PVector a = new PVector(50, 70); 21 | ellipse(a.x, a.y, 20, 20); 22 | ``` 23 | 24 | You can also change the values of the `x` and `y` components as: 25 | 26 | ```java 27 | a.x += 30; 28 | a.y -= 10; 29 | //new location of a becomes (80, 60) 30 | ``` 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # COMP1000 to COMP1010 Transition Workshops 2 | 3 | We focus on the following aspects of programming - 4 | 5 | - variables 6 | - conditions 7 | - loops 8 | - functions 9 | - arrays 10 | - strings 11 | - problem solving 12 | 13 | Workshop material is provided under relevant folders. 14 | 15 | There's no fixed agenda. Students can come and ask "can you help me with functions" or "i had trouble with arrays. can we go through that" and volunteers assist students with the same. 16 | -------------------------------------------------------------------------------- /arrayOfPVectorObjects.md: -------------------------------------------------------------------------------- 1 | # Array of PVector objects 2 | 3 | You can create an array of PVector objects to hold and operate on multiple locations as: 4 | 5 | ```java 6 | PVector[] data = new PVector[5]; //holds 5 locations 7 | ``` 8 | 9 | The number of items in the array is given by `data.length`. 10 | 11 | The 5 PVector objects in the array are accessed as: 12 | 13 | 1. `data[0]` 14 | 2. `data[1]` 15 | 3. `data[2]` 16 | 4. `data[3]` 17 | 5. `data[4]` 18 | 19 | Thus, you can go through each object using a loop, as, 20 | 21 | ```java 22 | for(int i=0; i < data.length; i++) { 23 | println(data[i]); 24 | } 25 | ``` 26 | 27 | You will see the following output as each PVector object is `null` (uninitialized) in the beginning. 28 | 29 | ```java 30 | null 31 | null 32 | null 33 | null 34 | null 35 | ``` 36 | 37 | You can randomize each object in a loop before displaying it, as, 38 | 39 | ```java 40 | for(int i=0; i < data.length; i++) { 41 | data[i] = new PVector(random(width), random(height)); 42 | println(data[i]); 43 | } 44 | ``` 45 | 46 | Sample output (remember, PVectors have a third value `z` that we don't use): 47 | 48 | ```java 49 | [ 8.236826, 78.91757, 0.0 ] 50 | [ 92.74533, 54.27635, 0.0 ] 51 | [ 60.70919, 44.13377, 0.0 ] 52 | [ 59.916126, 69.40042, 0.0 ] 53 | [ 25.684088, 85.957634, 0.0 ] 54 | ``` 55 | 56 | To determine which point is furthest from the origin (0, 0), we can use the `dist()` function from Processing, as, 57 | 58 | ```java 59 | int furthestIndex = 0; //assume first point is furthest 60 | for(int i=1; i < data.length; i++) { 61 | float curDist = dist(data[i].x, data[i].y, 0, 0); 62 | float maxDist = dist(data[furthestIndex].x, data[furthestIndex].y, 0, 0); 63 | if(curDist > maxDist) { 64 | furthestIndex = i; 65 | } 66 | } 67 | ``` 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /comments.md: -------------------------------------------------------------------------------- 1 | # COMP115 to COMP125 Transition Workshops 2 | 3 | ## Comments 4 | 5 | ### Conditions 6 | 7 | ### Loops 8 | 9 | ### Functions 10 | 11 | ### Arrays 12 | 13 | ##### Re-referencing 14 | The 'Creating array - Option 2' section appears to explain that arrays can not be re-referenced later if they are created using the following syntax 15 | ```java 16 | type[] arrayName = {item1, item2, ....}; 17 | ``` 18 | What I think it actually means is that said syntax can not be used to re-reference an array later, and that you instead have to use the 'new' operator to do so. 19 | 20 | I'd swap the 'The problem with this approach..' line for something like 21 | > The problem with this approach is that if an array has already been created, it can not be re-referenced later using this (more about referencing soon). 22 | 23 | and the line under option 3 to 24 | > The third approach is similar to the second except you **can** use it to update the reference later. 25 | 26 | ##### Deep/Shallow array copies 27 | When talking about deep/shallow array copies, perhaps include something like 28 | ```java 29 | int[] a = {10, 70, 20, 90}; 30 | int[] b = a; 31 | b = new int[]{100,30,200,50}; 32 | ``` 33 | to demonstrate re-referencing in action. However it might be more suitable for the 'arrays and functions' part of the workshop. 34 | 35 | ##### Extra tasks 36 | Maybe include a task that requires storing arrays in an array? It might be a little too advanced but it really hammers home your ability to store anything in an array. 37 | 38 | All the scenarios look good, but Scenario 5 and 6 are screaming out for an advanced task that asks you to do the same thing using a single loop. 39 | 40 | ### Arrays and Functions 41 | -------------------------------------------------------------------------------- /revisionPackage/COMP115QuestionBank.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/COMP115QuestionBank.zip -------------------------------------------------------------------------------- /revisionPackage/COMP115QuestionBank/questions/01operatorsExpressions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/COMP115QuestionBank/questions/01operatorsExpressions.pdf -------------------------------------------------------------------------------- /revisionPackage/COMP115QuestionBank/questions/02conditions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/COMP115QuestionBank/questions/02conditions.pdf -------------------------------------------------------------------------------- /revisionPackage/COMP115QuestionBank/questions/03loops.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/COMP115QuestionBank/questions/03loops.pdf -------------------------------------------------------------------------------- /revisionPackage/COMP115QuestionBank/questions/04functions1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/COMP115QuestionBank/questions/04functions1.pdf -------------------------------------------------------------------------------- /revisionPackage/COMP115QuestionBank/questions/05arrays.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/COMP115QuestionBank/questions/05arrays.pdf -------------------------------------------------------------------------------- /revisionPackage/COMP115QuestionBank/questions/06functions2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/COMP115QuestionBank/questions/06functions2.pdf -------------------------------------------------------------------------------- /revisionPackage/COMP115QuestionBank/questions/07strings.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/COMP115QuestionBank/questions/07strings.pdf -------------------------------------------------------------------------------- /revisionPackage/COMP115QuestionBank/solutions/01operatorsExpressionsSolutions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/COMP115QuestionBank/solutions/01operatorsExpressionsSolutions.pdf -------------------------------------------------------------------------------- /revisionPackage/COMP115QuestionBank/solutions/02conditionsSolutions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/COMP115QuestionBank/solutions/02conditionsSolutions.pdf -------------------------------------------------------------------------------- /revisionPackage/COMP115QuestionBank/solutions/03loopsSolutions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/COMP115QuestionBank/solutions/03loopsSolutions.pdf -------------------------------------------------------------------------------- /revisionPackage/COMP115QuestionBank/solutions/04functions1Solutions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/COMP115QuestionBank/solutions/04functions1Solutions.pdf -------------------------------------------------------------------------------- /revisionPackage/COMP115QuestionBank/solutions/05arraysSolutions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/COMP115QuestionBank/solutions/05arraysSolutions.pdf -------------------------------------------------------------------------------- /revisionPackage/COMP115QuestionBank/solutions/06functions2Solutions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/COMP115QuestionBank/solutions/06functions2Solutions.pdf -------------------------------------------------------------------------------- /revisionPackage/COMP115QuestionBank/solutions/07stringsSolutions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/COMP115QuestionBank/solutions/07stringsSolutions.pdf -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/MultiDimensionArrays/1chessBoardHighlight/chessBoardHighlightSolution/chessBoardHighlightSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | This program should draw a chessboard. 3 | The chessboard should be represented by a 2-D integer array 4 | of size 8 x 8. 5 | The aim of this exercise is for student to gain experience using 6 | 2-D arrays to represent a visual image. 7 | The students need to complete a number of stages. 8 | 1. Declare an appropriate variable to hold the chessboard according 9 | to the information provided above. 10 | 2. The chessboard should be initialised with values = 0; 11 | 3. Complete the highlightSquare(int posX, int posY) method below. 12 | NOTE: Students should not need to alter the draw() and mousePressed() 13 | functions. 14 | TESTING: Student should test their answer with edge cases to make sure their 15 | program is working as intended. This should include making sure each corner 16 | of the chessboard is highlighted when clicked. 17 | */ 18 | 19 | /* SOLUTION */ 20 | final int WIDTH = 50; 21 | int[][] chessboard = new int[8][8]; 22 | 23 | void setup(){ 24 | size(400,400); 25 | noStroke(); 26 | 27 | for(int i = 0; i < 8; i++){ 28 | for (int j = 0; j < 8; j++){ 29 | chessboard[i][j] = 0; 30 | } 31 | } 32 | } 33 | 34 | void draw(){ 35 | background(255); 36 | for(int i = 0; i < 8; i++){ 37 | for (int j = 0; j < 8; j++){ 38 | if (chessboard[i][j] == 1) 39 | fill(0, 255, 0); 40 | else if ((i + j) % 2 == 0) 41 | fill(255); 42 | else 43 | fill(0); 44 | rect(i * WIDTH,j * WIDTH, WIDTH, WIDTH); 45 | } 46 | } 47 | } 48 | 49 | void mousePressed(){ 50 | highlightSquare(mouseX, mouseY); 51 | } 52 | 53 | void highlightSquare(int posX, int posY){ 54 | for(int i = 0; i < 8; i++){ 55 | for(int j = 0; j < 8; j++){ 56 | if(chessboard[i][j] == 1) 57 | chessboard[i][j] = 0; 58 | } 59 | } 60 | chessboard[posX/WIDTH][posY/WIDTH] = 1; 61 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/MultiDimensionArrays/2rowsAndColumns/rowsAndColumnsOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/A&SPracticePackage/MultiDimensionArrays/2rowsAndColumns/rowsAndColumnsOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/MultiDimensionArrays/2rowsAndColumns/rowsAndColumnsSolution/rowsAndColumnsSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | create a multi-dimension array rows of size 6 4 | with sub-arrays of size 4 5 | */ 6 | int[][] rows = new int [6][4]; 7 | 8 | /* 9 | TASK 2 10 | initialise the array such that each sub-array 11 | contains the same value within the sub-array, 12 | but the value stored between the sub-arrays 13 | increas consecutively from 0. the output 14 | should match the screenshot if completed 15 | correctly. 16 | */ 17 | for (int i = 0; i < rows.length; i++) { 18 | for (int j = 0; j < rows[i].length; j++) { 19 | rows[i][j] = i; 20 | } 21 | } 22 | 23 | println(); 24 | 25 | /* 26 | TASK 3 27 | create a multi-dimension array columns of size 6 28 | with sub-arrays of size 4 29 | */ 30 | int[][] columns = new int [6][4]; 31 | 32 | /* 33 | TASK 4 34 | initialise the array such that the value 35 | increases from 0 to 3 within each sub-array 36 | for all the sub-arrays. the output 37 | should match the screenshot if completed 38 | correctly. 39 | */ 40 | for (int i = 0; i < columns.length; i++) { 41 | for (int j = 0; j < columns[i].length; j++) { 42 | columns[i][j] = j; 43 | } 44 | } 45 | 46 | 47 | /* DO NOT MODIFY */ 48 | println("rows:"); 49 | for (int i = 0; i < rows.length; i++) { 50 | print("["); 51 | for (int j = 0; j < rows[i].length; j++) { 52 | if (j != (rows[i].length - 1)) 53 | print(rows[i][j] + ", "); 54 | else 55 | print(rows[i][j]); 56 | } 57 | println("]"); 58 | } 59 | 60 | println(); 61 | 62 | println("columns:"); 63 | for (int i = 0; i {{3, 23}, {9, 493}, {123, 45}} 23 | {54, 145, 0}, 1 -> {{54}, {145}, {0}} 24 | {5, 2, 8, 2, 7, 9}, 3, {{5, 2, 8}, {2, 7, 9}} 25 | */ 26 | int[][] split(int[] arr, int splitNum) { 27 | int[][] result = new int[arr.length/splitNum][splitNum]; 28 | 29 | for (int i = 0; i < result.length; i++) { 30 | for (int j = 0; j < result[i].length; j++) { 31 | result[i][j] = arr[i*result[i].length + j]; 32 | } 33 | } 34 | 35 | /* alternate solution 36 | int count = 0; 37 | for (int i = 0; i < result.length; i++) { 38 | for (int j = 0; j < result[i].length; j++) { 39 | result[i][j] = arr[count]; 40 | count++; 41 | } 42 | } 43 | */ 44 | return result; 45 | } 46 | 47 | /* DO NOT MODIFY */ 48 | void printArrays(int[] a1, int split, int[][] a2) { 49 | print("single-dimension array: ["); 50 | for (int i = 0; i < a1.length -1; i++) { 51 | print(a1[i] + ", "); 52 | } 53 | println(a1[a1.length - 1] +"]"); 54 | 55 | println("splitNum: " + split); 56 | 57 | print("multi-dimension array: ["); 58 | for (int i = 0; i < a2.length; i++) { 59 | print("["); 60 | for (int j = 0; j < a2[i].length; j++) { 61 | print(a2[i][j]); 62 | if (j != a2[i].length - 1) print(", "); 63 | } 64 | print("]"); 65 | if (i != a2.length - 1) print(", "); 66 | } 67 | println("]"); 68 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/MultiDimensionArrays/3split/splitTemplate/splitTemplate.pde: -------------------------------------------------------------------------------- 1 | /* DO NOT MODIFY SETUP */ 2 | void setup() { 3 | int[] single = new int[6]; 4 | for (int i = 0; i < single.length; i++) { 5 | single[i] = (int)random(1000); 6 | } 7 | int split = (int)random(1, 4); 8 | int[][] multi = split(single, split); 9 | 10 | printArrays(single, split, multi); 11 | } 12 | 13 | /* 14 | TASK 15 | complete the function split so that when given an int 16 | array arr and an int splitNum, it divides the array into 17 | a multi-dimension array with sub-arrays of splitNum 18 | size chunks. assume splitNum is a divisor of the 19 | length of arr. 20 | 21 | examples: 22 | {3, 23, 9, 493, 123, 45}, 2 -> {{3, 23}, {9, 493}, {123, 45}} 23 | {54, 145, 0}, 1 -> {{54}, {145}, {0}} 24 | {5, 2, 8, 2, 7, 9}, 3, {{5, 2, 8}, {2, 7, 9}} 25 | */ 26 | int[][] split(int[] arr, int splitNum) { 27 | } 28 | 29 | /* DO NOT MODIFY */ 30 | void printArrays(int[] a1, int split, int[][] a2) { 31 | print("single-dimension array: ["); 32 | for (int i = 0; i < a1.length -1; i++) { 33 | print(a1[i] + ", "); 34 | } 35 | println(a1[a1.length - 1] +"]"); 36 | 37 | println("splitNum: " + split); 38 | 39 | print("multi-dimension array: ["); 40 | for (int i = 0; i < a2.length; i++) { 41 | print("["); 42 | for (int j = 0; j < a2[i].length; j++) { 43 | print(a2[i][j]); 44 | if (j != a2[i].length - 1) print(", "); 45 | } 46 | print("]"); 47 | if (i != a2.length - 1) print(", "); 48 | } 49 | println("]"); 50 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/10onlyLowercase/onlyLowercaseSolution/onlyLowercaseSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | This program generates a randomly sized array of random characters. 3 | The aim of this exercise is for the student to validate the array based 4 | on the element inside it. 5 | Students need to fill out the onlyLowercase() method. 6 | This method should return true if and only if the array conatins 7 | just lowercase elements. 8 | If the array does not only contain lowercase elements return false. 9 | */ 10 | final int SIZE = (int)random(1, 10); 11 | char arr[] = new char[SIZE]; 12 | 13 | void setup(){ 14 | println("Array: "); 15 | for(int i = 0; i < arr.length; i++){ 16 | arr[i] = (char)(int)random(65, 123); 17 | print(arr[i], ' '); 18 | } 19 | println(); 20 | boolean result = onlyLowercase(); 21 | if(result){ 22 | println("The array contains only lowercase letters"); 23 | } else { 24 | println("The array does not contain only lowercase letters"); 25 | } 26 | } 27 | 28 | /* SOLUTION */ 29 | boolean onlyLowercase(){ 30 | boolean result = true; 31 | for(int i = 0; i < arr.length; i++){ 32 | if(arr[i] < 'a' || arr[i] > 'z'){ 33 | result = false; 34 | break; 35 | } 36 | } 37 | return result; 38 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/10onlyLowercase/onlyLowercaseTemplate/onlyLowercaseTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | This program generates a randomly sized array of random characters. 3 | The aim of this exercise is for the student to validate the array based 4 | on the element inside it. 5 | Students need to fill out the onlyLowercase() method. 6 | This method should return true if and only if the array conatins 7 | just lowercase elements. 8 | If the array does not only contain lowercase elements return false. 9 | */ 10 | final int SIZE = (int)random(1, 10); 11 | char arr[] = new char[SIZE]; 12 | 13 | void setup(){ 14 | println("Array: "); 15 | for(int i = 0; i < arr.length; i++){ 16 | arr[i] = (char)(int)random(65, 123); 17 | print(arr[i], ' '); 18 | } 19 | println(); 20 | boolean result = onlyLowercase(); 21 | if(result){ 22 | println("The array contains only lowercase letters"); 23 | } else { 24 | println("The array does not contain only lowercase letters"); 25 | } 26 | } 27 | 28 | /* ------ DO NOT MODIFY CODE ABOVE THIS LINE ------ */ 29 | 30 | /* STUDENTS TO FILL OUT */ 31 | boolean onlyLowercase(){ 32 | return false; 33 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/11difference/differenceTemplate/differenceTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Fill out the diffBetweenLargestAndSmallest and use the function 3 | in setup and store the return value of the function with the 4 | array a as the parameter in the variable result 5 | 6 | You can assume that the smallest possible value in array a is 0 and the 7 | largest element can be 157 8 | */ 9 | 10 | color lavender = color(230,230,250); 11 | color thistle = color(216,191,216); 12 | 13 | final int ARRAY_RECT = 40; 14 | 15 | // The array to be passed in function as the parameter 16 | int[] a = {5, 2, 4, 10}; 17 | final int SIZE = a.length; 18 | 19 | // Used to store the result 20 | int result; 21 | 22 | // Store the index of the smallest element into this variable 23 | int smallestEleIdx = -1; 24 | 25 | // Store the index of the largest element into this variable 26 | int largestEleIdx = -1; 27 | void setup() { 28 | size(400, 400); 29 | background(255); 30 | // Use the function diffBetweenLargestAndSmallest with array a passed 31 | 32 | // Now print the result 33 | 34 | // Smallest element block will be filled lavender color 35 | // and the largest element block will be filled 36 | // with a thistle color 37 | printArray(); 38 | printDiffBetweenLargest_Smallest(result); 39 | } 40 | 41 | /* STUDENT TO FILL OUT */ 42 | // This function return the difference between the largest and smallest element in a int arr 43 | int diffBetweenLargestAndSmallest(int[] arr){ 44 | return 0; // Dummy value 45 | } 46 | 47 | 48 | /* ----- DO NOT MODIFY CODE BELOW THIS LINE ----- */ 49 | 50 | void printArray(){ 51 | for(int i = 0; i < SIZE; i ++){ 52 | if(i == smallestEleIdx) 53 | fill(lavender); 54 | else if(i == largestEleIdx) 55 | fill(thistle); 56 | else 57 | fill(255); 58 | rect(((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT, (height/3) - SIZE/2, ARRAY_RECT, ARRAY_RECT); 59 | fill(0); 60 | text(a[i], (((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT) + ARRAY_RECT/3, height/3 + ARRAY_RECT/2); 61 | } 62 | } 63 | 64 | 65 | void printDiffBetweenLargest_Smallest(int element){ 66 | textSize(16); 67 | 68 | text("The difference between the largest\n number and the smallest number\n in the array is: " + element, 50, 3*(height/4)); 69 | 70 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/13decreasing/decreasingSolution/decreasingSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Fill out the function arrDecreasing, which return the index of the first element that is not in decreasing order, else return -1 3 | You can assume that the array passed into the function will have a length >= 2. 4 | For example arrDecreasing({5,4,1,7,5}) will return 3 5 | */ 6 | 7 | color cornflowerblue = color(100,149,237); 8 | color lightsalmon = color(255,160,122); 9 | 10 | final int ARRAY_RECT = 40; 11 | 12 | int[] a = {7, 5, 14, 3}; 13 | final int SIZE = a.length; 14 | 15 | // Used to store the result 16 | int result; 17 | 18 | void setup() { 19 | size(400, 400); 20 | background(255); 21 | 22 | result = arrDecreasing(a); 23 | printArray(result); 24 | printIdx(result); 25 | } 26 | 27 | /* STUDENT TO FILL OUT */ 28 | int arrDecreasing(int[] arr) { 29 | for(int i = 1; i < arr.length; i++){ 30 | if(arr[i] > arr[i-1]) 31 | return i; 32 | 33 | } 34 | return -1; 35 | } 36 | 37 | 38 | /* ----- DO NOT MODIFY CODE BELOW THIS LINE ----- */ 39 | 40 | void printArray(int idx){ 41 | for(int i = 0; i < SIZE; i ++){ 42 | if(i == idx) 43 | fill(lightsalmon); 44 | else if(i > idx && idx != -1) 45 | fill(255); 46 | else 47 | fill(cornflowerblue); 48 | rect(((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT, (height/3) - SIZE/2, ARRAY_RECT, ARRAY_RECT); 49 | fill(0); 50 | text(a[i], (((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT) + ARRAY_RECT/3, height/3 + ARRAY_RECT/2); 51 | } 52 | } 53 | 54 | void printIdx(int element){ 55 | textSize(16); 56 | if(element == -1) 57 | text("Array in decreasing order", 50, 3*(height/4)); 58 | else 59 | text("The index of the first element that\n is not in deccreasing order is: " + element, 50, 3*(height/4)); 60 | 61 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/13decreasing/decreasingTemplate/decreasingTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Fill out the function arrDecreasing, which return the index of the first element that is not in decreasing order, else return -1 3 | You can assume that the array passed into the function will have a length >= 2. 4 | For example arrDecreasing({5,4,1,7,5}) will return 3 5 | */ 6 | 7 | color cornflowerblue = color(100,149,237); 8 | color lightsalmon = color(255,160,122); 9 | 10 | final int ARRAY_RECT = 40; 11 | 12 | int[] a = {7, 5, 14, 3}; 13 | final int SIZE = a.length; 14 | 15 | // Used to store the result 16 | int result; 17 | 18 | void setup() { 19 | size(400, 400); 20 | background(255); 21 | 22 | result = arrDecreasing(a); 23 | printArray(result); 24 | printIdx(result); 25 | } 26 | 27 | /* STUDENT TO FILL OUT */ 28 | int arrDecreasing(int[] arr) { 29 | return 0; // Dummy value 30 | } 31 | 32 | 33 | /* ----- DO NOT MODIFY CODE BELOW THIS LINE ----- */ 34 | 35 | void printArray(int idx){ 36 | for(int i = 0; i < SIZE; i ++){ 37 | if(i == idx) 38 | fill(lightsalmon); 39 | else if(i > idx && idx < 0) 40 | fill(255); 41 | else 42 | fill(cornflowerblue); 43 | rect(((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT, (height/3) - SIZE/2, ARRAY_RECT, ARRAY_RECT); 44 | fill(0); 45 | text(a[i], (((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT) + ARRAY_RECT/3, height/3 + ARRAY_RECT/2); 46 | } 47 | } 48 | 49 | void printIdx(int element){ 50 | textSize(16); 51 | if(element == -1) 52 | text("Array in decreasing order", 50, 3*(height/4)); 53 | else 54 | text("The index of the first element that\n is not in deccreasing order is: " + element, 50, 3*(height/4)); 55 | 56 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/15mostCommon/mostCommonTemplate/mostCommonTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | This program generates a randomly sized array of random integers. 3 | The aim of this exercise is for the student to calculate something 4 | about the array by comparison to other elements in the array. 5 | The student should fill out the mostCommon() method. 6 | The method should return the most common element. If there are multiple 7 | the function only need return one of them. 8 | If multiple common elements are found then the boolean multiple should be changed. 9 | NOTE: Make sure the multiple flag is set and unset correctly! 10 | What would happen if the first 2 elements you found both had a count of x but then 11 | you see another element later on that has a count of x + y. Should multiple still be set? 12 | */ 13 | final int SIZE = (int)random(1, 10); 14 | final int ARRAY_RECT = 40; 15 | int arr[] = new int[SIZE]; 16 | boolean multiple = false; 17 | 18 | void setup(){ 19 | size(400, 400); 20 | background(255); 21 | println("Array: "); 22 | for(int i = 0; i < arr.length; i++){ 23 | arr[i] = (int)random(1, 5); 24 | print(arr[i], ' '); 25 | } 26 | println(); 27 | int element = mostCommon(); 28 | printArray(element); 29 | printMostCommon(element); 30 | if(multiple){ 31 | println("One of the most common elements is:", element); 32 | } else { 33 | println("The most common element is:", element); 34 | } 35 | } 36 | 37 | void printArray(int element){ 38 | for(int i = 0; i < SIZE; i ++){ 39 | fill(255); 40 | if(element == arr[i]){ 41 | fill(0, 255, 0); 42 | } 43 | rect(((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT, (height/3) - SIZE/2, ARRAY_RECT, ARRAY_RECT); 44 | fill(0); 45 | text(arr[i], (((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT) + ARRAY_RECT/3, height/3 + ARRAY_RECT/2); 46 | } 47 | } 48 | 49 | void printMostCommon(int element){ 50 | textSize(16); 51 | if(multiple){ 52 | text("One of the most common elements is: " + element, 50, 3*(height/4)); 53 | } else { 54 | text("The most common element is: " + element , 55, 3*(height/4)); 55 | } 56 | } 57 | 58 | /* ----- DO NOT MODIFY CODE ABOVE THIS LINE ----- */ 59 | 60 | /* STUDENT TO FILL OUT */ 61 | int mostCommon(){ 62 | return -1; 63 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/16drawStacks/case1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/16drawStacks/case1.PNG -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/16drawStacks/case2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/16drawStacks/case2.PNG -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/16drawStacks/case3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/16drawStacks/case3.PNG -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/16drawStacks/drawStacksTemplate/drawStacksTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Given a array arr of n elements. Draw up to 10 stacks of rectangles 4 | where each element at index represent the number of rectangles in 5 | that stack. The number of rectangle on a stack can be at most 10. 6 | So at most 10 x 10 rectangles.If there at less than 10 elements 7 | in arr then draw n stacks, else draw for the first ten elements. 8 | If the arr[i] is greater than 10, draw 10 rectangles for stack i. 9 | For each stack i, the rectangle in that stack should be filled with 10 | the colors[i] 11 | 12 | 13 | Refer to given case and the corresponding image to see what should 14 | be the result 15 | 16 | CASE 1: 17 | arr = {1, 2, 3, 4, 5, 9, 8, 7, 6, 10} 18 | Refer to case1.png for expected result 19 | 20 | CASE 2: 21 | arr = {3, 12, 5, 0, 6, 10, 2, 3, 4, 9, 8, 5} 22 | Refer to case2.png for expected result 23 | 24 | CASE 3: 25 | arr = {0, 0, 5, 6, 3, 7} 26 | Refer to case3.png for expected result 27 | */ 28 | 29 | // Colors 30 | 31 | color lightsteelblue = color(176,196,222); 32 | color palegoldenrod = color(238,232,170); 33 | color lightsalmon = color(255,160,122); 34 | color lightyellow = color(255,255,224); 35 | color rosybrown = color(188,143,143); 36 | 37 | color palevioletred = color(219,112,147); 38 | color yellowgreen = color(154,205,50); 39 | color lightgreen = color(144,238,144); 40 | color honeydew = color(240,255,240); 41 | color lavender = color(230,230,250); 42 | 43 | 44 | // The rectangle in stack i should be filled in with colors[i] 45 | color[] colors = {lightsteelblue, palegoldenrod, lightsalmon, 46 | lightyellow, rosybrown, palevioletred, yellowgreen, 47 | lightgreen, honeydew, lavender}; 48 | 49 | color ghostwhite = color(248,248,255); 50 | // The maximum number of stacks 51 | final int MAX_NUM_STACK = 10; 52 | 53 | // This maximum number of rectangle on a stack 54 | final int MAX_NUM_OF_RECT_PER_STACK = 10; 55 | 56 | 57 | int[] arr = {0, 0, 5, 6, 3, 7}; 58 | 59 | void setup() { 60 | size(500,500); 61 | background(ghostwhite); 62 | drawStackOfRects(arr); 63 | 64 | } 65 | 66 | 67 | /* STUDENT TO FILL OUT */ 68 | void drawStackOfRects(int[] arr) { 69 | 70 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/1lines/linesSolution/linesSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | This program generates an array with 6 integers 3 | and calculates the total. Each time it draws a 4 | vertical line from the bottom whose length is 5 | proportional to the total. 6 | 7 | During every iteration of draw, one value of 8 | the array is changed and the updated array displayed. 9 | Lines for past totals must also be drawn but 10 | in lighter colour 11 | */ 12 | 13 | //create an integer array a containing 6 items 14 | int[] a = new int[6]; 15 | 16 | //DECLARE an integer array graphY 17 | int[] graphY; 18 | 19 | int n = 0; 20 | 21 | final int MARGIN = 40; 22 | 23 | void setup() { 24 | size(500, 150); 25 | //instantiate array graphY so it contains width number of items 26 | graphY = new int[width]; 27 | 28 | background(255); 29 | /* 30 | initialize each item of array a to a value between 1 and 9 31 | (including both 1 and 9) 32 | */ 33 | for (int i=0; i < a.length; i++) { 34 | a[i] = (int)random(1, 10); 35 | } 36 | } 37 | 38 | /* 39 | return the sum of all items 40 | of array passed to the function. 41 | some parameter-return value mappings: 42 | {1, 7, 2, 9} -> 19 43 | {8, 4, -7, -8} -> -3 44 | */ 45 | int total(int[] arr) { 46 | int result = 0; 47 | for (int i=0; i < arr.length; i++) { 48 | result+=arr[i]; 49 | } 50 | return result; 51 | } 52 | 53 | //DO NOT MODIFY ANY CODE BELOW THIS COMMENT 54 | 55 | void draw() { 56 | background(255); 57 | if (n == width - 1) 58 | noLoop(); 59 | display(a, height/3); 60 | graphY[n] = total(a); 61 | text("Total = "+graphY[n], width/2, 2*height/3); 62 | a[(int)random(a.length)] = (int)random(1, 10); 63 | for (int i=0; i <= n; i++) { 64 | if (i < n) { 65 | stroke(255, 0, 0, 127); 66 | strokeWeight(1); 67 | } else { 68 | stroke(255, 0, 0); 69 | strokeWeight(4); 70 | } 71 | line(i, height-graphY[i], i, height); 72 | } 73 | n++; 74 | } 75 | 76 | void display(int[] arr, int y) { 77 | float x = MARGIN; 78 | fill(0); 79 | textSize(MARGIN); 80 | textAlign(CENTER, CENTER); 81 | for (int i=0; i < arr.length; i++) { 82 | text(arr[i], x, y); 83 | x+=(width - MARGIN)/arr.length; 84 | if (x > width - MARGIN) { 85 | x = MARGIN; 86 | y+=MARGIN; 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/1lines/linesTemplate/linesTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | This program generates an array with 6 integers 3 | and calculates the total. Each time it draws a 4 | vertical line from the bottom whose length is 5 | proportional to the total. 6 | 7 | During every iteration of draw, one value of 8 | the array is changed and the updated array displayed. 9 | Lines for past totals must also be drawn but 10 | in lighter colour 11 | */ 12 | 13 | //create an integer array a containing 6 items 14 | 15 | //DECLARE an integer array graphY 16 | 17 | int n = 0; 18 | 19 | final int MARGIN = 40; 20 | 21 | void setup() { 22 | size(500, 150); 23 | //instantiate array graphY so it contains width number of items 24 | 25 | background(255); 26 | /* 27 | initialize each item of array a to a value between 1 and 9 28 | (including both 1 and 9) 29 | */ 30 | } 31 | 32 | /* 33 | return the sum of all items 34 | of array passed to the function. 35 | some parameter-return value mappings: 36 | {1, 7, 2, 9} -> 19 37 | {8, 4, -7, -8} -> -3 38 | */ 39 | int total(int[] arr) { 40 | } 41 | 42 | //DO NOT MODIFY ANY CODE BELOW THIS COMMENT 43 | 44 | void draw() { 45 | background(255); 46 | if (n == width - 1) 47 | noLoop(); 48 | display(a, height/3); 49 | graphY[n] = total(a); 50 | text("Total = "+graphY[n], width/2, 2*height/3); 51 | a[(int)random(a.length)] = (int)random(1, 10); 52 | for (int i=0; i <= n; i++) { 53 | if (i < n) { 54 | stroke(255, 0, 0, 127); 55 | strokeWeight(1); 56 | } else { 57 | stroke(255, 0, 0); 58 | strokeWeight(4); 59 | } 60 | line(i, height-graphY[i], i, height); 61 | } 62 | n++; 63 | } 64 | 65 | void display(int[] arr, int y) { 66 | float x = MARGIN; 67 | fill(0); 68 | textSize(MARGIN); 69 | textAlign(CENTER, CENTER); 70 | for (int i=0; i < arr.length; i++) { 71 | text(arr[i], x, y); 72 | x+=(width - MARGIN)/arr.length; 73 | if (x > width - MARGIN) { 74 | x = MARGIN; 75 | y+=MARGIN; 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/2createArrayFunction/createArrayFunctionSolution/createArrayFunctionSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | this program has a function newArray to create and return 3 | a boolean array. the function newArray has parameters 4 | size and value. size is the size (length) of the array 5 | to be created and value is the value that all items 6 | of the array should be initialised to. 7 | 8 | run the program once done and the output should indicate 9 | if completed correctly or not. 10 | */ 11 | 12 | /* DO NOT MODIFY SETUP */ 13 | void setup() { 14 | checkProgram(); 15 | } 16 | 17 | /* 18 | FUNCTION TO BE COMPLETED BY STUDENT AS PER THE 19 | INSTRUCTIONS AT THE TOP OF THE PROGRAM 20 | */ 21 | boolean[] newArray (int size, boolean value) { 22 | boolean[] result = new boolean[size]; 23 | 24 | for (int i = 0; i < result.length; i++) { 25 | result[i] = value; 26 | } 27 | 28 | return result; 29 | } 30 | 31 | /* DO NOT MODIFY */ 32 | void checkProgram() { 33 | boolean[] a1 = newArray(5, false); 34 | boolean[] a2 = newArray(1, true); 35 | boolean[] a3 = newArray(8, true); 36 | boolean[] a4 = newArray(35, false); 37 | 38 | boolean l1 = a1.length == 5; 39 | boolean l2 = a2.length == 1; 40 | boolean l3 = a3.length == 8; 41 | boolean l4 = a4.length == 35; 42 | 43 | boolean v1 = true; 44 | for (int i = 0; i < a1.length; i++) 45 | if(a1[i]) v1 = false; 46 | 47 | boolean v2 = true; 48 | for (int i = 0; i < a2.length; i++) 49 | if(!a2[i]) v2 = false; 50 | 51 | boolean v3 = true; 52 | for (int i = 0; i < a3.length; i++) 53 | if(!a3[i]) v3 = false; 54 | 55 | boolean v4 = true; 56 | for (int i = 0; i < a4.length; i++) 57 | if(a4[i]) v4 = false; 58 | 59 | if (l1 && l2 && l3 && l4) { 60 | if (v1 && v2 && v3 && v4) { 61 | println("correct!"); 62 | } else { 63 | println("incorrect. arrays aren't initialised correctly."); 64 | } 65 | } else { 66 | println("incorrect. arrays created with wrong size."); 67 | } 68 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/2createArrayFunction/createArrayFunctionTemplate/createArrayFunctionTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | this program has a function newArray to create and return 3 | a boolean array. the function newArray has parameters 4 | size and value. size is the size (length) of the array 5 | to be created and value is the value that all items 6 | of the array should be initialised to. 7 | 8 | run the program once done and the output should indicate 9 | if completed correctly or not. 10 | */ 11 | 12 | /* DO NOT MODIFY SETUP */ 13 | void setup() { 14 | checkProgram(); 15 | } 16 | 17 | /* 18 | FUNCTION TO BE COMPLETED BY STUDENT AS PER THE 19 | INSTRUCTIONS AT THE TOP OF THE PROGRAM 20 | */ 21 | boolean[] newArray (int size, boolean value) { 22 | } 23 | 24 | /* DO NOT MODIFY */ 25 | void checkProgram() { 26 | boolean[] a1 = newArray(5, false); 27 | boolean[] a2 = newArray(1, true); 28 | boolean[] a3 = newArray(8, true); 29 | boolean[] a4 = newArray(35, false); 30 | 31 | boolean l1 = a1.length == 5; 32 | boolean l2 = a2.length == 1; 33 | boolean l3 = a3.length == 8; 34 | boolean l4 = a4.length == 35; 35 | 36 | boolean v1 = true; 37 | for (int i = 0; i < a1.length; i++) 38 | if(a1[i]) v1 = false; 39 | 40 | boolean v2 = true; 41 | for (int i = 0; i < a2.length; i++) 42 | if(!a2[i]) v2 = false; 43 | 44 | boolean v3 = true; 45 | for (int i = 0; i < a3.length; i++) 46 | if(!a3[i]) v3 = false; 47 | 48 | boolean v4 = true; 49 | for (int i = 0; i < a4.length; i++) 50 | if(a4[i]) v4 = false; 51 | 52 | if (l1 && l2 && l3 && l4) { 53 | if (v1 && v2 && v3 && v4) { 54 | println("correct!"); 55 | } else { 56 | println("incorrect. arrays aren't initialised correctly."); 57 | } 58 | } else { 59 | println("incorrect. arrays created with wrong size."); 60 | } 61 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/3patterns/patternsSolution/patternsSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | The aim of this exercise is for students to define and intialize arrays with patterns. 3 | Student needs to initialize three arrays with different patterns. 4 | PATTERN 1: 0, 1, 2, 3, 4, .... 5 | PATTERN 2: 1, 2, 4, 8, 16, .... 6 | PATTERN 3: 1, -2, 3, -4, 5, -6, .... 7 | */ 8 | /* SOLUTION */ 9 | int pattern1[] = new int[10]; 10 | int pattern2[] = new int[10]; 11 | int pattern3[] = new int[10]; 12 | 13 | void setup(){ 14 | // PATTERN 1 15 | println("Pattern 1: "); 16 | for(int i = 0; i < pattern1.length; i++){ 17 | pattern1[i] = i; 18 | print(pattern1[i], ' '); 19 | } 20 | println(); 21 | // PATTERN 2 22 | println("Pattern 2: "); 23 | int value = 1; 24 | for(int i = 0; i < pattern2.length; i++){ 25 | pattern2[i] = value; 26 | value = value * 2; 27 | print(pattern2[i], ' '); 28 | } 29 | println(); 30 | // PATTERN 3 31 | println("Pattern 3: "); 32 | value = 1; 33 | for(int i = 0; i < pattern3.length; i++){ 34 | if(i % 2 == 0){ 35 | pattern3[i] = value; 36 | } else { 37 | pattern3[i] = value * -1; 38 | } 39 | value = value + 1; 40 | print(pattern3[i], ' '); 41 | } 42 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/3patterns/patternsTemplate/patternsTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | The aim of this exercise is for students to define and intialize arrays with patterns. 3 | Student needs to initialize three arrays with different patterns. 4 | PATTERN 1: 0, 1, 2, 3, 4, .... 5 | PATTERN 2: 1, 2, 4, 8, 16, .... 6 | PATTERN 3: 1, -2, 3, -4, 5, -6, .... 7 | */ 8 | 9 | /* STUDENT TO FILL IN */ 10 | // Create 3 arrays of equal size. 11 | 12 | void setup(){ 13 | // PATTERN 1 14 | println("Pattern 1: "); 15 | // Populate the first array with pattern 1. 16 | println(); 17 | 18 | // PATTERN 2 19 | println("Pattern 2: "); 20 | // Populate the second array with pattern 2. 21 | println(); 22 | 23 | // PATTERN 3 24 | println("Pattern 3: "); 25 | // Populate the third array with pattern 3. 26 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/4middleElement/middleElementSolution/middleElementSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | This program generates a randomly sized array of random integers. 3 | The aim of this exercise is for the student to calculate the middle index of an array 4 | The student should fill out the method findMiddleItem(). 5 | It should return the element in the middle of the array. 6 | If the array is of even size then either the floor or ceiling element may be returned. 7 | */ 8 | final int SIZE = (int)random(1, 10); 9 | final int ARRAY_RECT = 40; 10 | int arr[] = new int[SIZE]; 11 | 12 | void setup(){ 13 | size(400, 400); 14 | background(255); 15 | println("Array: "); 16 | for(int i = 0; i < SIZE; i++){ 17 | arr[i] = (int)random(0, 100); 18 | print(arr[i], ' '); 19 | } 20 | println(); 21 | int middleElement = findMiddleItem(); 22 | printArray(); 23 | printIndex(middleElement); 24 | println("The middle element is:", middleElement); 25 | } 26 | 27 | void printArray(){ 28 | for(int i = 0; i < SIZE; i ++){ 29 | fill(255); 30 | if(i == SIZE/2){ 31 | fill(0, 255, 0); 32 | } 33 | rect(((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT, (height/3) - SIZE/2, ARRAY_RECT, ARRAY_RECT); 34 | fill(0); 35 | text(arr[i], (((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT) + ARRAY_RECT/3, height/3 + ARRAY_RECT/2); 36 | } 37 | } 38 | 39 | void printIndex(int element){ 40 | textSize(15); 41 | text("The middle element is: " + element, width/4, 3*(height/4)); 42 | } 43 | 44 | /* SOLUTION */ 45 | int findMiddleItem(){ 46 | int middleIndex = arr.length/2; 47 | return arr[middleIndex]; 48 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/4middleElement/middleElementTemplate/middleElementTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | This program generates a randomly sized array of random integers. 3 | The aim of this exercise is for the student to calculate the middle index of an array 4 | The student should fill out the method findMiddleItem(). 5 | It should return the element in the middle of the array. 6 | If the array is of even size then either the floor or ceiling element may be returned. 7 | */ 8 | final int SIZE = (int)random(1, 10); 9 | final int ARRAY_RECT = 40; 10 | int arr[] = new int[SIZE]; 11 | 12 | void setup(){ 13 | size(400, 400); 14 | background(255); 15 | println("Array: "); 16 | for(int i = 0; i < SIZE; i++){ 17 | arr[i] = (int)random(0, 100); 18 | print(arr[i], ' '); 19 | } 20 | println(); 21 | int middleElement = findMiddleItem(); 22 | printArray(); 23 | printIndex(middleElement); 24 | println("The middle element is:", middleElement); 25 | } 26 | 27 | void printArray(){ 28 | for(int i = 0; i < SIZE; i ++){ 29 | fill(255); 30 | if(i == SIZE/2){ 31 | fill(0, 255, 0); 32 | } 33 | rect(((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT, (height/3) - SIZE/2, ARRAY_RECT, ARRAY_RECT); 34 | fill(0); 35 | text(arr[i], (((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT) + ARRAY_RECT/3, height/3 + ARRAY_RECT/2); 36 | } 37 | } 38 | 39 | void printIndex(int element){ 40 | textSize(15); 41 | text("The middle element is: " + element, width/4, 3*(height/4)); 42 | } 43 | 44 | /* ----- DO NOT MOIDIFY CODE ABOVE THIS LINE ----- */ 45 | 46 | /* STUDENT TO FILL OUT */ 47 | int findMiddleItem(){ 48 | return -1; 49 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/5average/averageSolution/averageSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | This program generates an integer array of a random size 3 | containing random integers. 4 | Student needs to calculate the average of the array by 5 | filling out the average() function. 6 | */ 7 | final int SIZE = (int)random(1, 50); 8 | int arr[] = new int[SIZE]; 9 | 10 | void setup(){ 11 | for(int i = 0; i < SIZE; i++){ 12 | arr[i] = (int)random(0, 100); 13 | } 14 | average(); 15 | } 16 | 17 | /* SOLUTION */ 18 | void average(){ 19 | /* Store the average of all elements in the array in an 20 | int variable called average */ 21 | int average = 0; 22 | for(int i = 0; i < arr.length; i++){ 23 | average = average + arr[i]; 24 | } 25 | average = average/arr.length; 26 | // Print average to the console 27 | println(average); 28 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/5average/averageTemplate/averageTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | This program generates an integer array of a random size 3 | containing random integers. 4 | Student needs to calculate the average of the array by 5 | filling out the average() function. 6 | */ 7 | final int SIZE = (int)random(1, 50); 8 | int arr[] = new int[SIZE]; 9 | 10 | void setup(){ 11 | for(int i = 0; i < SIZE; i++){ 12 | arr[i] = (int)random(0, 100); 13 | } 14 | average(); 15 | } 16 | 17 | /* STUDENT TO FILL OUT */ 18 | void average(){ 19 | /* Store the average of all elements in the array in an 20 | int variable called average */ 21 | 22 | // Print average to the console 23 | 24 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/6sumEvenIndex/sumEvenIndexSolution/sumEvenIndexSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | The exercise is to sum every element in array arr with an even index 3 | and return that value 4 | Fill out sumOfElementWithEvenIndex 5 | */ 6 | 7 | final int ARRAY_RECT = 40; 8 | 9 | int[] arr = {80,60,10,50,23}; 10 | final int SIZE = arr.length; 11 | 12 | void setup() { 13 | size(400, 400); 14 | background(255); 15 | int result = sumOfElementWithEvenIndex(arr); 16 | println(result); // result should be 113 17 | 18 | printArray(); 19 | printSumCommon(result); 20 | } 21 | 22 | /* STUDENT TO FILL OUT */ 23 | // This function return the sum of the element in arr 24 | // with even index 25 | int sumOfElementWithEvenIndex(int[] arr) { 26 | int sum = 0; 27 | for(int i =0; i < arr.length; i += 2) { 28 | sum += arr[i]; 29 | } 30 | return sum; 31 | 32 | } 33 | 34 | 35 | /* ----- DO NOT MODIFY CODE BELOW THIS LINE ----- */ 36 | 37 | void printArray(){ 38 | for(int i = 0; i < SIZE; i ++){ 39 | fill(255); 40 | rect(((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT, (height/3) - SIZE/2, ARRAY_RECT, ARRAY_RECT); 41 | fill(0); 42 | text(arr[i], (((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT) + ARRAY_RECT/3, height/3 + ARRAY_RECT/2); 43 | } 44 | } 45 | 46 | 47 | void printSumCommon(int element){ 48 | textSize(16); 49 | 50 | text("Sum of of numbers in arr with even\n index is: " + element, 50, 3*(height/4)); 51 | 52 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/6sumEvenIndex/sumEvenIndexTemplate/sumEvenIndexTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | The exercise is to sum every element in array arr with an even index 3 | and return that value 4 | Fill out sumOfElementWithEvenIndex 5 | */ 6 | 7 | final int ARRAY_RECT = 40; 8 | 9 | int[] arr = {80,60,10,50,23}; 10 | final int SIZE = arr.length; 11 | 12 | void setup() { 13 | size(400, 400); 14 | background(255); 15 | int result = sumOfElementWithEvenIndex(arr); 16 | println(result); // result should be 113 17 | 18 | printArray(); 19 | printSumCommon(result); 20 | } 21 | 22 | 23 | /* STUDENT TO FILL OUT */ 24 | // This function return the sum of the element in arr 25 | // with even index 26 | int sumOfElementWithEvenIndex(int[] arr) { 27 | return 0; // Dummy value 28 | } 29 | 30 | 31 | /* ----- DO NOT MODIFY CODE BELOW THIS LINE ----- */ 32 | 33 | void printArray(){ 34 | for(int i = 0; i < SIZE; i ++){ 35 | fill(255); 36 | rect(((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT, (height/3) - SIZE/2, ARRAY_RECT, ARRAY_RECT); 37 | fill(0); 38 | text(arr[i], (((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT) + ARRAY_RECT/3, height/3 + ARRAY_RECT/2); 39 | } 40 | } 41 | 42 | 43 | void printSumCommon(int element){ 44 | textSize(16); 45 | 46 | text("Sum of of numbers in arr with even\n index is: " + element, 50, 3*(height/4)); 47 | 48 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/7sumPosNeg/sumPosNegSolution/sumPosNegSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | In setup, print out the sum of positive numbers and negative numbers in a array. 3 | For example [2, 0, -5, -7, 3] will print 4 | 5 5 | -12 6 | 7 | All positive numbers will be highlighted with lavender color 8 | All negative numbers will be highlighted with a thistle color 9 | */ 10 | 11 | color lavender = color(230,230,250); 12 | color thistle = color(216,191,216); 13 | 14 | final int ARRAY_RECT = 40; 15 | 16 | 17 | int[] arr = {2, 0, -5, -7, 3}; 18 | final int SIZE = arr.length; 19 | 20 | // Stores the sum of the positive numbers 21 | int positiveSum = 0; 22 | 23 | //Stores the sum of the negative numbers 24 | int negativeSum = 0; 25 | void setup() { 26 | size(400, 400); 27 | background(255); 28 | // Do the task here 29 | for(int i = 0; i < arr.length; i++) { 30 | if(arr[i] > 0){ 31 | positiveSum += arr[i]; 32 | } 33 | if(arr[i] < 0){ 34 | negativeSum += arr[i]; 35 | } 36 | } 37 | // Now print the sum of the positive numbers in the array, then 38 | // print the sum of the negative numbers in the array 39 | println(positiveSum); 40 | println(negativeSum); 41 | // Dont modify 42 | printArray(); 43 | printSums(); 44 | } 45 | 46 | 47 | /* ----- DO NOT MODIFY CODE BELOW THIS LINE ----- */ 48 | 49 | void printArray(){ 50 | for(int i = 0; i < SIZE; i ++){ 51 | if(arr[i] > 0) 52 | fill(lavender); 53 | else if(arr[i] < 0) 54 | fill(thistle); 55 | else 56 | fill(255); 57 | rect(((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT, (height/3) - SIZE/2, ARRAY_RECT, ARRAY_RECT); 58 | fill(0); 59 | text(arr[i], (((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT) + ARRAY_RECT/3, height/3 + ARRAY_RECT/2); 60 | } 61 | } 62 | 63 | void printSums() { 64 | textSize(16); 65 | text("Sum of positive numbers in arr is: " + positiveSum, 50, 3*(height/4)); 66 | text("Sum of negative numbers in arr is: " + negativeSum, 50, 16+3*(height/4)); 67 | 68 | 69 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/7sumPosNeg/sumPosNegTemplate/sumPosNegTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | In setup, print out the sum of positive numbers and negative numbers in a array. 3 | For example [2, 0, -5, -7, 3] will print 4 | 5 5 | -12 6 | 7 | All positive numbers will be highlighted with lavender color 8 | All negative numbers will be highlighted with a thistle color 9 | */ 10 | 11 | color lavender = color(230,230,250); 12 | color thistle = color(216,191,216); 13 | 14 | final int ARRAY_RECT = 40; 15 | 16 | // Stores the sum of the positive numbers 17 | int positiveSum = 0; 18 | 19 | //Stores the sum of the negative numbers 20 | int negativeSum = 0; 21 | 22 | int[] arr = {2, 0, -5, -7, 3}; 23 | final int SIZE = arr.length; 24 | void setup() { 25 | size(400, 400); 26 | background(255); 27 | // DO THE TASK HERE 28 | 29 | 30 | // DO NOT MODIFY CODE AFTER THIS LINE 31 | 32 | // Now print the sum of the positive numbers in the array, then 33 | // print the sum of the negative numbers in the array 34 | println(positiveSum); 35 | println(negativeSum); 36 | // Dont modify 37 | printArray(); 38 | printSums(); 39 | } 40 | 41 | 42 | /* ----- DO NOT MODIFY CODE BELOW THIS LINE ----- */ 43 | 44 | void printArray(){ 45 | for(int i = 0; i < SIZE; i ++){ 46 | if(arr[i] > 0) 47 | fill(lavender); 48 | else if(arr[i] < 0) 49 | fill(thistle); 50 | else 51 | fill(255); 52 | rect(((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT, (height/3) - SIZE/2, ARRAY_RECT, ARRAY_RECT); 53 | fill(0); 54 | text(arr[i], (((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT) + ARRAY_RECT/3, height/3 + ARRAY_RECT/2); 55 | } 56 | } 57 | 58 | void printSums() { 59 | textSize(16); 60 | text("Sum of positive numbers in arr is: " + positiveSum, 50, 3*(height/4)); 61 | text("Sum of negative numbers in arr is: " + negativeSum, 50, 16+3*(height/4)); 62 | 63 | 64 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/8findElement/findElementTemplate/findElementTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | This program generates a randomly sized array of 3 | random integers. 4 | Students need to fill out the findElement(int element) method. 5 | This method takes the element to be found in the array as a parameter. 6 | If the element is found then the index of the first occurance of the 7 | element should be returned. 8 | If the element is not found then return -1 9 | */ 10 | final int SIZE = (int)random(1, 10); 11 | final int ARRAY_RECT = 40; 12 | int arr[] = new int[SIZE]; 13 | 14 | void setup(){ 15 | size(400, 400); 16 | background(255); 17 | println("Array is: "); 18 | for(int i = 0; i < arr.length; i++){ 19 | arr[i] = (int)random(1, 5); 20 | print(arr[i], ' '); 21 | } 22 | println(); 23 | int element = (int)random(1, 5); 24 | printElement(element); 25 | int index = findElement(element); 26 | printArray(index); 27 | if(index < 0){ 28 | println("The element", element, "is not in the array"); 29 | } else { 30 | println("The element", element, "is at index", index, "in the array"); 31 | } 32 | printIndex(index); 33 | } 34 | 35 | void printElement(int element){ 36 | textSize(20); 37 | fill(0); 38 | text("Find the first occurance of element: " + element, 20, height/3); 39 | } 40 | 41 | void printArray(int index){ 42 | for(int i = 0; i < SIZE; i ++){ 43 | fill(255); 44 | if(i == index){ 45 | fill(0, 255, 0); 46 | } 47 | rect(((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT, (height/2) - SIZE/2, ARRAY_RECT, ARRAY_RECT); 48 | fill(0); 49 | text(arr[i], (((10 - SIZE)* ARRAY_RECT/2) + i * ARRAY_RECT) + ARRAY_RECT/3, height/2 + ARRAY_RECT/2); 50 | } 51 | } 52 | 53 | void printIndex(int index){ 54 | textSize(15); 55 | if(index < 0){ 56 | text("The element is not in the array", 40, 3*(height/4)); 57 | } else { 58 | text("The first occurance of the element was found at: " + index, 10, 3*(height/4)); 59 | } 60 | } 61 | 62 | /* ----- DO NOT MODIFY CODE ABOVE THIS LINE ----- */ 63 | 64 | /* STUDENT TO FILL OUT */ 65 | int findElement(int element){ 66 | return -1; 67 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/9compare/compareSolution/compareSolution.pde: -------------------------------------------------------------------------------- 1 | /* DO NOT MODIFY SETUP */ 2 | void setup() { 3 | checkProgram(); 4 | } 5 | 6 | /* 7 | TASK: 8 | complete the function compare. 9 | this function takes in two char arrays and 10 | returns the amount of times both arrays have the 11 | same character in the same index. 12 | 13 | examples: 14 | {'r', 's', 'c', '@'}, {'r', 'a', 'c'} -> 2 15 | {'?', '7', 'v'}, {'q', 'c', ')'} -> 0 16 | {'8', '%', '3', 'd'}, {'8', '3', 'd'} -> 1 17 | 18 | once completed, check output to see if done correctly 19 | */ 20 | int compare(char[] a, char[] b) { 21 | // find the smaller array out of a and b 22 | // stores the length of the smaller array in smaller 23 | int smaller = a.length; 24 | if (a.length > b.length) { 25 | smaller = b.length; 26 | } 27 | 28 | int count = 0; 29 | for (int i = 0; i < smaller; i++) { 30 | if (a[i] == b[i]) { 31 | count++; 32 | } 33 | } 34 | 35 | return count; 36 | } 37 | 38 | /* DO NOT MODIFY */ 39 | void checkProgram() { 40 | char[] a1 = {'g', '3', 'b', '!', 'a', 's', '>'}; 41 | char[] b1 = {'g', '3', 'm', '!', '5'}; 42 | boolean c1 = compare(a1, b1) == 3; 43 | 44 | char[] a2 = {'r', 's', 'c', '@'}; 45 | char[] b2 = {'r', 'a', 'c'}; 46 | boolean c2 = compare(a2, b2) == 2; 47 | 48 | char[] a3 = {'?', '7', 'v'}; 49 | char[] b3 = {'q', 'c', ')'}; 50 | boolean c3 = compare(a3, b3) == 0; 51 | 52 | char[] a4 = {'8', '%', '3', 'd'}; 53 | char[] b4 = {'8', '3', 'd'}; 54 | boolean c4 = compare(a4, b4) == 1; 55 | 56 | char[] a5 = {'1', '2'}; 57 | char[] b5 = {'2', '1'}; 58 | boolean c5 = compare(a5, b5) == 0; 59 | 60 | if (c1 && c2 && c3 && c4 && c5) { 61 | println("correct!"); 62 | } else { 63 | println("incorrect"); 64 | } 65 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/OneDimensionArrays/9compare/compareTemplate/compareTemplate.pde: -------------------------------------------------------------------------------- 1 | /* DO NOT MODIFY SETUP */ 2 | void setup() { 3 | checkProgram(); 4 | } 5 | 6 | /* 7 | TASK: 8 | complete the function compare. 9 | this function takes in two char arrays and 10 | returns the amount of times both arrays have the 11 | same character in the same index. 12 | 13 | examples: 14 | {'r', 's', 'c', '@'}, {'r', 'a', 'c'} -> 2 15 | {'?', '7', 'v'}, {'q', 'c', ')'} -> 0 16 | {'8', '%', '3', 'd'}, {'8', '3', 'd'} -> 1 17 | 18 | once completed, check output to see if done correctly 19 | */ 20 | int compare(char[] a, char[] b) { 21 | // find the smaller array out of a and b 22 | // stores the length of the smaller array in smaller 23 | int smaller = a.length; 24 | if (a.length > b.length) { 25 | smaller = b.length; 26 | } 27 | } 28 | 29 | /* DO NOT MODIFY */ 30 | void checkProgram() { 31 | char[] a1 = {'g', '3', 'b', '!', 'a', 's', '>'}; 32 | char[] b1 = {'g', '3', 'm', '!', '5'}; 33 | boolean c1 = compare(a1, b1) == 3; 34 | 35 | char[] a2 = {'r', 's', 'c', '@'}; 36 | char[] b2 = {'r', 'a', 'c'}; 37 | boolean c2 = compare(a2, b2) == 2; 38 | 39 | char[] a3 = {'?', '7', 'v'}; 40 | char[] b3 = {'q', 'c', ')'}; 41 | boolean c3 = compare(a3, b3) == 0; 42 | 43 | char[] a4 = {'8', '%', '3', 'd'}; 44 | char[] b4 = {'8', '3', 'd'}; 45 | boolean c4 = compare(a4, b4) == 1; 46 | 47 | char[] a5 = {'1', '2'}; 48 | char[] b5 = {'2', '1'}; 49 | boolean c5 = compare(a5, b5) == 0; 50 | 51 | if (c1 && c2 && c3 && c4 && c5) { 52 | println("correct!"); 53 | } else { 54 | println("incorrect"); 55 | } 56 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/Strings/2extract/extractSolution/extractSolution.pde: -------------------------------------------------------------------------------- 1 | /* DO NOT MODIFY SETUP */ 2 | void setup() { 3 | String str1 = "Introduction to Computer Programming (COMP115)"; 4 | String str2 = "San Fransisco (s f) is a city in the United States (u s)"; 5 | String str3 = "( i))(@)*F)G(e0g)}{(()@&( "; 6 | String str4 = "United Nations (un!)"; 7 | 8 | println(extract(str1) + extract(str3) + extract(str2) + extract(str4)); 9 | } 10 | 11 | 12 | /* 13 | TASK 14 | complete the function extract such that it returns a String which 15 | contains the contents inside the first bracket pair of String 16 | str. hint: use substring and indexOf 17 | 18 | complete task successfully to reveal secret message in the output. 19 | 20 | assume open and closed bracket exists in String passed 21 | assume no nested brackets in String passed. 22 | 23 | examples: 24 | "Yesterday (Wednesday) I played tennis." -> "Wednesday" 25 | "Australia (aus) and New Zealand (nz) -> "aus" 26 | */ 27 | String extract(String str) { 28 | String result = str.substring(str.indexOf('(') + 1, str.indexOf(')')); 29 | return result; 30 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/Strings/2extract/extractTemplate/extractTemplate.pde: -------------------------------------------------------------------------------- 1 | /* DO NOT MODIFY SETUP */ 2 | void setup() { 3 | String str1 = "Introduction to Computer Programming (COMP115)"; 4 | String str2 = "San Fransisco (s f) is a city in the United States (u s)"; 5 | String str3 = "( i))(@)*F)G(e0g)}{(()@&( "; 6 | String str4 = "United Nations (un!)"; 7 | 8 | println(extract(str1) + extract(str3) + extract(str2) + extract(str4)); 9 | } 10 | 11 | 12 | /* 13 | TASK 14 | complete the function extract such that it returns a String which 15 | contains the contents inside the first bracket pair of String 16 | str. hint: use substring and indexOf 17 | 18 | complete task successfully to reveal secret message in the output. 19 | 20 | assume open and closed bracket exists in String passed 21 | assume no nested brackets in String passed. 22 | 23 | examples: 24 | "Yesterday (Wednesday) I played tennis." -> "Wednesday" 25 | "Australia (aus) and New Zealand (nz) -> "aus" 26 | */ 27 | String extract(String str) { 28 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/Strings/3splitToArray/splitToArraySolution/splitToArraySolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | The task of this program is to write a function that when 3 | passed a String, returns a char array of the String split 4 | into its characters. 5 | */ 6 | 7 | /* DO NOT MODIFY SETUP */ 8 | void setup() { 9 | String toBeSplit = "The quick brown fox jumps over the lazy dog."; 10 | char[] split = splitString(toBeSplit); 11 | printSplitString(split); 12 | } 13 | 14 | 15 | char[] splitString(String str) { 16 | /* 17 | TASK 1: create a new char array result with its size equal 18 | to the amount of characters in the String 19 | */ 20 | char[] result = new char[str.length()]; 21 | 22 | /* 23 | TASK 2: split the String str into its characters in the 24 | char array result 25 | */ 26 | for (int i = 0; i < str.length(); i++) { 27 | result[i] = str.charAt(i); 28 | } 29 | 30 | return result; 31 | } 32 | 33 | /* DO NOT MODIFY */ 34 | void printSplitString(char[] a) { 35 | println("Split string:"); 36 | print("["); 37 | for (int i = 0; i < a.length - 1; i++) { 38 | print(a[i] + ", "); 39 | } 40 | println(a[a.length - 1] + "]"); 41 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/Strings/3splitToArray/splitToArrayTemplate/splitToArrayTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | The task of this program is to write a function that when 3 | passed a String, returns a char array of the String split 4 | into its characters. 5 | */ 6 | 7 | /* DO NOT MODIFY SETUP */ 8 | void setup() { 9 | String toBeSplit = "The quick brown fox jumps over the lazy dog."; 10 | char[] split = splitString(toBeSplit); 11 | printSplitString(split); 12 | } 13 | 14 | char[] splitString(String str) { 15 | /* 16 | TASK 1: create a new char array result with its size equal 17 | to the amount of characters in the String 18 | */ 19 | 20 | /* 21 | TASK 2: split the String str into its characters in the 22 | char array result 23 | */ 24 | 25 | return result; 26 | } 27 | 28 | /* DO NOT MODIFY */ 29 | void printSplitString(char[] a) { 30 | println("Split string:"); 31 | print("["); 32 | for (int i = 0; i < a.length - 1; i++) { 33 | print(a[i] + ", "); 34 | } 35 | println(a[a.length - 1] + "]"); 36 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/Strings/4isReverse/isReverseSolution/isReverseSolution.pde: -------------------------------------------------------------------------------- 1 | /* DO NOT MODIFY SETUP */ 2 | void setup() { 3 | checkFunction(); 4 | } 5 | 6 | /* 7 | TASK 8 | complete the isReverse function which takes in two 9 | Strings a and b and returns true if the two Strings 10 | are identical reverses of each other and false if 11 | otherwise. 12 | 13 | examples: 14 | "abc", "cba" -> true 15 | "abc", "cbaa" -> false 16 | "7", "7" -> true 17 | */ 18 | boolean isReverse(String a, String b) { 19 | // check length is equal for both strings 20 | if (a.length() != b.length()) { 21 | return false; 22 | } 23 | 24 | // check indexes 25 | for (int i = 0; i < a.length(); i++) { 26 | if (a.charAt(i) != b.charAt((b.length() - 1) - i)) { 27 | return false; 28 | } 29 | } 30 | 31 | return true; 32 | } 33 | 34 | /* DO NOT MODIFY */ 35 | void checkFunction() { 36 | String s1 = "racecar"; 37 | String s2 = "abcdefg"; 38 | String s3 = "gfedcba"; 39 | String s4 = "gfeecba"; 40 | String s5 = "gfedcbaa"; 41 | String s6 = "abcdefgh"; 42 | String s7 = "- "; 43 | String s8 = " -"; 44 | 45 | boolean b1 = isReverse(s1, s1) == true; 46 | boolean b2 = isReverse(s1, s2) == false; 47 | boolean b3 = isReverse(s2, s3) == true; 48 | boolean b4 = isReverse(s2, s4) == false; 49 | boolean b5 = isReverse(s2, s5) == false; 50 | boolean b6 = isReverse(s3, s6) == false; 51 | boolean b7 = isReverse(s7, s8) == true; 52 | 53 | if (b1 && b2 && b3 && b4 && b5 && b6 && b7) { 54 | println("correct!"); 55 | } else { 56 | if (!b5) { 57 | println("incorrect. did you check both strings were of same length?"); 58 | } else { 59 | println("incorrect"); 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/Strings/4isReverse/isReverseTemplate/isReverseTemplate.pde: -------------------------------------------------------------------------------- 1 | /* DO NOT MODIFY SETUP */ 2 | void setup() { 3 | checkFunction(); 4 | } 5 | 6 | /* 7 | TASK 8 | complete the isReverse function which takes in two 9 | Strings a and b and returns true if the two Strings 10 | are identical reverses of each other and false if 11 | otherwise. 12 | 13 | examples: 14 | "abc", "cba" -> true 15 | "abc", "cbaa" -> false 16 | "7", "7" -> true 17 | */ 18 | boolean isReverse(String a, String b) { 19 | // check length is equal for both strings 20 | if (a.length() != b.length()) { 21 | return false; 22 | } 23 | 24 | // check indexes 25 | for (int i = 0; i < a.length(); i++) { 26 | if (a.charAt(i) != b.charAt((b.length() - 1) - i)) { 27 | return false; 28 | } 29 | } 30 | 31 | return true; 32 | } 33 | 34 | /* DO NOT MODIFY */ 35 | void checkFunction() { 36 | String s1 = "racecar"; 37 | String s2 = "abcdefg"; 38 | String s3 = "gfedcba"; 39 | String s4 = "gfeecba"; 40 | String s5 = "gfedcbaa"; 41 | String s6 = "abcdefgh"; 42 | String s7 = "- "; 43 | String s8 = " -"; 44 | 45 | boolean b1 = isReverse(s1, s1) == true; 46 | boolean b2 = isReverse(s1, s2) == false; 47 | boolean b3 = isReverse(s2, s3) == true; 48 | boolean b4 = isReverse(s2, s4) == false; 49 | boolean b5 = isReverse(s2, s5) == false; 50 | boolean b6 = isReverse(s3, s6) == false; 51 | boolean b7 = isReverse(s7, s8) == true; 52 | 53 | if (b1 && b2 && b3 && b4 && b5 && b6 && b7) { 54 | println("correct!"); 55 | } else { 56 | if (!b5) { 57 | println("incorrect. did you check both strings were of same length?"); 58 | } else { 59 | println("incorrect"); 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/Strings/withoutVowelSolution/withoutVowelSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | The purpose of this exercise is to write a function that takes a String and 3 | return a new String with all vowels removed, whether it is lowercase or 4 | uppercase. For example the string "abcIwoQu" will become "bcwQ" 5 | Fill out the function stringWithoutVowels. You can declare helper functions 6 | to assist you 7 | */ 8 | 9 | char[] vowels = {'a', 'e', 'i', 'o', 'u'}; 10 | 11 | String s = "KaeiTyoUB"; 12 | 13 | void setup() { 14 | String sWithoutVowels = stringWithoutVowels(s); 15 | println(sWithoutVowels); //KTyB 16 | } 17 | 18 | 19 | // Return a new string that remove all the vowels in the String str 20 | // Ensure your function works whether str contains a mix of uppercase 21 | // and lowercase characters and digits 22 | String stringWithoutVowels(String str) { 23 | // First convert all character in str to lowercase and store it into 24 | // a new String 25 | String strInLowerCase = str.toLowerCase(); 26 | //str = str.toLowerCase(); 27 | // Declare a new String variable to hold new string without vowels 28 | String s = ""; 29 | // Loop through the string 30 | for(int i = 0; i < strInLowerCase.length(); i++){ 31 | 32 | char cInLowerCase = strInLowerCase.charAt(i); 33 | char c = str.charAt(i); 34 | // Compare the lowercase c and if the character is not a 35 | // vowel then concatenate it onto s 36 | if(notAVowel(cInLowerCase)) 37 | s += c; 38 | } 39 | // Return the new string without vowels 40 | return s; 41 | } 42 | 43 | // Helper function that determines whether c is a lowercase vowel or not 44 | boolean notAVowel(char c) { 45 | for(int i = 0; i < vowels.length; i++){ 46 | if(c == vowels[i]) 47 | return false; 48 | } 49 | return true; 50 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/A&SPracticePackage/Strings/withoutVowelTemplate/withoutVowelTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | The purpose of this exercise is to write a function that takes a String and 3 | return a new String with all vowels removed, whether it is lowercase or 4 | uppercase. For example the string "abcIwoQu" will become "bcwQ" 5 | Fill out the function stringWithoutVowels. You can declare helper functions 6 | to assist you 7 | */ 8 | 9 | String s = "KaeiTyoUB"; 10 | 11 | void setup() { 12 | String sWithoutVowels = stringWithoutVowels(s); 13 | println(sWithoutVowels); //KTyB 14 | } 15 | 16 | // Please fill out this function 17 | // Return a new string that remove all the vowels in the String str 18 | // Ensure your function works whether str contains a mix of uppercase 19 | // and lowercase characters and digits 20 | String stringWithoutVowels(String str) { 21 | return ""; // Dummy value 22 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/10twoButtons/twoButtonsOutput.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/conditionsPracticePackage/10twoButtons/twoButtonsOutput.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/10twoButtons/twoButtonsSolution/twoButtonsSolution.pde: -------------------------------------------------------------------------------- 1 | int DIA = 30; 2 | int buttonWidth = 60; 3 | int buttonHeight = 40; 4 | int offset = 10; // number of pixels between border and button 5 | 6 | boolean blue = true; 7 | 8 | void setup() { 9 | size(500, 500); 10 | background(255); 11 | } 12 | 13 | void draw() { 14 | //draw colour changebutton 15 | if (blue) { 16 | fill(30, 145, 255); 17 | } else { 18 | fill(255, 140, 0); 19 | } 20 | rect(offset, offset, buttonWidth, buttonHeight); 21 | 22 | // draw clear button 23 | fill(255); 24 | rect(width - (offset + buttonWidth), offset, buttonWidth, buttonHeight); 25 | } 26 | 27 | void mouseClicked() { 28 | if (mouseX > offset && mouseX < offset + buttonWidth 29 | && mouseY > offset && mouseY < offset + buttonHeight) { // colour change button pressed 30 | blue = !blue; 31 | } else if (mouseX > width - (offset + buttonWidth) && mouseX < width - offset 32 | && mouseY > offset && mouseY < offset + buttonHeight) { // clear button pressed 33 | background(255); 34 | } else { 35 | // draw circle 36 | if (blue) { 37 | fill(30, 145, 255); 38 | } else { 39 | fill(255, 140, 0); 40 | } 41 | ellipse(mouseX, mouseY, DIA, DIA); 42 | } 43 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/11rebound/reboundOutput.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/conditionsPracticePackage/11rebound/reboundOutput.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/11rebound/reboundSolution/reboundSolution.pde: -------------------------------------------------------------------------------- 1 | float x1, y1, x2, y2; 2 | float spdX1, spdY1, spdX2, spdY2; 3 | float dia = 50; 4 | 5 | void setup() { 6 | size(300, 300); 7 | 8 | /* 9 | x1, y1, x2, y2 are randomized in a way 10 | that the entire ball is within the screen 11 | */ 12 | 13 | x1 = random(dia/2, width - dia/2); 14 | y1 = random(dia/2, height - dia/2); 15 | x2 = random(dia/2, width - dia/2); 16 | y2 = random(dia/2, height - dia/2); 17 | 18 | spdX1 = random(1, 3); //initialize it to be positive 19 | 20 | if (random(1) < 0.5) //with a 50% probablity 21 | spdX1*=-1; //make it negative 22 | 23 | /* 24 | i don't initialize speed to be random(-3, 3) because 25 | with a small probablity, it can be 0 or a very very 26 | small value like 0.001, which would make the ball 27 | be very slow/ still 28 | */ 29 | 30 | //similarly the others 31 | spdY1 = random(1, 3); 32 | if (random(1) < 0.5) 33 | spdY1*=-1; 34 | 35 | spdX2 = random(1, 3); 36 | if (random(1) < 0.5) 37 | spdX2*=-1; 38 | 39 | spdY2 = random(1, 3); 40 | if (random(1) < 0.5) 41 | spdY2*=-1; 42 | } 43 | 44 | void draw() { 45 | background(0); 46 | noStroke(); 47 | 48 | //draw the balls 49 | fill(255, 0, 0); 50 | ellipse(x1, y1, dia, dia); 51 | fill(240, 240, 80); 52 | ellipse(x2, y2, dia, dia); 53 | 54 | //update locations 55 | x1+=spdX1; 56 | y1+=spdY1; 57 | x2+=spdX2; 58 | y2+=spdY2; 59 | 60 | if(x1 <= dia/2 || x1 >= width - dia/2) 61 | spdX1*=-1; 62 | if(y1 <= dia/2 || y1 >= height - dia/2) 63 | spdY1*=-1; 64 | if(x2 <= dia/2 || x2 >= width - dia/2) 65 | spdX2*=-1; 66 | if(y2 <= dia/2 || y2 >= height - dia/2) 67 | spdY2*=-1; 68 | 69 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/12flickr/flickrOutput.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/conditionsPracticePackage/12flickr/flickrOutput.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/12flickr/flickrSolution/flickrSolution.pde: -------------------------------------------------------------------------------- 1 | final float DIA = 30; 2 | float x1, x2; 3 | boolean redInFront = false; 4 | 5 | void setup() { 6 | size(300,300); 7 | background(0); 8 | x1 = width/2-DIA; 9 | x2 = width/2+DIA; 10 | } 11 | 12 | void draw() { 13 | background(0); 14 | noStroke(); 15 | if(redInFront == true) { 16 | //blue ball 17 | fill(0,0,255); 18 | ellipse(x2, height/2, DIA, DIA); 19 | x1 = x1 - 1; //blue ball moves left 20 | 21 | //red ball 22 | fill(255,0,0); 23 | ellipse(x1, height/2, DIA, DIA); 24 | x2 = x2 + 1; //red ball moves right 25 | } 26 | else { 27 | fill(255,0,0); 28 | ellipse(x1, height/2, DIA, DIA); 29 | x1 = x1 + 1; 30 | 31 | fill(0,0,255); 32 | ellipse(x2, height/2, DIA, DIA); 33 | x2 = x2 - 1; 34 | } 35 | if(abs(x1 - width/2) > DIA) { //if you reach the extreme 36 | redInFront = !redInFront; 37 | } 38 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/1fade/fadeOutput.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/conditionsPracticePackage/1fade/fadeOutput.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/1fade/fadeSolution/fadeSolution.pde: -------------------------------------------------------------------------------- 1 | final int LENGTH = 150; 2 | int alpha = 255; 3 | 4 | void setup() { 5 | size(500, 300); 6 | background(255); 7 | } 8 | 9 | void draw() { 10 | background(255); 11 | 12 | // draw rect 13 | noStroke(); 14 | fill(255, 200, 0, alpha); 15 | rect(width/2 - LENGTH/2, height/2 - LENGTH/2, LENGTH, LENGTH); 16 | 17 | if (alpha > 50) { 18 | alpha = alpha - 1; // decrease opacity 19 | } 20 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/2leftRight/leftRightOutput.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/conditionsPracticePackage/2leftRight/leftRightOutput.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/2leftRight/leftRightSolution/leftRightSolution.pde: -------------------------------------------------------------------------------- 1 | final int DIA = 50; 2 | final int LENGTH = 50; 3 | 4 | void setup() { 5 | size(500, 500); 6 | background(180); 7 | fill(0, 255, 255); 8 | 9 | // seperation line 10 | line(width/2, 0, width/2, height); 11 | } 12 | 13 | void draw() { 14 | } 15 | 16 | void mouseClicked() { 17 | if (mouseX < width/2) { // mouse position in left half 18 | ellipse(mouseX, mouseY, DIA, DIA); 19 | } else { // mouse position in right half 20 | rect(mouseX - LENGTH/2, mouseY - LENGTH/2, LENGTH, LENGTH); 21 | } 22 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/3circleShrinkGrow/circleShrinkGrowOutput.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/conditionsPracticePackage/3circleShrinkGrow/circleShrinkGrowOutput.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/3circleShrinkGrow/circleShrinkGrowSolution/circleShrinkGrowSolution.pde: -------------------------------------------------------------------------------- 1 | int dia = 40; 2 | boolean shrinking = false; 3 | 4 | int maxDia = 120; 5 | int minDia = 20; 6 | 7 | void setup() { 8 | size(200, 200); 9 | background(255); 10 | fill(0, 0, 255); 11 | } 12 | 13 | void draw() { 14 | background(255); 15 | 16 | // draw circle 17 | ellipse(width/2, height/2, dia, dia); 18 | 19 | if (shrinking) { 20 | dia = dia - 1; // increase circle diameter 21 | } else { 22 | dia = dia + 1; // decrease circle diameter 23 | } 24 | 25 | if (dia >= maxDia || dia <= minDia) { // if extreme has been reached 26 | shrinking = !shrinking; 27 | } 28 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/4increasingDiameter/increasingDiameterOutput.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/conditionsPracticePackage/4increasingDiameter/increasingDiameterOutput.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/4increasingDiameter/increasingDiameterSolution/increasingDiameterSolution.pde: -------------------------------------------------------------------------------- 1 | int dia = 40; 2 | int maxDia = 130; 3 | 4 | void setup() { 5 | size(600, 500); 6 | background(255); 7 | fill(0, 0, 255); 8 | } 9 | 10 | void draw() { 11 | } 12 | 13 | void mouseClicked() { 14 | ellipse(mouseX, mouseY, dia, dia); // draw circle 15 | dia += 20; // increase diameter 16 | 17 | if (dia > maxDia) { // if diameter exceeds the maximum 18 | dia = 40; 19 | } 20 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/5highlight/highlightOutput.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/conditionsPracticePackage/5highlight/highlightOutput.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/5highlight/highlightSolution/highlightSolution.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | size(600, 500); 3 | background(255); 4 | fill(0, 0, 255); 5 | } 6 | 7 | void draw() { 8 | background(255); 9 | 10 | // draw highlight 11 | noStroke(); 12 | fill(105,90,205); 13 | if (mouseX < width/4) { 14 | rect(0, 0, width/4, height); 15 | } else if (mouseX < width/2) { 16 | rect(width/4, 0, width/4, height); 17 | } else if (mouseX < (3*width)/4) { 18 | rect(width/2, 0, width/4, height); 19 | } else { 20 | rect((3*width)/4, 0, width/4, height); 21 | } 22 | 23 | // draw boarders 24 | strokeWeight(2); 25 | stroke(0); 26 | line (width/4, 0, width/4, height); 27 | line (width/2, 0, width/2, height); 28 | line((3*width)/4, 0, (3*width)/4, height); 29 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/6shapeChange/shapeChangeOutput.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/conditionsPracticePackage/6shapeChange/shapeChangeOutput.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/6shapeChange/shapeChangeSolution/shapeChangeSolution.pde: -------------------------------------------------------------------------------- 1 | final int SIZE = 20; 2 | int count = 0; 3 | 4 | void setup() { 5 | size(300, 400); 6 | background(255); 7 | } 8 | 9 | void draw() { 10 | } 11 | 12 | void mouseClicked() { 13 | if (count % 3 == 0) { 14 | fill(255, 0, 0); 15 | ellipse(mouseX, mouseY, SIZE, SIZE); 16 | } else if (count % 3 == 1) { 17 | fill(0, 255, 0); 18 | rect(mouseX - SIZE/2, mouseY - SIZE/2, SIZE, SIZE); 19 | } else { 20 | fill(0, 0, 255); 21 | triangle(mouseX, mouseY - 10, mouseX - 10, mouseY + 10, mouseX + 10, mouseY + 10); 22 | } 23 | 24 | count++; // increase count 25 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/7alongBorder/alongBorderOutput.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/conditionsPracticePackage/7alongBorder/alongBorderOutput.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/7alongBorder/alongBorderSolution/alongBorderSolution.pde: -------------------------------------------------------------------------------- 1 | int x = 0; 2 | int y = 0; 3 | final int LENGTH = 20; 4 | int direction = 1; // keeps track of what direction square is moving in 5 | 6 | void setup() { 7 | size(170, 200); 8 | background(255); 9 | fill(255, 0, 0); 10 | noStroke(); 11 | } 12 | 13 | void draw() { 14 | background(255); 15 | 16 | rect(x, y, LENGTH, LENGTH); // draw square 17 | 18 | // check for direction change 19 | if (direction == 1 && x >= width - LENGTH) { // if top-right corner reached 20 | direction = 2; 21 | } else if (direction == 2 && y >= height - LENGTH) { // if bottom-right corner reached 22 | direction = 3; 23 | } else if (direction == 3 && x <= 0) { // if botton-left corner reached 24 | direction = 4; 25 | } else if (direction == 4 && y <= 0) { // if top-left corner reached 26 | direction = 1; 27 | } 28 | 29 | // move square 30 | if (direction == 1) { 31 | x = x + 2; // move right 32 | } else if (direction == 2) { 33 | y = y + 2; // move down 34 | } else if (direction == 3) { 35 | x = x - 2; // move left 36 | } else { 37 | y = y - 2; // move up 38 | } 39 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/8changingBackground/changingBackgroundOutput.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/conditionsPracticePackage/8changingBackground/changingBackgroundOutput.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/8changingBackground/changingBackgroundSolution/changingBackgroundSolution.pde: -------------------------------------------------------------------------------- 1 | boolean fading = true; 2 | 3 | int r = 0, g = 0, b = 0; 4 | 5 | void setup() { 6 | size(400, 300); 7 | background(255); 8 | } 9 | 10 | void draw() { 11 | background(r, g, b); 12 | if (fading) { 13 | if (r < 255) { 14 | r++; 15 | } else { 16 | if (g < 255) { 17 | g++; 18 | } else { 19 | if (b < 255) { 20 | b++; 21 | } else { 22 | fading = false; 23 | } 24 | } 25 | } 26 | } else { 27 | if (b > 0) { 28 | b--; 29 | } else { 30 | if (g > 0) { 31 | g--; 32 | } else { 33 | if (r > 0) { 34 | r--; 35 | } else { 36 | fading = true; 37 | } 38 | } 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/9button/buttonOutput.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/conditionsPracticePackage/9button/buttonOutput.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/conditionsPracticePackage/9button/buttonSolution/buttonSolution.pde: -------------------------------------------------------------------------------- 1 | int DIA = 30; 2 | int buttonWidth = 60; 3 | int buttonHeight = 40; 4 | int offset = 10; 5 | 6 | boolean blue = true; 7 | 8 | void setup() { 9 | size(500, 500); 10 | background(255); 11 | fill(30, 145, 255); // set to blue 12 | } 13 | 14 | void draw() { 15 | rect(offset, offset, buttonWidth, buttonHeight); //draw button 16 | } 17 | 18 | void mouseClicked() { 19 | if (mouseX > offset && mouseX < offset + buttonWidth 20 | && mouseY > offset && mouseY < offset + buttonHeight) { // if button pressed 21 | blue = !blue; 22 | 23 | // change fill colour 24 | if (blue) { 25 | fill(30, 145, 255); 26 | } else { 27 | fill(255, 140, 0); 28 | } 29 | } else { 30 | ellipse(mouseX, mouseY, DIA, DIA); 31 | } 32 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/10drawBorders3Param/drawBorders3ParamOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/functionsPracticePackage/10drawBorders3Param/drawBorders3ParamOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/10drawBorders3Param/drawBorders3ParamSolution/drawBorders3ParamSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function drawBorders which takes 3 parameters 4 | (int margin, color c, int weight). the function shouldn't return 5 | anything, but draw a border on the screen when called. 6 | The border drawn should have margin pixels from all four sides of 7 | the screen and the border. The stroke colour of the border should 8 | be set to colour and and strokeWeight should be set to weight. 9 | */ 10 | void drawBorders(int margin, color c, int weight) { 11 | stroke(c); 12 | strokeWeight(weight); 13 | line(margin, margin, width-margin, margin); // top line 14 | line(margin, margin, margin, height-margin); // left line 15 | line(width-margin, margin, width-margin, height-margin); // right line 16 | line(margin, height-margin, width-margin, height-margin); // bottom line 17 | } 18 | 19 | void setup() { 20 | background(255); 21 | size(400, 300); 22 | 23 | /* 24 | TASK 2 25 | initialize a color variable c1 to #ED6729. 26 | call drawBorders with the parameters 15, c1 and 4. 27 | 28 | the output should match the picture in the question folder. 29 | */ 30 | color c1 = #ED6729; 31 | drawBorders(17, c1, 4); 32 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/10drawBorders3Param/drawBorders3ParamTemplate/drawBorders3ParamTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function drawBorders which takes 3 parameters 4 | (int margin, color c, int weight). the function shouldn't return 5 | anything, but draw a border on the screen when called. 6 | The border drawn should have margin pixels from all four sides of 7 | the screen and the border. The stroke colour of the border should 8 | be set to colour and and strokeWeight should be set to weight. 9 | */ 10 | 11 | void setup() { 12 | background(255); 13 | size(400, 300); 14 | 15 | /* 16 | TASK 2 17 | initialize a color variable c1 to #ED6729. 18 | call drawBorders with the parameters 15, c1 and 4. 19 | 20 | the output should match the picture in the question folder. 21 | */ 22 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/11drawBorders4Param/drawBorders4ParamOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/functionsPracticePackage/11drawBorders4Param/drawBorders4ParamOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/11drawBorders4Param/drawBorders4ParamSolution/drawBorders4ParamSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function drawBorders which takes 4 parameters 4 | (int marginWidth, int marginHeight, color c, int weight. the 5 | function shouldn't return anything, but draw a border on the 6 | screen when called. The border drawn should have marginWidth 7 | pixels between left and right sides of the screen and the 8 | border and marginHeight pixels between the top and bottom 9 | edges of the screen and the border. The stroke colour of the 10 | border should be set to colour and and strokeWeight should be 11 | set to weight. 12 | */ 13 | void drawBorders(int marginWidth, int marginHeight, int colour, int weight) { 14 | stroke(colour); 15 | strokeWeight(weight); 16 | line(marginWidth, marginHeight, width-marginWidth, marginHeight); // top line 17 | line(marginWidth, marginHeight, marginWidth, height-marginHeight); // left line 18 | line(width-marginWidth, marginHeight, width-marginWidth, height-marginHeight); // right line 19 | line(marginWidth, height-marginHeight, width-marginWidth, height-marginHeight); // bottom line 20 | } 21 | 22 | void setup() { 23 | background(255); 24 | size(400, 300); 25 | } 26 | 27 | void draw() { 28 | } 29 | 30 | void keyPressed() { 31 | /* 32 | TASK 2 33 | draw a border on the screen when the key is pressed using the drawBorders 34 | function. the border should be 8 pixels from the top and bottom of the screen, 35 | 17 pixels from the left and right side of the screen, pink in colour and 36 | have a stroke weight of 3. 37 | 38 | your output should match the picture in the question folder. 39 | */ 40 | drawBorders(17, 8, #F55EEB, 3); 41 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/11drawBorders4Param/drawBorders4ParamTemplate/drawBorders4ParamTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function drawBorders which takes 4 parameters 4 | (int marginWidth, int marginHeight, color c, int weight. the 5 | function shouldn't return anything, but draw a border on the 6 | screen when called. The border drawn should have marginWidth 7 | pixels between left and right sides of the screen and the 8 | border and marginHeight pixels between the top and bottom 9 | edges of the screen and the border. The stroke colour of the 10 | border should be set to colour and and strokeWeight should be 11 | set to weight. 12 | */ 13 | 14 | void setup() { 15 | background(255); 16 | size(400, 300); 17 | } 18 | 19 | void draw() { 20 | } 21 | 22 | void keyPressed() { 23 | /* 24 | TASK 2 25 | draw a border on the screen when the key is pressed using the drawBorders 26 | function. the border should be 8 pixels from the top and bottom of the screen, 27 | 17 pixels from the left and right side of the screen, pink in colour and 28 | have a stroke weight of 3. 29 | 30 | your output should match the picture in the question folder. 31 | */ 32 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/12countDigits/countDigitsSolution/countDigitsSolution.pde: -------------------------------------------------------------------------------- 1 | int countDigits(int a) { 2 | int count = 0; 3 | while (a > 0) { 4 | a /= 10; 5 | count++; 6 | } 7 | 8 | return count; 9 | } 10 | 11 | void setup() { 12 | size(300, 300); 13 | background(255); 14 | noStroke(); 15 | /* 16 | TASK 1 17 | call the function count digits to compute the amount of 18 | digits in d, and store the value returned in variable e. 19 | 20 | once completed, a circle will appear on the screen. 21 | */ 22 | int d = 1574067545; 23 | int e = countDigits(d); 24 | 25 | /* 26 | TASK 2 27 | call the function count digits to compute the amount of 28 | digits in e, and store the value returned in variable f. 29 | 30 | once completed, a square will appear on the screen. 31 | */ 32 | int f = countDigits(e); 33 | 34 | /* 35 | TASK 3 36 | call the function count digits to compute the amount of 37 | digits in f, and store the value returned in variable g. 38 | 39 | once completed, a triangle will appear on the screen. 40 | */ 41 | int g = countDigits(f); 42 | 43 | if (d == 1574067545 && e == 10) { 44 | fill(94, 143, 245); 45 | ellipse(80, 100, 50, 50); 46 | if (f == 2) { 47 | fill(245, 94, 94); 48 | rect(210, 40, 50, 50); 49 | if (g == 1) { 50 | fill(94, 245, 173); 51 | triangle(170, 180, 130, 230, 210, 230); 52 | } 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/12countDigits/countDigitsTemplate/countDigitsTemplate.pde: -------------------------------------------------------------------------------- 1 | int countDigits(int a) { 2 | int count = 0; 3 | while (a > 0) { 4 | a /= 10; 5 | count++; 6 | } 7 | 8 | return count; 9 | } 10 | 11 | void setup() { 12 | size(300, 300); 13 | background(255); 14 | noStroke(); 15 | /* 16 | TASK 1 17 | call the function count digits to compute the amount of 18 | digits in d, and store the value returned in variable e. 19 | 20 | once completed, a circle will appear on the screen. 21 | */ 22 | int d = 1574067545; 23 | int e = 0; 24 | 25 | /* 26 | TASK 2 27 | call the function count digits to compute the amount of 28 | digits in e, and store the value returned in variable f. 29 | 30 | once completed, a square will appear on the screen. 31 | */ 32 | int f = 0; 33 | 34 | /* 35 | TASK 3 36 | call the function count digits to compute the amount of 37 | digits in f, and store the value returned in variable g. 38 | 39 | once completed, a triangle will appear on the screen. 40 | */ 41 | int g = 0; 42 | 43 | 44 | if (d == 1574067545 && e == 10) { 45 | fill(94, 143, 245); 46 | ellipse(80, 100, 50, 50); 47 | if (f == 2) { 48 | fill(245, 94, 94); 49 | rect(210, 40, 50, 50); 50 | if (g == 1) { 51 | fill(94, 245, 173); 52 | triangle(170, 180, 130, 230, 210, 230); 53 | } 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/13sumDigits/sumDigitsSolution/sumDigitsSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function that when passed an integer, returns an the sum 4 | of all the digits in the integer. 5 | */ 6 | int sumDigits(int a) { 7 | int result = 0; 8 | while (a > 0) { 9 | int digit = a%10; // last digit 10 | result += digit; 11 | 12 | a /= 10; 13 | } 14 | 15 | return result; 16 | } 17 | 18 | void setup() { 19 | /* 20 | TASK 2 21 | using the sumDigits function, calculate the sum of the digits 22 | in the integer 97284962. store the result in a variable g. 23 | 24 | once completed, run the program and check the console to 25 | see if you are correct. 26 | */ 27 | int g = sumDigits(97284962); 28 | 29 | if (g == 47) { 30 | println("correct!"); 31 | } else { 32 | println("wrong"); 33 | } 34 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/13sumDigits/sumDigitsTemplate/sumDigitsTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function that when passed an integer, returns an the sum 4 | of all the digits in the integer. 5 | */ 6 | 7 | 8 | void setup() { 9 | /* 10 | TASK 2 11 | using the sumDigits function, calculate the sum of the digits 12 | in the integer 97284962. store the result in a variable g. 13 | 14 | once completed, run the program and check the console to 15 | see if you are correct. 16 | */ 17 | 18 | if (g == 47) { 19 | println("correct!"); 20 | } else { 21 | println("wrong"); 22 | } 23 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/14highestDigit/highestDigitSolution/highestDigitSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 3 | define a function that when passed an integer, returns the highest 4 | digit within that integer. 5 | you may use the higher function in this function. 6 | some parameter-return value mappings: 7 | 2 -> 2 8 | 34525 -> 5 9 | 152622 -> 6 10 | 90 -> 9 11 | 12 | once completed correctly, a yellow square will appear on the screen. 13 | */ 14 | int highestDigit(int a) { 15 | int highest = 0; 16 | while (a > 0) { 17 | int digit = a%10; 18 | if (digit > highest) { 19 | highest = digit; 20 | } 21 | 22 | a /= 10; 23 | } 24 | 25 | return highest; 26 | } 27 | 28 | /* using higher function 29 | int highestDigit(int a) { 30 | int highest = 0; 31 | while (a > 0) { 32 | int digit = a%10; 33 | highest = higher(highest, digit); 34 | } 35 | 36 | a /= 10; 37 | } 38 | 39 | return highest; 40 | } 41 | */ 42 | 43 | int higher(int a, int b) { 44 | if (a > b) { 45 | return a; 46 | } else { 47 | return b; 48 | } 49 | } 50 | 51 | void setup() { 52 | size(300, 300); 53 | background(255); 54 | 55 | boolean a = highestDigit(2) == 2; 56 | boolean b = highestDigit(0) == 0; 57 | boolean c = highestDigit(9) == 9; 58 | boolean d = highestDigit(34525) == 5; 59 | boolean e = highestDigit(152622) == 6; 60 | boolean f = highestDigit(980) == 9; 61 | boolean g = highestDigit(42580437) == 8; 62 | boolean h = highestDigit(1222) == 2; 63 | 64 | noStroke(); 65 | fill(255, 200, 0); 66 | rectMode(CENTER); 67 | if (a && b && c && d && e && f && g && h) { 68 | rect(width/2, height/2, 100, 100); 69 | } 70 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/14highestDigit/highestDigitTemplate/highestDigitTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 3 | define a function that when passed an integer, returns the highest 4 | digit within that integer. 5 | you may use the higher function in this function. 6 | some parameter-return value mappings: 7 | 2 -> 2 8 | 34525 -> 5 9 | 152622 -> 6 10 | 90 -> 9 11 | 12 | once completed, a yellow square will appear on the screen. 13 | */ 14 | 15 | int higher(int a, int b) { 16 | if (a > b) { 17 | return a; 18 | } else { 19 | return b; 20 | } 21 | } 22 | 23 | void setup() { 24 | size(300, 300); 25 | background(255); 26 | 27 | boolean a = highestDigit(2) == 2; 28 | boolean b = highestDigit(0) == 0; 29 | boolean c = highestDigit(9) == 9; 30 | boolean d = highestDigit(34525) == 5; 31 | boolean e = highestDigit(152622) == 6; 32 | boolean f = highestDigit(980) == 9; 33 | boolean g = highestDigit(42580437) == 8; 34 | boolean h = highestDigit(1222) == 2; 35 | 36 | noStroke(); 37 | fill(255, 200, 0); 38 | rectMode(CENTER); 39 | if (a && b && c && d && e && f && g && h) { 40 | rect(width/2, height/2, 100, 100); 41 | } 42 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/15lowestDigit/lowestDigitSolution/lowestDigitSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function that when passed a integer parameter, returns 4 | the lowest digit within that integer. 5 | */ 6 | int lowestDigit(int a) { 7 | int lowest = a%10; // last digit 8 | while (a > 0) { 9 | int digit = a%10; 10 | if (digit < lowest) { 11 | lowest = digit; 12 | } 13 | 14 | a /= 10; 15 | } 16 | 17 | return lowest; 18 | } 19 | 20 | void setup() { 21 | /* 22 | TASK 2 23 | initialize a variable c to 3046164. 24 | print the lowest digit of c using the lowestDigit function. 25 | 26 | once completed, '4' should be printed in the console. 27 | */ 28 | int c = 7964946; 29 | println(lowestDigit(c)); 30 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/15lowestDigit/lowestDigitTemplate/lowestDigitTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function that when passed a integer parameter, returns 4 | the lowest digit within that integer. 5 | */ 6 | 7 | 8 | void setup() { 9 | /* 10 | TASK 2 11 | initialize a variable c to 3046164. 12 | print the lowest digit of c using the lowestDigit function. 13 | 14 | once completed, '4' should be printed in the console. 15 | */ 16 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/16getDigit/getDigitSolution/getDigitSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function getDigit that when passed two 4 | integers (num and index), returns the digit which is at 5 | index position from the right of the integer num. 6 | 7 | assume that the index passed is within range. 8 | 9 | some parameter-return value mappings: 10 | 20934, 0 -> 4 11 | 20934, 3 -> 0 12 | 9, 0 -> 9 13 | 3451, 2 -> 4 14 | 3451, 3 -> 3 15 | */ 16 | 17 | int getDigit(int num, int index) { 18 | for (int i = 0; i < index; i++) { 19 | num /= 10; 20 | } 21 | 22 | return num%10; 23 | } 24 | 25 | void setup() { 26 | size(300, 300); 27 | background(255); 28 | noStroke(); 29 | 30 | /* 31 | TASK 2 32 | declare two variables d and e and initialize them to 33 | 84 and 0 respectively. 34 | call the function getDigit to compute the digit at index e 35 | of the integer d and store the value returned in variable f 36 | 37 | once completed, the top half of the screen will be light 38 | blue 39 | */ 40 | int d = 84; 41 | int e = 0; 42 | int f = getDigit(d, e); 43 | 44 | /* 45 | TASK 3 46 | store the 5th digit of the integer 2746023 in a variable g 47 | using the function getDigit. 48 | 49 | once completed, the bottom half of the screen will be 50 | dark blue 51 | */ 52 | int g = getDigit(2746023, 5); 53 | 54 | if(d == 84 && e == 0 && f == 4) { 55 | fill(161, 238, 245); 56 | rect(0, 0, width, height/2); 57 | } 58 | 59 | if(g == 7) { 60 | fill(34, 70, 240); 61 | rect(0, height/2, width, height/2); 62 | } 63 | 64 | 65 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/16getDigit/getDigitTemplate/getDigitTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function getDigit that when passed two 4 | integers (num and index), returns the digit which is at 5 | index position from the right of the integer num. 6 | 7 | assume that the index passed is within range. 8 | 9 | some parameter-return value mappings: 10 | 20934, 0 -> 4 11 | 20934, 3 -> 0 12 | 9, 0 -> 9 13 | 3451, 2 -> 4 14 | 3451, 3 -> 3 15 | */ 16 | 17 | void setup() { 18 | size(300, 300); 19 | background(255); 20 | noStroke(); 21 | 22 | /* 23 | TASK 2 24 | declare two variables d and e and initialize them to 25 | 84 and 0 respectively. 26 | call the function getDigit to compute the digit at index e 27 | of the integer d and store the value returned in variable f 28 | 29 | once completed, the top half of the screen will be light 30 | blue 31 | */ 32 | 33 | /* 34 | TASK 3 35 | store the 5th digit of the integer 2746023 in a variable g 36 | using the function getDigit. 37 | 38 | once completed, the bottom half of the screen will be 39 | dark blue 40 | */ 41 | 42 | 43 | if(d == 84 && e == 0 && f == 4) { 44 | fill(161, 238, 245); 45 | rect(0, 0, width, height/2); 46 | } 47 | if(g == 7) { 48 | fill(34, 70, 240); 49 | rect(0, height/2, width, height/2); 50 | } 51 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/17drawStickFigure/drawStickFigureSolution/drawStickFigureSolution.pde: -------------------------------------------------------------------------------- 1 | int x1 = 0; 2 | int x2, y2 = -10000; 3 | 4 | // draw a stick figure at (x, y) and use scale to 5 | // determine its size 6 | void drawStickFigure(int scale, float x, float y) { 7 | strokeWeight(scale/50); 8 | if (scale/50 < 1) { 9 | strokeWeight(1); 10 | } 11 | ellipse(x, y-(scale/3.0), (scale/3.0), (scale/3.0)); // head 12 | line(x, y-(scale/3.0 - (scale/3.0)/2), x, y+(scale/3.5)); // body 13 | line(x - scale/5.0, y, x + scale/5.0, y); // arms 14 | line(x, y + (scale/3.5), x - scale/5.0, y + scale/1.8); //left leg 15 | line(x, y + (scale/3.5), x + scale/5.0, y + scale/1.8); //right leg 16 | } 17 | 18 | void setup() { 19 | size(500, 500); 20 | background(200, 235, 225); 21 | } 22 | 23 | void draw() { 24 | } 25 | 26 | void mouseClicked() { 27 | /* 28 | TASK 1 29 | call the function drawStickFigure to draw a stick figure on the screen 30 | at the mouse position and at scale mouseY/2 whenever the mouse is clicked. 31 | */ 32 | drawStickFigure(mouseY/2, mouseX, mouseY); 33 | } 34 | 35 | void keyPressed() { 36 | /* 37 | TASK 2 38 | call the function drawStickFigure to draw a stick figure at a random 39 | position on the screen at a random scale between 30 and 200 (inclusive) 40 | whenever the key is pressed. 41 | */ 42 | drawStickFigure((int)random(30, 201), random(0, width), random(0, height)); 43 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/17drawStickFigure/drawStickFigureTemplate/drawStickFigureTemplate.pde: -------------------------------------------------------------------------------- 1 | int x1 = 0; 2 | int x2, y2 = -10000; 3 | 4 | // draw a stick figure at (x, y) and use scale to 5 | // determine its size 6 | void drawStickFigure(int scale, float x, float y) { 7 | strokeWeight(scale/50); 8 | if (scale/50 < 1) { 9 | strokeWeight(1); 10 | } 11 | ellipse(x, y-(scale/3.0), (scale/3.0), (scale/3.0)); // head 12 | line(x, y-(scale/3.0 - (scale/3.0)/2), x, y+(scale/3.5)); // body 13 | line(x - scale/5.0, y, x + scale/5.0, y); // arms 14 | line(x, y + (scale/3.5), x - scale/5.0, y + scale/1.8); //left leg 15 | line(x, y + (scale/3.5), x + scale/5.0, y + scale/1.8); //right leg 16 | } 17 | 18 | void setup() { 19 | size(500, 500); 20 | background(200, 235, 225); 21 | } 22 | 23 | void draw() { 24 | } 25 | 26 | void mouseClicked() { 27 | /* 28 | TASK 1 29 | call the function drawStickFigure to draw a stick figure on the screen 30 | at the mouse position and at scale mouseY/2 whenever the mouse is clicked. 31 | */ 32 | } 33 | 34 | void keyPressed() { 35 | /* 36 | TASK 2 37 | call the function drawStickFigure to draw a stick figure at a random 38 | position on the screen at a random scale between 30 and 200 (inclusive) 39 | whenever the key is pressed. 40 | */ 41 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/18power/powerSolution/powerSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function power that when passed a float base and an 4 | int exp, returns base to the power of exp. 5 | 6 | some parameter-return value mappings: 7 | 2.0, 2 -> 4.0 8 | 5.5, 6 -> 27680.64 9 | */ 10 | float power(float base, int exp) { 11 | float result = 1; 12 | 13 | for (int i = 0; i < exp; i++) { 14 | result *= base; 15 | } 16 | 17 | return result; 18 | } 19 | 20 | void setup() { 21 | /* 22 | TASK 2 23 | a) compute the 2 to the power of 2 and store it in a vairable a. 24 | b) compute the 2 to the power of 7 and store it in a vairable b. 25 | c) compute the 5.5 to the power of 2 and store it in a vairable c. 26 | d) compute the 5.5 to the power of 6 and store it in a vairable d. 27 | e) compute the 8.3 to the power of 4 and store it in a vairable e. 28 | 29 | once completed, run the program and check the console to see if you 30 | are correct. 31 | */ 32 | float a = power(2, 2); 33 | float b = power(2, 7); 34 | float c = power(5.5, 2); 35 | float d = power(5.5, 6); 36 | float e = power(8.3, 4); 37 | 38 | if (a == 4.0) { 39 | println("a is correct"); 40 | } else { 41 | println("a is incorrect. a should equal 4.0, but instead is " + a); 42 | } 43 | 44 | if (b == 128.0) { 45 | println("b is correct"); 46 | } else { 47 | println("b is incorrect. b should equal 128.0, but instead is " + b); 48 | } 49 | 50 | if (c == 30.25) { 51 | println("c is correct"); 52 | } else { 53 | println("c is incorrect. c should equal 30.25, but instead is " + c); 54 | } 55 | 56 | if (d == 27680.64) { 57 | println("d is correct"); 58 | } else { 59 | println("d is incorrect. d should equal 27680.64, but instead is " + d); 60 | } 61 | 62 | if (e == 4745.832) { 63 | println("e is correct"); 64 | } else { 65 | println("e is incorrect. e should equal 4745.832, but instead is " + e); 66 | } 67 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/18power/powerTemplate/powerTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function power that when passed a float base and an 4 | int exp, returns base to the power of exp. 5 | 6 | some parameter-return value mappings: 7 | 2.0, 2 -> 4.0 8 | 5.5, 6 -> 27680.64 9 | */ 10 | 11 | void setup() { 12 | /* 13 | TASK 2 14 | a) compute the 2 to the power of 2 and store it in a vairable a. 15 | b) compute the 2 to the power of 7 and store it in a vairable b. 16 | c) compute the 5.5 to the power of 2 and store it in a vairable c. 17 | d) compute the 5.5 to the power of 6 and store it in a vairable d. 18 | e) compute the 8.3 to the power of 4 and store it in a vairable e. 19 | 20 | once completed, run the program and check the console to see if you 21 | are correct. 22 | */ 23 | 24 | if (a == 4.0) { 25 | println("a is correct"); 26 | } else { 27 | println("a is incorrect. a should equal 4.0, but instead is " + a); 28 | } 29 | 30 | if (b == 128.0) { 31 | println("b is correct"); 32 | } else { 33 | println("b is incorrect. b should equal 128.0, but instead is " + b); 34 | } 35 | 36 | if (c == 30.25) { 37 | println("c is correct"); 38 | } else { 39 | println("c is incorrect. c should equal 30.25, but instead is " + c); 40 | } 41 | 42 | if (d == 27680.64) { 43 | println("d is correct"); 44 | } else { 45 | println("d is incorrect. d should equal 27680.64, but instead is " + d); 46 | } 47 | 48 | if (e == 4745.832) { 49 | println("e is correct"); 50 | } else { 51 | println("e is incorrect. e should equal 4745.832, but instead is " + e); 52 | } 53 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/19factorial/factorialSolution/factorialSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 3 | define a function facotrial that when passed an integer a, 4 | returns value of a factorial. 5 | 6 | some parameter-return value mappings: 7 | 0 -> 1 8 | 1 -> 1 9 | 3 -> 6 10 | 12 -> 479001600 11 | 12 | once completed, the screen should have a green background if 13 | correct and a red background if incorrect. 14 | */ 15 | int factorial(int a) { 16 | int result = 1; 17 | 18 | for (int i = a; i > 1; i--) { 19 | result *= i; 20 | } 21 | 22 | return result; 23 | } 24 | 25 | void setup() { 26 | size(200, 200); 27 | boolean a = factorial(0) == 1; 28 | boolean b = factorial(1) == 1; 29 | boolean c = factorial(2) == 2; 30 | boolean d = factorial(3) == 6; 31 | boolean e = factorial(8) == 40320; 32 | boolean f = factorial(12) == 479001600; 33 | 34 | if (a && b && c && d && e && f) { 35 | background(0, 255, 0); 36 | } else { 37 | background(255, 0, 0); 38 | } 39 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/19factorial/factorialTemplate/factorialTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 3 | define a function facotrial that when passed an integer a, 4 | returns value of a factorial. 5 | 6 | some parameter-return value mappings: 7 | 0 -> 1 8 | 1 -> 1 9 | 3 -> 6 10 | 12 -> 479001600 11 | 12 | once completed, the screen should have a green background if 13 | correct and a red background if incorrect. 14 | */ 15 | 16 | 17 | void setup() { 18 | size(200, 200); 19 | boolean a = factorial(0) == 1; 20 | boolean b = factorial(1) == 1; 21 | boolean c = factorial(2) == 2; 22 | boolean d = factorial(3) == 6; 23 | boolean e = factorial(8) == 40320; 24 | boolean f = factorial(12) == 479001600; 25 | 26 | if (a && b && c && d && e && f) { 27 | background(0, 255, 0); 28 | } else { 29 | background(255, 0, 0); 30 | } 31 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/1square/squareSolution/squareSolution.pde: -------------------------------------------------------------------------------- 1 | float square(float a) { 2 | return a*a; 3 | } 4 | 5 | void draw() { 6 | } 7 | 8 | void setup() { 9 | size(300, 150); 10 | background(255); 11 | line(width/2, 0, width/2, height); 12 | strokeWeight(3); 13 | 14 | /* 15 | TASK 1 16 | compute the square of 5 using the 'square' function 17 | and store it in a variable 'z'. 18 | 19 | once completed, a green tick will appear on the left side 20 | of the screen if correct. If not, a red cross will appear 21 | on the left side of the screen. 22 | */ 23 | float z = square(5.5); 24 | 25 | /* 26 | TASK 2 27 | declare a floating point variable 'y' and initialize it 28 | to 9. 29 | compute the square of 'y' using the 'square' function 30 | and store it in a variable 'x'. 31 | 32 | once completed, a green tick will appear on the right side 33 | of the screen if correct. If not, a red cross will appear 34 | on the right side of the screen. 35 | */ 36 | float y = 9; 37 | float x = square(y); 38 | 39 | 40 | if (z == 30.25) { 41 | stroke(0, 255, 0); 42 | line(width/4, height/2 + 10, width/4 - 8, height/2 + 2); 43 | line(width/4, height/2 + 10, width/4 + 12, height/2 - 15); 44 | } else { 45 | stroke(255, 0, 0); 46 | line(width/4 - 10, height/2 -10, width/4 + 10, height/2 + 10); 47 | line(width/4 - 10, height/2 +10, width/4 + 10, height/2 - 10); 48 | } 49 | 50 | if (x == 81) { 51 | stroke(0, 255, 0); 52 | line(3*width/4, height/2 + 10, 3*width/4 - 8, height/2 + 2); 53 | line(3*width/4, height/2 + 10, 3*width/4 + 12, height/2 - 15); 54 | } else { 55 | stroke(255, 0, 0); 56 | line(3*width/4 - 10, height/2 -10, 3*width/4 + 10, height/2 + 10); 57 | line(3*width/4 - 10, height/2 +10, 3*width/4 + 10, height/2 - 10); 58 | } 59 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/1square/squareTemplate/squareTemplate.pde: -------------------------------------------------------------------------------- 1 | float square(float a) { 2 | return a*a; 3 | } 4 | 5 | void draw() { 6 | } 7 | 8 | void setup() { 9 | size(300, 150); 10 | background(255); 11 | line(width/2, 0, width/2, height); 12 | strokeWeight(3); 13 | 14 | /* 15 | TASK 1 16 | compute the square of 5 using the 'square' function 17 | and store it in a variable 'z'. 18 | 19 | once completed, a green tick will appear on the left side 20 | of the screen if correct. If not, a red cross will appear 21 | on the left side of the screen. 22 | */ 23 | 24 | /* 25 | TASK 2 26 | declare a floating point variable 'y' and initialize it 27 | to 9. 28 | compute the square of 'y' using the 'square' function 29 | and store it in a variable 'x'. 30 | 31 | once completed, a green tick will appear on the right side 32 | of the screen if correct. If not, a red cross will appear 33 | on the right side of the screen. 34 | */ 35 | 36 | 37 | if (z == 30.25) { 38 | stroke(0, 255, 0); 39 | line(width/4, height/2 + 10, width/4 - 8, height/2 + 2); 40 | line(width/4, height/2 + 10, width/4 + 12, height/2 - 15); 41 | } else { 42 | stroke(255, 0, 0); 43 | line(width/4 - 10, height/2 -10, width/4 + 10, height/2 + 10); 44 | line(width/4 - 10, height/2 +10, width/4 + 10, height/2 - 10); 45 | } 46 | 47 | if (x == 81) { 48 | stroke(0, 255, 0); 49 | line(3*width/4, height/2 + 10, 3*width/4 - 8, height/2 + 2); 50 | line(3*width/4, height/2 + 10, 3*width/4 + 12, height/2 - 15); 51 | } else { 52 | stroke(255, 0, 0); 53 | line(3*width/4 - 10, height/2 -10, 3*width/4 + 10, height/2 + 10); 54 | line(3*width/4 - 10, height/2 +10, 3*width/4 + 10, height/2 - 10); 55 | } 56 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/2isEven/isEvenSolution/isEvenSolution.pde: -------------------------------------------------------------------------------- 1 | boolean isEven(int a) { 2 | /* 3 | TASK 4 | given the function header for the function 'isEven', 5 | write the body of the fucntion such that the function 6 | will return true if 'a' is an even integer and 'false' 7 | otherwise. 8 | 9 | the program will output a smiley face if done correctly, 10 | and a sad face if not. 11 | */ 12 | return a%2 == 0; 13 | 14 | /* 15 | also correct: 16 | if (a%2 == 0) { 17 | return true; 18 | } else { 19 | return false; 20 | } 21 | */ 22 | } 23 | 24 | void setup() { 25 | size(250, 250); 26 | background(255); 27 | boolean a = isEven(0); 28 | boolean b = isEven(1934); 29 | boolean c = isEven(8); 30 | boolean z = isEven(1); 31 | boolean y = isEven(8427); 32 | boolean x = isEven(9); 33 | 34 | fill(0); 35 | ellipse(width/4 + 20, height/4 + 20, 20, 20); 36 | ellipse(3*width/4 - 20, height/4 + 20, 20, 20); 37 | noFill(); 38 | strokeWeight(5); 39 | if (a && b && c && !z && !y && !x) { 40 | arc(width/2, height/2, 100, 100, 0, PI); 41 | } else { 42 | arc(width/2, height/2 + 50, 100, 100, PI, TWO_PI); 43 | } 44 | } 45 | 46 | void draw() { 47 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/2isEven/isEvenTemplate/isEvenTemplate.pde: -------------------------------------------------------------------------------- 1 | boolean isEven(int a) { 2 | /* 3 | TASK 4 | given the function header for the function 'isEven', 5 | write the body of the fucntion such that the function 6 | will return true if 'a' is an even integer and 'false' 7 | otherwise. 8 | 9 | the program will output a smiley face if done correctly, 10 | and a sad face if not. 11 | */ 12 | 13 | } 14 | 15 | void setup() { 16 | size(250, 250); 17 | background(255); 18 | boolean a = isEven(0); 19 | boolean b = isEven(1934); 20 | boolean c = isEven(8); 21 | boolean z = isEven(1); 22 | boolean y = isEven(8427); 23 | boolean x = isEven(9); 24 | 25 | fill(0); 26 | ellipse(width/4 + 20, height/4 + 20, 20, 20); 27 | ellipse(3*width/4 - 20, height/4 + 20, 20, 20); 28 | noFill(); 29 | strokeWeight(5); 30 | if (a && b && c && !z && !y && !x) { 31 | arc(width/2, height/2, 100, 100, 0, PI); 32 | } else { 33 | arc(width/2, height/2 + 50, 100, 100, PI, TWO_PI); 34 | } 35 | } 36 | 37 | void draw() { 38 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/3isPositive/isPositiveSolution/isPositiveSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function 'isPositive' that when passed one integer 4 | (call the parameter a), returns the boolean value true if 5 | the int is positive (or 0) and the boolean value false if 6 | the int is negative. 7 | 8 | if the function is implemented correcty, the screen will 9 | be blue, if not the screen will be orange. 10 | */ 11 | 12 | boolean isPositive(int a) { 13 | return a >= 0; 14 | 15 | /* 16 | also correct: 17 | if (a >= 0) { 18 | return true; 19 | } else { 20 | return false; 21 | } 22 | */ 23 | } 24 | 25 | void setup() { 26 | size(200, 200); 27 | if (isPositive(0) && isPositive(213) 28 | && !isPositive(-1) && !isPositive(-1213)) { 29 | background(#86C7FF); 30 | } else { 31 | background(#FFAB0D); 32 | } 33 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/3isPositive/isPositiveTemplate/isPositiveTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function 'isPositive' that when passed one integer 4 | (call the parameter a), returns the boolean value true if 5 | the int is positive (or 0) and the boolean value false if 6 | the int is negative. 7 | 8 | if the function is implemented correcty, the screen will 9 | be blue, if not the screen will be orange. 10 | */ 11 | 12 | void setup() { 13 | size(200, 200); 14 | if (isPositive(0) && isPositive(213) 15 | && !isPositive(-1) && !isPositive(-1213)) { 16 | background(#86C7FF); 17 | } else { 18 | background(#FFAB0D); 19 | } 20 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/4isDigit/isDigitSolution/isDigitSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function isDigit that when passed a char, returns true 4 | if the character is a digit and false otherwise. 5 | some parameter-return value mappings: 6 | 'a' -> false 7 | '0' -> true 8 | '7' -> true 9 | ';' -> false 10 | */ 11 | 12 | boolean isDigit(char a) { 13 | return a >= '0' && a <= '9'; 14 | 15 | /* 16 | also correct: 17 | return a >= 48 && a <= 57 18 | */ 19 | 20 | /* 21 | also correct: 22 | if (a >= '0' && a <= '9') { 23 | return true; 24 | } else { 25 | return false; 26 | } 27 | */ 28 | } 29 | 30 | void setup() { 31 | /* 32 | TASK 2 33 | compute whether the character '8' is a digit and store it 34 | in a boolean variable j. 35 | 36 | compute whether the character '9' is a digit and store it 37 | in a boolean variable k. 38 | 39 | compute whether the character '!' is a digit and store it 40 | in a boolean variable l. 41 | 42 | compute whether the character 'w' is a digit and store it 43 | in a boolean variable m. 44 | 45 | compute whether the character '0' is a digit and store it 46 | in a boolean variable n. 47 | 48 | once completed, run your program and check the console 49 | to see whether you have successfully completed both tasks. 50 | */ 51 | 52 | boolean j = isDigit('8'); 53 | boolean k = isDigit('9'); 54 | boolean l = isDigit('!'); 55 | boolean m = isDigit('w'); 56 | boolean n = isDigit('0'); 57 | 58 | if (j && k && !l && !m && n) { 59 | println("Congratulations! You have completed the tasks correctly."); 60 | } else { 61 | println("Something is wrong, try again."); 62 | } 63 | 64 | 65 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/4isDigit/isDigitTemplate/isDigitTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | fill in the body to the function isDigit such that when passed 4 | a char, the function returns true if the character is a 5 | digit and false otherwise. 6 | 7 | some parameter-return value mappings: 8 | 'a' -> false 9 | '0' -> true 10 | '7' -> true 11 | ';' -> false 12 | */ 13 | 14 | boolean isDigit(char a) { 15 | } 16 | 17 | void setup() { 18 | /* 19 | TASK 2 20 | compute whether the character '8' is a digit and store it 21 | in a boolean variable j. 22 | 23 | compute whether the character '9' is a digit and store it 24 | in a boolean variable k. 25 | 26 | compute whether the character '!' is a digit and store it 27 | in a boolean variable l. 28 | 29 | compute whether the character 'w' is a digit and store it 30 | in a boolean variable m. 31 | 32 | compute whether the character '0' is a digit and store it 33 | in a boolean variable n. 34 | 35 | once completed, run your program and check the console 36 | to see whether you have successfully completed both tasks. 37 | */ 38 | 39 | if (j && k && !l && !m && n) { 40 | println("Congratulations! You have completed the tasks correctly."); 41 | } else { 42 | println("Something is wrong, try again."); 43 | } 44 | 45 | 46 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/5higher/higherSolution/higherSolution.pde: -------------------------------------------------------------------------------- 1 | int higher(int a, int b) { 2 | if(a > b) { 3 | return a; 4 | } 5 | else { 6 | return b; 7 | } 8 | 9 | /* 10 | also good: 11 | if(a > b) { 12 | return a; 13 | } 14 | return b; 15 | */ 16 | 17 | /* 18 | also good: 19 | 20 | return a > b ? a : b; 21 | */ 22 | } 23 | 24 | void setup() { 25 | /* 26 | declare two variables x and y and initialize them to 27 | 8 and 5 respectively. 28 | call the function higher to compute the higher of x and y, 29 | and store the value returned in variable c. 30 | */ 31 | 32 | int x = 8; 33 | int y = 5; 34 | int c = higher(x, y); 35 | 36 | if (x == 8 && y == 5 && c == 8) { 37 | println("correct"); 38 | } else { 39 | println("incorrect"); 40 | } 41 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/5higher/higherTemplate/higherTemplate.pde: -------------------------------------------------------------------------------- 1 | int higher(int a, int b) { 2 | if(a > b) { 3 | return a; 4 | } 5 | else { 6 | return b; 7 | } 8 | 9 | /* 10 | also good: 11 | if(a > b) { 12 | return a; 13 | } 14 | return b; 15 | */ 16 | 17 | /* 18 | also good: 19 | 20 | return a > b ? a : b; 21 | */ 22 | } 23 | 24 | void setup() { 25 | /* 26 | declare two variables x and y and initialize them to 27 | 8 and 5 respectively. 28 | call the function higher to compute the higher of x and y, 29 | and store the value returned in variable c. 30 | */ 31 | 32 | if (x == 8 && y == 5 && c == 8) { 33 | println("correct"); 34 | } else { 35 | println("incorrect"); 36 | } 37 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/6highest/highestSolutoin/highestSolutoin.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function highest that returns the highest integer out 4 | of three integer parameters (a, b and c). note: the higher 5 | function should be called within this function. 6 | */ 7 | int highest(int a, int b, int c) { 8 | int currentHighest = higher(a, b); 9 | return higher(currentHighest, c); 10 | 11 | /* 12 | also correct: 13 | b = higher(a, b); 14 | return highest(b, c); 15 | */ 16 | } 17 | 18 | void setup() { 19 | /* 20 | TASK 2 21 | declare two variables f and g and initialize them to 23 and 20 22 | respectively. 23 | call the function with the f, g and 50 as the parameters and store 24 | the value returned in variable h. 25 | */ 26 | 27 | int f = 23; 28 | int g = 20; 29 | 30 | int h = highest(f, g, 50); 31 | 32 | if (h == 50) { 33 | println("correct!"); 34 | } else { 35 | println("incorrect"); 36 | } 37 | 38 | } 39 | 40 | int higher(int a, int b) { 41 | if(a > b) { 42 | return a; 43 | } 44 | else { 45 | return b; 46 | } 47 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/6highest/highestTemplate/highestTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function highest that returns the highest integer out 4 | of three integer parameters (a, b and c). note: the higher 5 | function should be called within this function. 6 | */ 7 | 8 | void setup() { 9 | /* 10 | TASK 2 11 | declare two variables f and g and initialize them to 23 and 20 12 | respectively. 13 | call the function with the f, g and 50 as the parameters and store 14 | the value returned in variable h. 15 | */ 16 | 17 | if (h == 50) { 18 | println("correct!"); 19 | } else { 20 | println("incorrect"); 21 | } 22 | 23 | } 24 | 25 | int higher(int a, int b) { 26 | if(a > b) { 27 | return a; 28 | } 29 | else { 30 | return b; 31 | } 32 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/7average/averageSolution/averageSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function average that when passed two integers 4 | (call the formal parameters a and b), returns their average. 5 | some parameter-return value mappings: 6 | 5, 9 -> 7 7 | 6, 11 -> 8.5 8 | -3, 6 -> 1.5 9 | -4, 4 -> 0 10 | */ 11 | 12 | float average(int a, int b) { 13 | return (a+b)/2.0; 14 | 15 | /* 16 | also correct: 17 | float sum = a + b; 18 | return sum/2; 19 | */ 20 | } 21 | 22 | void setup() { 23 | size(300, 300); 24 | background(255); 25 | 26 | /* 27 | TASK 2 28 | declare two variables x and y and initialize them to 29 | 8 and 5 respectively. 30 | call the function average to compute the average of x and y, 31 | and store the value returned in variable c. 32 | 33 | once you complete this code, you'll get a green circle at 34 | the centre of the screen if your solution is correct 35 | */ 36 | 37 | int x = 8; 38 | int y = 5; 39 | float c = average(x, y); 40 | 41 | 42 | if (c > 6) { 43 | fill(0, 150, 0); 44 | } else { 45 | fill(255, 0, 0); 46 | } 47 | ellipse(width/2, height/2, 50, 50); 48 | } 49 | 50 | void draw() { 51 | } 52 | 53 | void mousePressed() { 54 | /* 55 | TASK 3 56 | declare two variables p and q and initialize each of 57 | them to a random integer between 1 and 10 (inclusive on both sides) 58 | call the function average to compute the average of p and q 59 | and store the value returned in variable r. 60 | 61 | once you complete this code, you'll get a green circle 62 | at the location of the mouse if your solution is correct 63 | */ 64 | 65 | int p = (int)random(1, 11); 66 | int q = (int)random(1, 11); 67 | float r = average(p, q); 68 | 69 | if (r == (p+q)/2.0) { 70 | fill(0, 150, 0); 71 | } else { 72 | fill(255, 0, 0); 73 | } 74 | ellipse(mouseX, mouseY, 50, 50); 75 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/7average/averageTemplate/averageTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 1 3 | define a function average that when passed two integers 4 | (call the formal parameters a and b), returns their average. 5 | some parameter-return value mappings: 6 | 5, 9 -> 7 7 | 6, 11 -> 8.5 8 | -3, 6 -> 1.5 9 | -4, 4 -> 0 10 | */ 11 | 12 | void setup() { 13 | size(300, 300); 14 | background(255); 15 | 16 | /* 17 | TASK 2 18 | declare two variables x and y and initialize them to 19 | 8 and 5 respectively. 20 | call the function average to compute the average of x and y, 21 | and store the value returned in variable c. 22 | 23 | once you complete this code, you'll get a green circle at 24 | the centre of the screen if your solution is correct 25 | */ 26 | if (c > 6) { 27 | fill(0, 150, 0); 28 | } else { 29 | fill(255, 0, 0); 30 | } 31 | ellipse(width/2, height/2, 50, 50); 32 | } 33 | 34 | void draw() { 35 | } 36 | 37 | void mousePressed() { 38 | /* 39 | TASK 3 40 | declare two variables p and q and initialize each of 41 | them to a random integer between 1 and 10 (inclusive on both sides) 42 | call the function average to compute the average of p and q 43 | and store the value returned in variable r. 44 | 45 | once you complete this code, you'll get a green circle 46 | at the location of the mouse if your solution is correct 47 | */ 48 | if (r == (p+q)/2.0) { 49 | fill(0, 150, 0); 50 | } else { 51 | fill(255, 0, 0); 52 | } 53 | ellipse(mouseX, mouseY, 50, 50); 54 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/8drawBorders1Param/drawBorders1ParamSolution/drawBorders1ParamSolution.pde: -------------------------------------------------------------------------------- 1 | void drawBorders(int margin) { 2 | line(margin, margin, width-margin, margin); // top line 3 | line(margin, margin, margin, height-margin); // left line 4 | line(width-margin, margin, width-margin, height-margin); // right line 5 | line(margin, height-margin, width-margin, height-margin); // bottom line 6 | } 7 | 8 | void setup() { 9 | background(255); 10 | size(400, 300); 11 | } 12 | 13 | void draw() { 14 | } 15 | 16 | void mouseClicked() { 17 | /* 18 | TASK 19 | call the drawBorders function such that it draws a border with 20 | margin at mouseY when mouseY is less than height/2 and margin at 21 | height-mouseY when mouseY is greater than or equal to height/2. 22 | */ 23 | if (mouseY < height/2) { 24 | drawBorders(mouseY); 25 | } else { 26 | drawBorders(height-mouseY); 27 | } 28 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/8drawBorders1Param/drawBorders1ParamTemplate/drawBorders1ParamTemplate.pde: -------------------------------------------------------------------------------- 1 | void drawBorders(int margin) { 2 | line(margin, margin, width-margin, margin); // top line 3 | line(margin, margin, margin, height-margin); // left line 4 | line(width-margin, margin, width-margin, height-margin); // right line 5 | line(margin, height-margin, width-margin, height-margin); // bottom line 6 | } 7 | 8 | void setup() { 9 | background(255); 10 | size(400, 300); 11 | } 12 | 13 | void draw() { 14 | } 15 | 16 | void mouseClicked() { 17 | /* 18 | TASK 19 | call the drawBorders function such that it draws a border with 20 | margin at mouseY when mouseY is less than height/2 and margin at 21 | height-mouseY when mouseY is greater than or equal to height/2. 22 | */ 23 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/9drawBorders2Param/drawBorders2ParamOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/functionsPracticePackage/9drawBorders2Param/drawBorders2ParamOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/9drawBorders2Param/drawBorders2ParamSolution/drawBorders2ParamSolution.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 3 | define a function drawBorders that takes 2 integer parameters marginWidth 4 | and marginHeight. The function should not return anything, but draw a 5 | border on the screen when called. The border drawn should have 6 | marginWidth pixels between left and right sides of the screen and the 7 | border and marginHeight pixels between the top and bottom edges of 8 | the screen and the border. 9 | 10 | once completed, your output should match the picture provided in the 11 | question folder. 12 | */ 13 | void drawBorders(int marginWidth, int marginHeight) { 14 | line(marginWidth, marginHeight, width-marginWidth, marginHeight); // top line 15 | line(marginWidth, marginHeight, marginWidth, height-marginHeight); // left line 16 | line(width-marginWidth, marginHeight, width-marginWidth, height-marginHeight); // right line 17 | line(marginWidth, height-marginHeight, width-marginWidth, height-marginHeight); // bottom line 18 | } 19 | 20 | void setup() { 21 | background(255); 22 | size(400, 300); 23 | drawBorders(5, 15); 24 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/9drawBorders2Param/drawBorders2ParamTemplate/drawBorders2ParamTemplate.pde: -------------------------------------------------------------------------------- 1 | /* 2 | TASK 3 | define a function drawBorders that takes 2 integer parameters marginWidth 4 | and marginHeight. The function should not return anything, but draw a 5 | border on the screen when called. The border drawn should have 6 | marginWidth pixels between both sides of the screen and the border 7 | and marginHeight pixels between the top of the screen and border as well 8 | as the bottom of the screen and the border. 9 | 10 | once completed, your output should match the picture provided in the 11 | question folder. 12 | */ 13 | 14 | void setup() { 15 | background(255); 16 | size(400, 300); 17 | drawBorders(5, 15); 18 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/functionsPracticePackage/ToDo.txt: -------------------------------------------------------------------------------- 1 | Complete the tasks provided in the template file for each program. -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/10circlesBorder/circleBorderSolution/circleBorderSolution.pde: -------------------------------------------------------------------------------- 1 | //assume square display window 2 | size(400, 400); 3 | background(255); 4 | fill(152, 255, 0); 5 | float dia = 40; 6 | 7 | for (float x = dia/2; x < width; x+=dia) { 8 | ellipse(x, dia/2, dia, dia); // circles along the top 9 | ellipse(dia/2, x, dia, dia); // circles along the left 10 | ellipse(x, height-dia/2, dia, dia); // circles along the bottom 11 | ellipse(width-dia/2, x, dia, dia); // circles along the right 12 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/10circlesBorder/circlesBorderOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/10circlesBorder/circlesBorderOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/11fibonacci/fibonacciOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/11fibonacci/fibonacciOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/11fibonacci/fibonacciSolution/fibonacciSolution.pde: -------------------------------------------------------------------------------- 1 | int a = 0; 2 | int b = 1; 3 | print(a + ", " + b); 4 | 5 | for (int i = 0; i < 20; i++) { 6 | int c = a + b; // fibonacci number 7 | print(", " + c); 8 | 9 | // set new a and b 10 | a = b; 11 | b = c; 12 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/12linesFromCorner/linesFromCornerOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/12linesFromCorner/linesFromCornerOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/12linesFromCorner/linesFromCornerSolution/linesFromCornerSolution.pde: -------------------------------------------------------------------------------- 1 | // assume square display 2 | size(500, 500); 3 | background(255); 4 | 5 | for (int i = 0; i <= width; i+=10) { 6 | // lines from top left corner 7 | stroke(255, 0, 0); 8 | line(0, 0, i, height); 9 | 10 | // lines from bottom left corner 11 | stroke(255, 200, 0); 12 | line(0, height, width, height-i); 13 | 14 | // lines from bottom right corner 15 | stroke(0, 255, 0); 16 | line(width, height, width - i, 0); 17 | 18 | // lines from top right corner 19 | stroke(0, 0, 255); 20 | line(width, 0, 0, i); 21 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/13divisors/divisorsOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/13divisors/divisorsOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/13divisors/divisorsSolution/divisorsSolution.pde: -------------------------------------------------------------------------------- 1 | int num = 2050; //<>// 2 | 3 | println("Divisors of " + num + ":"); 4 | 5 | for (int i = 1; i <= num; i++) { 6 | if (num%i == 0) { // if i is a divisor of num 7 | println(i); 8 | } 9 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/14gcd/gcdOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/14gcd/gcdOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/14gcd/gcdSolution/gcdSolution.pde: -------------------------------------------------------------------------------- 1 | int n1 = 5340; 2 | int n2 = 3345; 3 | int gcd = 0; 4 | 5 | // find smallest of the two numbers 6 | int smallest; //<>// 7 | if (n1 < n2) { //<>// 8 | smallest = n1; //<>// 9 | } else { 10 | smallest = n2; 11 | } 12 | 13 | for (int i = 1; i <= smallest/2; i++) { //<>// 14 | if(n1%i == 0 && n2%i == 0) { // if both numbers divisible by i //<>// 15 | gcd = i; //<>// 16 | } 17 | } 18 | 19 | println("GCD of " + n1 + " and " + n2 + ": " + gcd); -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/15circleGrid/circleGridOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/15circleGrid/circleGridOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/15circleGrid/circleGridSolution/circleGridSolution.pde: -------------------------------------------------------------------------------- 1 | int dia = 60; 2 | size(400, 400); 3 | background(255); 4 | fill(145, 45, 250); 5 | 6 | // draw circles 7 | for (int i = 0; i < 5; i++) { 8 | for (int j = 0; j < 3; j++) { 9 | int xPos = width-(i*dia + dia/2); 10 | int yPos = j*dia + dia/2; 11 | ellipse(xPos, yPos, dia, dia); 12 | } 13 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/16circleStaggered1/circleStaggered1Output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/16circleStaggered1/circleStaggered1Output.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/16circleStaggered1/circleStaggered1Solution/circleStaggered1Solution.pde: -------------------------------------------------------------------------------- 1 | int dia = 60; 2 | size(400, 400); 3 | background(255); 4 | fill(145, 45, 250); 5 | 6 | // draw circles 7 | for (int i = 0; i < 4; i++) { 8 | for (int j = i; j < 4; j++) { 9 | int xPos = i*dia + dia/2; 10 | int yPos = j*dia + dia/2; 11 | ellipse(xPos, yPos, dia, dia); 12 | } 13 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/17circleStaggered2/circleStaggered2Output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/17circleStaggered2/circleStaggered2Output.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/17circleStaggered2/circleStaggered2Solution/circleStaggered2Solution.pde: -------------------------------------------------------------------------------- 1 | int dia = 60; 2 | size(400, 400); 3 | background(255); 4 | fill(145, 45, 250); 5 | 6 | // draw circles 7 | for (int i = 0; i < 4; i++) { 8 | for (int j = 3-i; j >= 0; j--) { 9 | int xPos = i*dia + dia/2; 10 | int yPos = height - (j*dia + dia/2); 11 | ellipse(xPos, yPos, dia, dia); 12 | } 13 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/18primeNumbers/primeNumbersOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/18primeNumbers/primeNumbersOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/18primeNumbers/primeNumbersSolution/primeNumbersSolution.pde: -------------------------------------------------------------------------------- 1 | int primeCount = 0; 2 | 3 | int current = 2; 4 | while (primeCount < 15) { 5 | boolean isPrime = true; 6 | 7 | // check if current isn't a prime number 8 | for (int j = 2; j <= current/2; j++) { 9 | if (current%j == 0) { 10 | isPrime = false; // current is divisible by a number 11 | } 12 | } 13 | 14 | if (isPrime) { // if current is a prime number 15 | println(current); 16 | primeCount++; 17 | } 18 | 19 | current++; 20 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/19brickWall/brickWallOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/19brickWall/brickWallOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/19brickWall/brickWallSolution/brickWallSolution.pde: -------------------------------------------------------------------------------- 1 | int brickWidth = 34; 2 | int brickHeight = 15; 3 | 4 | size(500, 500); 5 | background(153, 76, 0); 6 | stroke(255); 7 | 8 | for (int i = 0; i<=height; i+=brickHeight) { 9 | // draw horizontal lines 10 | line(0, i, width, i); 11 | 12 | // draw vertical lines 13 | if (i%(brickHeight*2) == 0) { // 'a' row 14 | for (int a = 0; a<=width; a+=brickWidth) { 15 | line(a, i, a, i+brickHeight); //vertical lines on 'a' row 16 | } 17 | } else { // 'b' row 18 | for (int b = brickWidth/2; b<=width; b+=brickWidth) { 19 | line(b, i, b, i+brickHeight); //vertical lines on 'b' row 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/1verticalLines/verticalLinesOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/1verticalLines/verticalLinesOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/1verticalLines/verticalLinesSolution/verticalLinesSolution.pde: -------------------------------------------------------------------------------- 1 | size(300, 200); 2 | background(255); 3 | 4 | // draw lines 5 | for (float x = 0; x < width; x+=width/10.0) { 6 | line(x, 0, x, height); 7 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/20circles/circlesOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/20circles/circlesOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/20circles/circlesSolution/circlesSolution.pde: -------------------------------------------------------------------------------- 1 | //assume square display window 2 | size(400, 400); 3 | background(255); 4 | 5 | int n = 15; // number of circles across width 6 | float dia = width*1.0/n; 7 | float shade = 0; 8 | for (float margin = dia/2; margin < width/2; margin+=dia) { 9 | fill(shade); 10 | shade+=255.0/(n/2 - 1); 11 | 12 | for (float x = margin; x <= width - margin; x+=dia) { 13 | ellipse(x, margin, dia, dia); // draw top circles 14 | ellipse(margin, x, dia, dia); // draw left circles 15 | ellipse(x, height-margin, dia, dia); // draw bottom circles 16 | ellipse(width-margin, x, dia, dia); // draw right circles 17 | } 18 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/2horizontalLines/horizontalLinesOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/2horizontalLines/horizontalLinesOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/2horizontalLines/horizontalLinesSolution/horizontalLinesSolution.pde: -------------------------------------------------------------------------------- 1 | size(300, 200); 2 | background(255); 3 | 4 | // draw lines 5 | for (float y = 0; y < height; y+=height/10.0) { 6 | line(0, y, width, y); 7 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/3alternatingColours/alternatingColoursOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/3alternatingColours/alternatingColoursOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/3alternatingColours/alternatingColoursSolution/alternatingColoursSolution.pde: -------------------------------------------------------------------------------- 1 | size(250, 300); 2 | background(255); 3 | 4 | int i = 0; 5 | for (float x = 0; x < width; x+=width/10.0) { 6 | // change line colour 7 | if (i%2 == 0) { // even line 8 | stroke(255, 0, 0); 9 | } else { // odd line 10 | stroke(0, 0, 255); 11 | } 12 | 13 | // draw line 14 | line(x, 0, x, height); 15 | 16 | // increase line count 17 | i = i + 1; 18 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/4alternatingLines/alternatingLinesOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/4alternatingLines/alternatingLinesOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/4alternatingLines/alternatingLinesSolution/alternatingLinesSolution.pde: -------------------------------------------------------------------------------- 1 | size(250, 300); 2 | background(255); 3 | 4 | int i = 0; 5 | for (float y = 0; y < height; y+=height/10.0) { 6 | 7 | // draw line 8 | if (i%2 == 0) { // even line 9 | line(width/2, y, width, y); 10 | } else { // odd line 11 | line(width/2, y, 0, y); 12 | } 13 | 14 | // increase line count 15 | i = i + 1; 16 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/5numDigits/numDigitsOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/5numDigits/numDigitsOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/5numDigits/numDigitsSolution/numDigitsSolution.pde: -------------------------------------------------------------------------------- 1 | int num = 124290; 2 | int digitCount = 0; 3 | 4 | print("Number of digits in " + num + ": "); 5 | 6 | while (num > 0) { 7 | num = num/10; 8 | digitCount++; // increase digit counter 9 | } 10 | 11 | println(digitCount); -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/6sumOddDigits/sumOddDigitsOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/6sumOddDigits/sumOddDigitsOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/6sumOddDigits/sumOddDigitsSolution/sumOddDigitsSolution.pde: -------------------------------------------------------------------------------- 1 | int num = 1224340989; 2 | int result = 0; 3 | 4 | print("sum of odd digits in " + num + ": "); 5 | 6 | while (num > 0) { 7 | int digit = num%10; // last digit of number 8 | if (digit%2 == 1) { // if digit is odd 9 | result += digit; 10 | } 11 | 12 | num /= 10; 13 | } 14 | 15 | println(result); -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/7triangles/trianglesOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/7triangles/trianglesOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/7triangles/trianglesSolution/trianglesSolution.pde: -------------------------------------------------------------------------------- 1 | size(400, 200); 2 | background(255); 3 | fill(0); 4 | 5 | // draw triangles 6 | for (float i=0; i < 10; i++) { 7 | float x = i*width/10; 8 | triangle(x, 0, x, 30, x + width/10.0, 30); 9 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/8circlesAcross/circlesAcrossOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/8circlesAcross/circlesAcrossOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/8circlesAcross/circlesAcrossSolution/circlesAcrossSolution.pde: -------------------------------------------------------------------------------- 1 | int dia = 50; 2 | 3 | size(500, 150); 4 | background(255); 5 | fill(255, 160, 55); 6 | 7 | // draw circles 8 | for (int i = dia/2; i < width; i+=dia) { 9 | ellipse(i, height/2, dia, dia); 10 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/9circlesAcrossRandom/circlesAcrossRandomOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/loopsPracticePackage/9circlesAcrossRandom/circlesAcrossRandomOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/9circlesAcrossRandom/circlesAcrossRandomSolution/circlesAcrossRandomSolution.pde: -------------------------------------------------------------------------------- 1 | size(500, 150); 2 | background(255); 3 | fill(73, 224, 242); 4 | 5 | float dia = random(10, 60); 6 | float oldDia; 7 | 8 | // draw circles 9 | for (float i = dia/2; i <= width+80; i+=(dia/2 + oldDia/2)) { 10 | ellipse(i, height/2, dia, dia); 11 | oldDia = dia; 12 | dia = random(10, 60); // set new diameter 13 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/loopsPracticePackage/Questions.txt: -------------------------------------------------------------------------------- 1 | Question 1 - Vertical Lines 2 | Draw 10 evenly spaced vertical lines as seen in the sample output. 3 | 4 | Question 2 - Horizontal Lines 5 | Draw 10 evenly spaced horizontal lines as seen in the sample output. 6 | 7 | Question 3 - Alternating Colours 8 | Draw 10 evenly spaced vertical lines with alternating colours as seen in the sample output. 9 | 10 | Question 4 - Alternating Lines 11 | Draw 10 lines as seen in the sample output. 12 | 13 | Question 5 - Number of Digits 14 | Write a program that prints the number of digits in an integer. 15 | 16 | Question 6 - Sum of Odd Digits 17 | Write a program that prints the sum of all the odd digits in an integer. 18 | 19 | Question 7 - Triangles 20 | Draw 10 triangles as seen in the sample output. 21 | 22 | Question 8 - Circles Across 23 | Draw circles across the screen with diameters touching as seen in the sample output. 24 | 25 | Question 9 - Circles Across with Random Diameter 26 | Draw circles across the screen with diameters touching as seen in the sample output. The diameter of each circle should be randomly selected. 27 | 28 | Question 10 - Circle Border 29 | Draw a border of circles around the screen as seen in the sample output. 30 | 31 | Question 11 - Fibonacci 32 | Print the first 22 numbers of the fibonacci sequence. Note: the first two numbers of the sequence can be printed before the start of the loop. 33 | 34 | Question 12 - Lines from Corner 35 | Recreate the sample output. 36 | 37 | Question 13 - Divisors 38 | Print all the divisors of an integer. 39 | 40 | Question 14 - Greatest Common Divisor (GCD) 41 | Print the GCD of two numbers. 42 | 43 | Question 15 - Circle Grid 44 | Draw a 5x3 grid of circles in the top right corner as seen in the sample output. 45 | 46 | Question 16 - Staggered Circles 1 47 | Draw a "staircase" of circles as seen in the sample output. 48 | 49 | Question 17 - Staggered Circles 2 50 | Draw a "staircase" of circles in the bottom left corner as seen in the sample output. 51 | 52 | Question 18 - Prime Numbers 53 | Print the first 15 prime numbers. 54 | 55 | Question 19 - Brick Wall 56 | Draw a brick wall as seen in the sample output. 57 | 58 | Question 20 - Circles 59 | Recreate the sample output. 60 | -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/10triggeredAnimationMultipleAttributes/triggeredAnimationMultipleAttributesOutput.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/10triggeredAnimationMultipleAttributes/triggeredAnimationMultipleAttributesOutput.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/10triggeredAnimationMultipleAttributes/triggeredAnimationMultipleAttributesSolution/triggeredAnimationMultipleAttributesSolution.pde: -------------------------------------------------------------------------------- 1 | float dia = 0; //initially empty 2 | float x; 3 | float y; 4 | float alpha; 5 | 6 | void setup() { 7 | size(300, 500); 8 | background(255); 9 | } 10 | 11 | void draw() { 12 | background(255); 13 | fill(255, 0, 0, alpha); 14 | noStroke(); 15 | ellipse(x, y, dia, dia); 16 | dia = dia + 0.1; //inflate 17 | y = y - 1; //move up as it's getting lighter 18 | alpha = alpha - 0.5; 19 | } 20 | 21 | void mousePressed() { 22 | x = mouseX; 23 | y = mouseY; 24 | dia = 20; 25 | alpha = 255; 26 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/11triggeredAnimationMultipleObjects/triggeredAnimationMultipleObjectsOutput.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/11triggeredAnimationMultipleObjects/triggeredAnimationMultipleObjectsOutput.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/11triggeredAnimationMultipleObjects/triggeredAnimationMultipleObjectsSolution/triggeredAnimationMultipleObjectsSolution.pde: -------------------------------------------------------------------------------- 1 | float xBlueBall, yBlueBall = -100; 2 | float xRedBall, yRedBall = -100; 3 | float xGreenBall, yGreenBall = -100; 4 | float xYellowBall, yYellowBall = -100; 5 | final float DIA = 30; 6 | 7 | void setup() { 8 | size(300, 500); 9 | background(255); 10 | } 11 | 12 | void draw() { 13 | background(255); 14 | noStroke(); 15 | 16 | fill(0, 0, 255); 17 | ellipse(xBlueBall, yBlueBall, DIA, DIA); 18 | xBlueBall = xBlueBall + 1; 19 | 20 | fill(255, 0, 0); 21 | ellipse(xRedBall, yRedBall, DIA, DIA); 22 | yRedBall = yRedBall - 1; 23 | 24 | fill(0, 255, 0); 25 | ellipse(xGreenBall, yGreenBall, DIA, DIA); 26 | yGreenBall = yGreenBall + 1; 27 | 28 | fill(240, 240, 80); 29 | ellipse(xYellowBall, yYellowBall, DIA, DIA); 30 | xYellowBall = xYellowBall - 1; 31 | } 32 | 33 | void mousePressed() { 34 | xBlueBall = mouseX; 35 | yBlueBall = mouseY; 36 | 37 | xRedBall = mouseX; 38 | yRedBall = mouseY; 39 | 40 | xGreenBall = mouseX; 41 | yGreenBall = mouseY; 42 | 43 | xYellowBall = mouseX; 44 | yYellowBall = mouseY; 45 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/1solidVennDiagram/solidVennDiagramOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/1solidVennDiagram/solidVennDiagramOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/1solidVennDiagram/solidVennDiagramSolution/solidVennDiagramSolution.pde: -------------------------------------------------------------------------------- 1 | size(300, 300); 2 | background(0); 3 | noStroke(); 4 | fill(255, 0, 0); 5 | ellipse(width/3, height/3, width/2, height/2); 6 | fill(0, 255, 0); 7 | ellipse(2*width/3, height/3, width/2, height/2); 8 | fill(0, 0, 255); 9 | ellipse(width/2, 2*height/3, width/2, height/2); -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/2translucentVennDiagram/translucentVennDiagramOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/2translucentVennDiagram/translucentVennDiagramOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/2translucentVennDiagram/translucentVennDiagramSolution/translucentVennDiagramSolution.pde: -------------------------------------------------------------------------------- 1 | size(300, 300); 2 | background(255); 3 | noStroke(); 4 | fill(255, 0, 0, 127); 5 | ellipse(width/3, height/3, width/2, height/2); 6 | fill(0, 255, 0, 127); 7 | ellipse(2*width/3, height/3, width/2, height/2); 8 | fill(0, 0, 255, 127); 9 | ellipse(width/2, 2*height/3, width/2, height/2); -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/3allShapesColors/allShapesColorsOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/3allShapesColors/allShapesColorsOutput.png -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/3allShapesColors/allShapesColorsSolution/allShapesColorsSolution.pde: -------------------------------------------------------------------------------- 1 | final int FRAME_WIDTH = 10; 2 | final int FRAME_MARGIN = 20; 3 | final int DIAMETER = 80; 4 | 5 | size(400, 300); 6 | background(20, 155, 20); 7 | strokeWeight(FRAME_WIDTH); 8 | noFill(); 9 | stroke(255); 10 | rect(FRAME_MARGIN, FRAME_MARGIN, width - 2*FRAME_MARGIN, height - 2*FRAME_MARGIN); 11 | fill(240, 240, 80); 12 | noStroke(); 13 | ellipse(width/2, height/2, DIAMETER, DIAMETER); 14 | fill(0, 127); 15 | stroke(200, 100, 0); 16 | strokeWeight(2); 17 | rectMode(CENTER); 18 | rect(width/2, height/2, DIAMETER/2, 2*DIAMETER); 19 | rect(width/2, height/2, 2*DIAMETER, DIAMETER/2); -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/4animation/animation.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/4animation/animation.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/4animation/animation/animation.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | size(400, 300); 3 | background(255); 4 | } 5 | 6 | void draw() { 7 | /* 8 | processing records mouse location at fixed intervals 9 | (like 5 milliseconds) 10 | mouseX, mouseY hold the current mouse location 11 | pmouseX, pmouseY hold the location recorded before that 12 | 13 | P.S. Initial values of all 4 variables are 0 14 | */ 15 | line(pmouseX, pmouseY, mouseX, mouseY); 16 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/5animation/compositeAnimation.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/5animation/compositeAnimation.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/5animation/compositeAnimation/compositeAnimation.pde: -------------------------------------------------------------------------------- 1 | final float HEAD_SIZE = 40; 2 | 3 | void setup() { 4 | size(400, 300); 5 | background(0); 6 | } 7 | 8 | void draw() { 9 | background(0); 10 | stroke(255); 11 | fill(0); 12 | 13 | //torso 14 | line(mouseX - HEAD_SIZE, mouseY - HEAD_SIZE, mouseX - HEAD_SIZE, mouseY + 0.5*HEAD_SIZE); 15 | 16 | //legs 17 | line(mouseX - HEAD_SIZE, mouseY + 0.5*HEAD_SIZE, mouseX - 1.5*HEAD_SIZE, mouseY + HEAD_SIZE); 18 | line(mouseX - HEAD_SIZE, mouseY - HEAD_SIZE + 1.5*HEAD_SIZE, mouseX - HEAD_SIZE + 0.5*HEAD_SIZE, mouseY - HEAD_SIZE+2*HEAD_SIZE); 19 | 20 | //hands 21 | line(mouseX - HEAD_SIZE, mouseY - HEAD_SIZE + HEAD_SIZE, mouseX - HEAD_SIZE - HEAD_SIZE, mouseY - HEAD_SIZE+0.5*HEAD_SIZE); 22 | line(mouseX - HEAD_SIZE, mouseY - HEAD_SIZE + HEAD_SIZE, mouseX - HEAD_SIZE + HEAD_SIZE, mouseY - HEAD_SIZE+0.5*HEAD_SIZE); 23 | 24 | //head 25 | ellipse(mouseX - HEAD_SIZE, mouseY - HEAD_SIZE, HEAD_SIZE, HEAD_SIZE); 26 | 27 | //eyes 28 | fill(255); 29 | ellipse(mouseX - HEAD_SIZE - 0.25*HEAD_SIZE, mouseY - HEAD_SIZE - 0.15*HEAD_SIZE, 5, 5); 30 | ellipse(mouseX - HEAD_SIZE + 0.25*HEAD_SIZE, mouseY - HEAD_SIZE - 0.15*HEAD_SIZE, 5, 5); 31 | 32 | //nose 33 | line(mouseX - HEAD_SIZE, mouseY - HEAD_SIZE - 0.1*HEAD_SIZE, mouseX - HEAD_SIZE, mouseY - HEAD_SIZE + 0.1*HEAD_SIZE); 34 | 35 | //mouth 36 | line(mouseX - 1.1*HEAD_SIZE, mouseY - 0.8*HEAD_SIZE, mouseX - 0.9*HEAD_SIZE, mouseY - 0.8*HEAD_SIZE); 37 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/6incrementalAnimation/incrementalAnimation.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/6incrementalAnimation/incrementalAnimation.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/6incrementalAnimation/incrementalAnimation/incrementalAnimation.pde: -------------------------------------------------------------------------------- 1 | float previousPressX, previousPressY; 2 | float thickness; 3 | 4 | void setup() { 5 | size(400, 300); 6 | background(240, 240, 80); 7 | } 8 | 9 | void draw() { 10 | } 11 | 12 | //executes once every time you press the mouse 13 | void mousePressed() { 14 | float dx = previousPressX - mouseX; 15 | float dy = previousPressY - mouseY; 16 | thickness = sqrt(dx*dx + dy*dy); 17 | 18 | /* 19 | map from range [0, 500] to rang [2, 10] 20 | so if it's 0, it becomes 2 21 | if it's 250, it becomes 6 22 | if it's 500 it becomes 10 23 | */ 24 | thickness = map(thickness, 0, 500, 2, 10); 25 | strokeWeight(thickness); 26 | thickness = map(thickness, 0, 500, 1, 10); 27 | strokeWeight(thickness); 28 | line(previousPressX, previousPressY, mouseX, mouseY); 29 | //update previous press location for next time 30 | previousPressX = mouseX; 31 | previousPressY = mouseY; 32 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/6incrementalAnimation/incrementalAnimationTemplate/incrementalAnimationTemplate.pde: -------------------------------------------------------------------------------- 1 | float previousPressX, previousPressY; 2 | float thickness; 3 | 4 | void setup() { 5 | size(400, 300); 6 | background(240, 240, 80); 7 | } 8 | 9 | void draw() { 10 | } 11 | 12 | //executes once every time you press the mouse 13 | void mousePressed() { 14 | float dx = previousPressX - mouseX; 15 | float dy = previousPressY - mouseY; 16 | thickness = sqrt(dx*dx + dy*dy); 17 | 18 | /* 19 | map from range [0, 500] to rang [2, 10] 20 | so if it's 0, it becomes 2 21 | if it's 250, it becomes 6 22 | if it's 500 it becomes 10 23 | */ 24 | thickness = map(thickness, 0, 500, 2, 10); 25 | strokeWeight(thickness); 26 | 27 | //TO BE COMPLETED 28 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/7oneOffAnimation/oneOffAnimationOutput.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/7oneOffAnimation/oneOffAnimationOutput.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/7oneOffAnimation/oneOffAnimationSolution/oneOffAnimationSolution.pde: -------------------------------------------------------------------------------- 1 | final int DIA = 30; 2 | 3 | void setup() { 4 | size(400, 300); 5 | background(255); 6 | } 7 | 8 | void draw() { 9 | } 10 | 11 | void mousePressed() { 12 | background(255); 13 | fill(255, 0, 0); 14 | noStroke(); 15 | ellipse(mouseX, mouseY, DIA, DIA); 16 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/8triggeredAnimation/triggeredAnimationOutput.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/8triggeredAnimation/triggeredAnimationOutput.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/8triggeredAnimation/triggeredAnimationSolution/triggeredAnimationSolution.pde: -------------------------------------------------------------------------------- 1 | final int DIA = 30; 2 | float x = -100; //so initially it's off the screen 3 | float y; 4 | 5 | void setup() { 6 | size(400, 300); 7 | background(255); 8 | } 9 | 10 | void draw() { 11 | background(255); 12 | fill(255, 0, 0); 13 | noStroke(); 14 | ellipse(x, y, DIA, DIA); 15 | y = y + 1; //drop it like it's hot 16 | } 17 | 18 | void mousePressed() { 19 | x = mouseX; 20 | y = mouseY; 21 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/9triggeredAnimation/growingCircleAnimation.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/9triggeredAnimation/growingCircleAnimation.mp4 -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/9triggeredAnimation/growingCircleAnimationSolution/growingCircleAnimationSolution.pde: -------------------------------------------------------------------------------- 1 | int dia = 0; 2 | float x, y = -1000000; 3 | 4 | void setup() { 5 | size(400, 300); 6 | background(255); 7 | } 8 | 9 | void draw() { 10 | background(255); 11 | fill(0); 12 | ellipse(x, y, dia, dia); 13 | dia = dia + 1; 14 | } 15 | 16 | void mousePressed() { 17 | x = mouseX; 18 | y = mouseY; 19 | dia = 0; 20 | } -------------------------------------------------------------------------------- /revisionPackage/comp115practicePrograms/pixelsVariablesPracticePackage/instructionsPV.txt: -------------------------------------------------------------------------------- 1 | In each folder, there is a sample output, either as a, 2 | 3 | 1. png image, or, 4 | 2. mp4 video 5 | 6 | your task is to write a program that achieves this output. 7 | 8 | a template is provided as a starting point for question 6. 9 | 10 | solutions are provided for all questions for you to compare your solution against. -------------------------------------------------------------------------------- /revisionPackage/comp125startingQuiz/COMP125_week_1_revision_questions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp125startingQuiz/COMP125_week_1_revision_questions.pdf -------------------------------------------------------------------------------- /revisionPackage/comp125startingQuiz/COMP125_week_1_revision_solutions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/comp125startingQuiz/COMP125_week_1_revision_solutions.pdf -------------------------------------------------------------------------------- /revisionPackage/sourceFilesForTeachingStaff/revisionCOMP115/01operators.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/sourceFilesForTeachingStaff/revisionCOMP115/01operators.pdf -------------------------------------------------------------------------------- /revisionPackage/sourceFilesForTeachingStaff/revisionCOMP115/comp115questionBank.tex: -------------------------------------------------------------------------------- 1 | \documentclass[11pt]{exam} 2 | %\printanswers 3 | 4 | \usepackage{nopageno} 5 | \usepackage{color} 6 | \newcommand{\cc}{\texttt} 7 | 8 | \usepackage{listings} 9 | \lstset{% 10 | language=Java, 11 | basicstyle=\footnotesize\ttfamily, 12 | numbers=left, 13 | numberstyle=\tiny, 14 | xleftmargin=17pt, 15 | xrightmargin=5pt, 16 | frame=single, 17 | breaklines=true, 18 | moredelim=**[is][\color{red}]{@}{@} 19 | } 20 | 21 | \lstdefinestyle{buggy}{ 22 | language=Java, 23 | emptylines=1, 24 | breaklines=true, 25 | basicstyle=\ttfamily\color{black}, 26 | moredelim=**[is][\color{red}]{@}{@}, 27 | } 28 | 29 | \lstdefinestyle{correct}{ 30 | language=Java, 31 | emptylines=1, 32 | breaklines=true, 33 | basicstyle=\ttfamily\color{black}, 34 | moredelim=**[is][\color{blue}]{@}{@}, 35 | } 36 | \begin{document} 37 | 38 | \newpage 39 | \section{Operators, Expressions} 40 | \input{01operators} 41 | 42 | \newpage 43 | \section{Conditions} 44 | \input{02conditions} 45 | 46 | \newpage 47 | \section{Loops} 48 | \input{03loops} 49 | 50 | \newpage 51 | \section{Functions - 1} 52 | \input{04functions1} 53 | 54 | \newpage 55 | \section{Arrays} 56 | \input{05arrays} 57 | 58 | \newpage 59 | \section{Functions - 2} 60 | \input{06functions2} 61 | 62 | \newpage 63 | \section{Strings} 64 | \input{07strings} 65 | \end{document} 66 | -------------------------------------------------------------------------------- /revisionPackage/sourceFilesForTeachingStaff/revisionCOMP115/questionHeader.tex: -------------------------------------------------------------------------------- 1 | \documentclass[11pt]{exam} 2 | \printanswers -------------------------------------------------------------------------------- /revisionPackage/sourceFilesForTeachingStaff/revisionCOMP115/solutionHeader.tex: -------------------------------------------------------------------------------- 1 | \documentclass[11pt]{exam} 2 | \printanswers -------------------------------------------------------------------------------- /revisionPackage/sourceFilesForTeachingStaff/revisionCOMP125/comp125questionBank.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/sourceFilesForTeachingStaff/revisionCOMP125/comp125questionBank.pdf -------------------------------------------------------------------------------- /revisionPackage/sourceFilesForTeachingStaff/revisionCOMP125/comp125questions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/sourceFilesForTeachingStaff/revisionCOMP125/comp125questions.pdf -------------------------------------------------------------------------------- /revisionPackage/sourceFilesForTeachingStaff/revisionCOMP125/comp125solutions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/comp1010mq/comp1000_to_comp1010_transition_workshops/f07363266b107f3f9d86ffa1935542af23e7abb2/revisionPackage/sourceFilesForTeachingStaff/revisionCOMP125/comp125solutions.pdf --------------------------------------------------------------------------------